Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ensures that runall is never called on empty set
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 15 Oct 2012 22:52:43 +0000 (00:52 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 15 Oct 2012 22:52:43 +0000 (00:52 +0200)
Not sure of when it can happen, but it does, forcing the context
factories to be defensive. This was causing issues in java coroutines
as this factory was not defensive enough. So avoiding future issues
seems interesting to me.

src/simix/smx_context_raw.c
src/simix/smx_context_sysv.c
src/simix/smx_private.h

index 55b5d80..b147b97 100644 (file)
@@ -490,14 +490,12 @@ void smx_ctx_raw_new_sr(void)
  */
 static void smx_ctx_raw_runall_serial(void)
 {
  */
 static void smx_ctx_raw_runall_serial(void)
 {
-  if (!xbt_dynar_is_empty(simix_global->process_to_run)) {
-    smx_process_t first_process =
-        xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
-    raw_process_index = 1;
+  smx_process_t first_process =
+      xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
+  raw_process_index = 1;
 
 
-    /* execute the first process */
-    smx_ctx_raw_resume_serial(first_process);
-  }
+  /* execute the first process */
+  smx_ctx_raw_resume_serial(first_process);
 }
 #endif
 
 }
 #endif
 
@@ -564,6 +562,8 @@ static void smx_ctx_raw_runall_parallel(void)
   raw_threads_working = 0;
   xbt_parmap_apply(raw_parmap, (void_f_pvoid_t) smx_ctx_raw_resume_parallel,
       simix_global->process_to_run);
   raw_threads_working = 0;
   xbt_parmap_apply(raw_parmap, (void_f_pvoid_t) smx_ctx_raw_resume_parallel,
       simix_global->process_to_run);
+#else
+  xbt_die("You asked for a parallel execution, but you don't have any threads.")
 #endif
 }
 
 #endif
 }
 
index f65212c..e67c326 100644 (file)
@@ -258,14 +258,12 @@ static void smx_ctx_sysv_resume_serial(smx_process_t first_process)
 
 static void smx_ctx_sysv_runall_serial(void)
 {
 
 static void smx_ctx_sysv_runall_serial(void)
 {
-  if (!xbt_dynar_is_empty(simix_global->process_to_run)) {
-    smx_process_t first_process =
-        xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
-    sysv_process_index = 1;
+  smx_process_t first_process =
+      xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
+  sysv_process_index = 1;
 
 
-    /* execute the first process */
-    smx_ctx_sysv_resume_serial(first_process);
-  }
+  /* execute the first process */
+  smx_ctx_sysv_resume_serial(first_process);
 }
 
 static void smx_ctx_sysv_stop_parallel(smx_context_t context)
 }
 
 static void smx_ctx_sysv_stop_parallel(smx_context_t context)
index 6e151d7..59f4342 100644 (file)
@@ -299,7 +299,9 @@ static XBT_INLINE void SIMIX_context_suspend(smx_context_t context)
  */
 static XBT_INLINE void SIMIX_context_runall(void)
 {
  */
 static XBT_INLINE void SIMIX_context_runall(void)
 {
-  simix_global->context_factory->runall();
+  if (!xbt_dynar_is_empty(simix_global->process_to_run)) {
+    simix_global->context_factory->runall();
+  }
 }
 
 /**
 }
 
 /**