Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rework context factory's initialization logic.
authorcristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 7 Dec 2010 14:02:49 +0000 (14:02 +0000)
committercristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 7 Dec 2010 14:02:49 +0000 (14:02 +0000)
Now if both ucontext and threads are detected, allow the parallel execution of ucontexts using a thread pool.

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

src/simix/smx_context.c
src/simix/smx_context_sysv.c
src/simix/smx_context_sysv_private.h

index 84bd8de..857c049 100644 (file)
@@ -28,10 +28,10 @@ void SIMIX_context_mod_init(void)
       (*factory_initializer_to_use)(&(simix_global->context_factory));
     }
     else {
-#ifdef CONTEXT_THREADS /* Use os threads (either pthreads or windows ones) */
-      SIMIX_ctx_thread_factory_init(&simix_global->context_factory);
-#elif defined(CONTEXT_UCONTEXT) /* use ucontext */
+#ifdef CONTEXT_UCONTEXT /* use ucontext */
       SIMIX_ctx_sysv_factory_init(&simix_global->context_factory);
+#elif defined(CONTEXT_THREADS) /* Use os threads (either pthreads or windows ones) */
+      SIMIX_ctx_thread_factory_init(&simix_global->context_factory);
 #else
 #error ERROR [__FILE__, line __LINE__]: no context implementation specified.
 #endif
index f89fb01..c23084b 100644 (file)
@@ -45,8 +45,13 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
   (*factory)->name = "smx_sysv_context_factory";
 
   if(_surf_parallel_contexts){
+#ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
     tpool = xbt_tpool_new(2, 10);
     (*factory)->runall = smx_ctx_sysv_runall_parallel;
+    (*factory)->self = smx_ctx_sysv_self_parallel;
+#else
+    THROW0(arg_error, 0, "No thread support for parallel context execution");
+#endif
   }else{
     (*factory)->runall = smx_ctx_sysv_runall;
   }    
@@ -170,10 +175,24 @@ void smx_ctx_sysv_runall(xbt_swag_t processes)
     smx_ctx_sysv_resume(process->context);
 }
 
+void smx_ctx_sysv_resume_parallel(smx_context_t context)
+{
+  xbt_os_thread_set_extra_data(context);
+  int rv = swapcontext(&maestro_context->uc, &((smx_ctx_sysv_t) context)->uc);
+
+  xbt_assert0((rv == 0), "Context swapping failure");
+}
+
 void smx_ctx_sysv_runall_parallel(xbt_swag_t processes)
 {
   smx_process_t process;
   while((process = xbt_swag_extract(processes))){
-    xbt_tpool_queue_job(tpool, (void_f_pvoid_t)smx_ctx_sysv_resume, process->context);
+    xbt_tpool_queue_job(tpool, (void_f_pvoid_t)smx_ctx_sysv_resume_parallel, process->context);
   }
 }
+
+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;
+}
index 9c23bb0..de4b441 100644 (file)
@@ -51,7 +51,9 @@ void smx_ctx_sysv_stop(smx_context_t context);
 void smx_ctx_sysv_suspend(smx_context_t context);
 void smx_ctx_sysv_resume(smx_context_t new_context);
 void smx_ctx_sysv_runall(xbt_swag_t processes);
+void smx_ctx_sysv_resume_parallel(smx_context_t new_context);
 void smx_ctx_sysv_runall_parallel(xbt_swag_t processes);
+smx_context_t smx_ctx_sysv_self_parallel(void);
 
 SG_END_DECL()