From 714a970003a5bccec9a46b0a4e0b42b5d980ea2f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 16 Oct 2012 00:52:43 +0200 Subject: [PATCH] ensures that runall is never called on empty set 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 | 14 +++++++------- src/simix/smx_context_sysv.c | 12 +++++------- src/simix/smx_private.h | 4 +++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/simix/smx_context_raw.c b/src/simix/smx_context_raw.c index 55b5d80d9e..b147b97d71 100644 --- a/src/simix/smx_context_raw.c +++ b/src/simix/smx_context_raw.c @@ -490,14 +490,12 @@ void smx_ctx_raw_new_sr(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 @@ -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); +#else + xbt_die("You asked for a parallel execution, but you don't have any threads.") #endif } diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index f65212cc2e..e67c326be2 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -258,14 +258,12 @@ static void smx_ctx_sysv_resume_serial(smx_process_t first_process) 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) diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index 6e151d75db..59f4342d85 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -299,7 +299,9 @@ static XBT_INLINE void SIMIX_context_suspend(smx_context_t context) */ 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(); + } } /** -- 2.20.1