X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8be93beba0c7547303f5a102c2cb528b8c586066..7555d51e10906e1e1d50be93e2b415cc24bbeeee:/src/xbt/xbt_context.c diff --git a/src/xbt/xbt_context.c b/src/xbt/xbt_context.c index 418b125820..8774486165 100644 --- a/src/xbt/xbt_context.c +++ b/src/xbt/xbt_context.c @@ -10,24 +10,20 @@ #include "portable.h" #include "xbt/log.h" #include "xbt/swag.h" -#include "xbt_context_factory.h" +#include "xbt_context_private.h" /* the context associated with the current process */ -static xbt_context_t -current_context = NULL; +xbt_context_t current_context = NULL; /* the context associated with the maestro */ -static xbt_context_t -maestro_context = NULL; +xbt_context_t maestro_context = NULL; /* this list contains the contexts to destroy */ -static xbt_swag_t -context_to_destroy = NULL; +xbt_swag_t context_to_destroy = NULL; /* this list contains the contexts in use */ -static xbt_swag_t -context_living = NULL; +xbt_swag_t context_living = NULL; /* the context factory used to create the appropriate context * each context implementation define its own context factory @@ -42,18 +38,6 @@ context_living = NULL; static xbt_context_factory_t context_factory = NULL; -/* java implementation of the context */ -#include "xbt_jcontext.c" - -#ifdef CONTEXT_THREADS -/* use the native thread implementation of the context */ -#include "xbt_thread_context.c" -#elif !defined(WIN32) -/* use the ucontext based context */ -# include "xbt_ucontext.c" -#endif - - /** * This function is call by the xbt_init() function to initialize the context module. */ @@ -66,10 +50,10 @@ xbt_context_mod_init(void) #ifdef CONTEXT_THREADS /* context switch based os thread */ - xbt_thread_context_factory_init(&context_factory); + xbt_ctx_thread_factory_init(&context_factory); #elif !defined(WIN32) /* context switch based ucontext */ - xbt_ucontext_factory_init(&context_factory); + xbt_ctx_sysv_factory_init(&context_factory); #else /* context switch is not allowed on Windows */ #error ERROR [__FILE__, line __LINE__]: no context based implementation specified. @@ -116,9 +100,6 @@ xbt_context_mod_exit(void) /* remove the context of the scheduler from the list of the contexts in use */ xbt_swag_remove(maestro_context, context_living); - free(maestro_context); - maestro_context = current_context = NULL; - /* * kill all the contexts in use : * the killed contexts are added in the list of the contexts to destroy @@ -130,6 +111,9 @@ xbt_context_mod_exit(void) /* destroy all contexts in the list of contexts to destroy */ xbt_context_empty_trash(); + free(maestro_context); + maestro_context = current_context = NULL; + /* destroy the lists */ xbt_swag_free(context_to_destroy); xbt_swag_free(context_living); @@ -260,15 +244,10 @@ xbt_context_select_factory(const char* name) { /* if the desired factory is different of the current factory, call xbt_context_mod_exit() */ if(strcmp(context_factory->name,name)) - { xbt_context_mod_exit(); - - } else - { /* the same context factory is requested return directly */ return 0; - } } /* get the desired factory */ @@ -293,26 +272,20 @@ xbt_context_select_factory(const char* name) return 0; } -int +void xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name) { - if(!strcmp(name,"jcontext_factory")) - { - return xbt_jcontext_factory_init(factory); - } - #ifdef CONTEXT_THREADS - else if(!strcmp(name,"thread_context_factory")) - { - return xbt_thread_context_factory_init(factory); - } - #elif !defined(WIN32) - else if(!strcmp(name,"ucontext_context_factory")) - { - return xbt_ucontext_factory_init(factory); - } - #endif - - return EINVAL; + if(!strcmp(name,"java")) + xbt_ctx_java_factory_init(factory); +#ifdef CONTEXT_THREADS + else if(!strcmp(name,"thread")) + xbt_ctx_thread_factory_init(factory); +#elif !defined(WIN32) + else if(!strcmp(name,"sysv")) + xbt_ctx_sysv_factory_init(factory); +#endif + else + THROW1(not_found_error, 0,"Factory '%s' does not exist",name); } /** Garbage collection