Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
-Add smx_ctx_sysv_get_thread_id to the parallel ucontext factory.
authorcristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Feb 2011 13:34:25 +0000 (13:34 +0000)
committercristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Feb 2011 13:34:25 +0000 (13:34 +0000)
-Unify smx_current_context variable for both sequential and // raw/sysv contexts.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9553 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/simix/context.h
src/simix/smx_context.c
src/simix/smx_context_raw.c
src/simix/smx_context_sysv.c
src/simix/smx_context_sysv_private.h

index 7775c66..9d8ea2e 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "xbt/swag.h"
 #include "simix/datatypes.h"
 
 #include "xbt/swag.h"
 #include "simix/datatypes.h"
+#include "gras_config.h"
 
 SG_BEGIN_DECL()
 /******************************** Context *************************************/
 
 SG_BEGIN_DECL()
 /******************************** Context *************************************/
@@ -58,7 +59,12 @@ typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*);
 extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use;
 extern char* smx_context_factory_name;
 extern int smx_context_stack_size;
 extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use;
 extern char* smx_context_factory_name;
 extern int smx_context_stack_size;
+
+#ifdef CONTEXT_THREADS
+extern __thread smx_context_t smx_current_context;
+#else
 extern smx_context_t smx_current_context;
 extern smx_context_t smx_current_context;
+#endif
 
 /* *********************** */
 /* Context type definition */
 
 /* *********************** */
 /* Context type definition */
index ee5c9ff..6030548 100644 (file)
@@ -11,6 +11,7 @@
 #include "xbt/swag.h"
 #include "private.h"
 #include "simix/context.h"
 #include "xbt/swag.h"
 #include "private.h"
 #include "simix/context.h"
+#include "gras_config.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
                                 "Context switching mecanism");
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
                                 "Context switching mecanism");
@@ -18,7 +19,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
 char* smx_context_factory_name = NULL; /* factory name specified by --cfg=contexts/factory:value */
 smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL;
 int smx_context_stack_size = 128 * 1024;
 char* smx_context_factory_name = NULL; /* factory name specified by --cfg=contexts/factory:value */
 smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL;
 int smx_context_stack_size = 128 * 1024;
+
+#ifdef CONTEXT_THREADS
+__thread smx_context_t smx_current_context;
+#else
 smx_context_t smx_current_context;
 smx_context_t smx_current_context;
