X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/193cf49a5012fae01bdeee473a1847135defcb0d..2d103e931b4e47eb04613d0d038b08f5c0a2d004:/src/simix/smx_context_sysv.c diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index e5b66e1c17..4d30329226 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -19,14 +19,15 @@ #ifdef _XBT_WIN32 #include "win32_ucontext.h" -#include "win32_ucontext.c" #else #include "ucontext.h" #endif XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); +#ifdef CONTEXT_THREADS static xbt_parmap_t parmap; +#endif static smx_context_t smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv, @@ -52,7 +53,7 @@ union u_ctx_addr { void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) { smx_ctx_base_factory_init(factory); - VERB0("Activating SYSV context factory"); + XBT_VERB("Activating SYSV context factory"); (*factory)->finalize = smx_ctx_sysv_factory_finalize; (*factory)->create_context = smx_ctx_sysv_create_context; @@ -62,13 +63,13 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) (*factory)->suspend = smx_ctx_sysv_suspend; (*factory)->name = "smx_sysv_context_factory"; - if (smx_parallel_contexts) { + if (SIMIX_context_is_parallel()) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ parmap = xbt_parmap_new(2); (*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"); + THROWF(arg_error, 0, "No thread support for parallel context execution"); #endif }else{ (*factory)->runall = smx_ctx_sysv_runall; @@ -77,8 +78,10 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) int smx_ctx_sysv_factory_finalize(smx_context_factory_t *factory) { +#ifdef CONTEXT_THREADS if(parmap) xbt_parmap_destroy(parmap); +#endif return smx_ctx_base_factory_finalize(factory); } @@ -101,17 +104,19 @@ smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code, otherwise is the context for maestro */ if (code) { - xbt_assert2(getcontext(&(context->uc)) == 0, + int res; + res = getcontext(&(context->uc)); + xbt_assert(res == 0, "Error in context saving: %d (%s)", errno, strerror(errno)); context->uc.uc_link = NULL; context->uc.uc_stack.ss_sp = - pth_skaddr_makecontext(context->stack, CONTEXT_STACK_SIZE); + pth_skaddr_makecontext(context->stack, smx_context_stack_size); context->uc.uc_stack.ss_size = - pth_sksize_makecontext(context->stack, CONTEXT_STACK_SIZE); + pth_sksize_makecontext(context->stack, smx_context_stack_size); #ifdef HAVE_VALGRIND_VALGRIND_H context->valgrind_stack_id = @@ -136,7 +141,7 @@ smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv, void *data) { - return smx_ctx_sysv_create_context_sized(sizeof(s_smx_ctx_sysv_t), + return smx_ctx_sysv_create_context_sized(sizeof(s_smx_ctx_sysv_t) + smx_context_stack_size, code, argc, argv, cleanup_func, data); @@ -184,18 +189,20 @@ void smx_ctx_sysv_wrapper(int first, ...) void smx_ctx_sysv_suspend(smx_context_t context) { - smx_current_context = (smx_context_t)maestro_context; - int rv = swapcontext(&((smx_ctx_sysv_t) context)->uc, &((smx_ctx_sysv_t)context)->old_uc); + SIMIX_context_set_current((smx_context_t) maestro_context); + int rv; + rv = swapcontext(&((smx_ctx_sysv_t) context)->uc, &((smx_ctx_sysv_t)context)->old_uc); - xbt_assert0((rv == 0), "Context swapping failure"); + xbt_assert((rv == 0), "Context swapping failure"); } void smx_ctx_sysv_resume(smx_context_t context) { - smx_current_context = context; - int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc); + SIMIX_context_set_current(context); + int rv; + rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc); - xbt_assert0((rv == 0), "Context swapping failure"); + xbt_assert((rv == 0), "Context swapping failure"); } void smx_ctx_sysv_runall(xbt_dynar_t processes) @@ -204,30 +211,32 @@ void smx_ctx_sysv_runall(xbt_dynar_t processes) unsigned int cursor; xbt_dynar_foreach(processes, cursor, process) { - DEBUG2("Schedule item %u of %lu",cursor,xbt_dynar_length(processes)); + XBT_DEBUG("Schedule item %u of %lu",cursor,xbt_dynar_length(processes)); smx_ctx_sysv_resume(process->context); } - xbt_dynar_reset(processes); } void smx_ctx_sysv_resume_parallel(smx_process_t process) { smx_context_t context = process->context; - xbt_os_thread_set_extra_data(context); - int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc); - xbt_os_thread_set_extra_data(NULL); + SIMIX_context_set_current((smx_context_t) context); + int rv; + rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc); + SIMIX_context_set_current((smx_context_t) maestro_context); - xbt_assert0((rv == 0), "Context swapping failure"); + xbt_assert((rv == 0), "Context swapping failure"); } void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes) { +#ifdef CONTEXT_THREADS xbt_parmap_apply(parmap, (void_f_pvoid_t)smx_ctx_sysv_resume_parallel, processes); - xbt_dynar_reset(processes); +#endif } 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 SIMIX_context_get_current(); }