From: cristianrosa Date: Tue, 7 Dec 2010 14:02:49 +0000 (+0000) Subject: Rework context factory's initialization logic. X-Git-Tag: v3.6_beta2~861 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c32579154fc3d877f58348eb6a15d2eed8706b56 Rework context factory's initialization logic. 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 --- diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 84bd8de15e..857c049502 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -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 diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index f89fb018b6..c23084b53b 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -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; +} diff --git a/src/simix/smx_context_sysv_private.h b/src/simix/smx_context_sysv_private.h index 9c23bb0a69..de4b441e43 100644 --- a/src/simix/smx_context_sysv_private.h +++ b/src/simix/smx_context_sysv_private.h @@ -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()