+#endif
+
 static int smx_parallel_contexts = 1;
 
 /** 
 static int smx_parallel_contexts = 1;
 
 /** 
index 2d62d5d..8ed05e1 100644 (file)
@@ -153,10 +153,8 @@ void raw_swapcontext(raw_stack_t* old, raw_stack_t new) {
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
-static xbt_parmap_t parmap;
-
 #ifdef CONTEXT_THREADS
 #ifdef CONTEXT_THREADS
-static __thread smx_context_t current_context;
+static xbt_parmap_t parmap;
 #endif
 
 static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
 #endif
 
 static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
@@ -200,7 +198,6 @@ smx_ctx_raw_create_context(xbt_main_func_t code, int argc, char **argv,
 
      }else{
        maestro_raw_context = context;
 
      }else{
        maestro_raw_context = context;
-       current_context = (smx_context_t) maestro_raw_context;
      }
 
      return (smx_context_t) context;
      }
 
      return (smx_context_t) context;
@@ -265,11 +262,11 @@ static void smx_ctx_raw_runall(xbt_dynar_t processes)
 static void smx_ctx_raw_resume_parallel(smx_process_t process)
 {
   smx_ctx_raw_t context = (smx_ctx_raw_t)process->context;
 static void smx_ctx_raw_resume_parallel(smx_process_t process)
 {
   smx_ctx_raw_t context = (smx_ctx_raw_t)process->context;
-  current_context = (smx_context_t)context;
+  smx_current_context = (smx_context_t)context;
   raw_swapcontext(
       &context->old_stack_top,
       context->stack_top);
   raw_swapcontext(
       &context->old_stack_top,
       context->stack_top);
-  current_context = (smx_context_t)maestro_raw_context;
+  smx_current_context = (smx_context_t)maestro_raw_context;
 }
 
 static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
 }
 
 static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
@@ -280,7 +277,7 @@ static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
 
 static smx_context_t smx_ctx_raw_self_parallel(void)
 {
 
 static smx_context_t smx_ctx_raw_self_parallel(void)
 {
-  return current_context;
+  return smx_current_context;
 }
 
 static int smx_ctx_raw_get_thread_id(){
 }
 
 static int smx_ctx_raw_get_thread_id(){
index 51410dd..18cd39f 100644 (file)
@@ -26,7 +26,9 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
+#ifdef CONTEXT_THREADS
 static xbt_parmap_t parmap;
 static xbt_parmap_t parmap;
+#endif
 
 static smx_context_t
 smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
 
 static smx_context_t
 smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
@@ -67,6 +69,7 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
     parmap = xbt_parmap_new(2);
     (*factory)->runall = smx_ctx_sysv_runall_parallel;
     (*factory)->self = smx_ctx_sysv_self_parallel;
     parmap = xbt_parmap_new(2);
     (*factory)->runall = smx_ctx_sysv_runall_parallel;
     (*factory)->self = smx_ctx_sysv_self_parallel;
+    (*factory)->get_thread_id = smx_ctx_sysv_get_thread_id;
 #else
     THROW0(arg_error, 0, "No thread support for parallel context execution");
 #endif
 #else
     THROW0(arg_error, 0, "No thread support for parallel context execution");
 #endif
@@ -213,9 +216,9 @@ void smx_ctx_sysv_runall(xbt_dynar_t processes)
 void smx_ctx_sysv_resume_parallel(smx_process_t process)
 {
   smx_context_t context = process->context;
 void smx_ctx_sysv_resume_parallel(smx_process_t process)
 {
   smx_context_t context = process->context;
-  xbt_os_thread_set_extra_data(context);
+  smx_current_context = (smx_context_t)context;
   int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc);
   int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc);
-  xbt_os_thread_set_extra_data(NULL);
+  smx_current_context = (smx_context_t)maestro_context;
 
   xbt_assert0((rv == 0), "Context swapping failure");
 }
 
   xbt_assert0((rv == 0), "Context swapping failure");
 }
@@ -228,6 +231,12 @@ void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes)
 
 smx_context_t smx_ctx_sysv_self_parallel(void)
 {
 
 smx_context_t smx_ctx_sysv_self_parallel(void)
 {
-  smx_context_t self_context = (smx_context_t) xbt_os_thread_get_extra_data();
-  return self_context ? self_context : (smx_context_t) maestro_context;
+  /*smx_context_t self_context = (smx_context_t) xbt_os_thread_get_extra_data();
+  return self_context ? self_context : (smx_context_t) maestro_context;*/
+  return smx_current_context;
+}
+
+int smx_ctx_sysv_get_thread_id(void)
+{
+  return (int)(unsigned long)xbt_os_thread_get_extra_data();
 }
 }
index 3dd761a..168379b 100644 (file)
@@ -51,6 +51,7 @@ void smx_ctx_sysv_resume(smx_context_t new_context);
 void smx_ctx_sysv_runall(xbt_dynar_t processes);
 void smx_ctx_sysv_resume_parallel(smx_process_t new_context);
 void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes);
 void smx_ctx_sysv_runall(xbt_dynar_t processes);
 void smx_ctx_sysv_resume_parallel(smx_process_t new_context);
 void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes);
+int smx_ctx_sysv_get_thread_id(void);
 smx_context_t smx_ctx_sysv_self_parallel(void);
 
 SG_END_DECL()
 smx_context_t smx_ctx_sysv_self_parallel(void);
 
 SG_END_DECL()