Logo AND Algorithmique Numérique Distribuée

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