X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/55053de21d932fb0cc93eec52ec22ebc38ae936f..9f0e00fec83a9a1f7053f504e48173afb146331e:/src/xbt/context.c diff --git a/src/xbt/context.c b/src/xbt/context.c index fce1e64c3c..1ca6c8acb8 100644 --- a/src/xbt/context.c +++ b/src/xbt/context.c @@ -25,10 +25,11 @@ static xbt_swag_t context_to_destroy = NULL; static xbt_swag_t context_living = NULL; #ifndef USE_PTHREADS /* USE_PTHREADS and USE_CONTEXT are exclusive */ -# ifndef HAVE_UCONTEXT_H +# ifndef USE_UCONTEXT /* don't want to play with conditional compilation in automake tonight, sorry. include directly the c file from here when needed. */ # include "context_win32.c" +# define USE_WIN_CONTEXT # endif #endif @@ -108,9 +109,13 @@ static void *__context_wrapper(void *c) int i; #ifdef USE_PTHREADS + DEBUG0("**** Lock ****"); pthread_mutex_lock(&(context->mutex)); + DEBUG0("**** Releasing the prisonner ****"); pthread_cond_signal(&(context->cond)); + DEBUG0("**** Going to Jail ****"); pthread_cond_wait(&(context->cond), &(context->mutex)); + DEBUG0("**** Unlocking ****"); pthread_mutex_unlock(&(context->mutex)); #endif @@ -176,10 +181,14 @@ void xbt_context_start(xbt_context_t context) { #ifdef USE_PTHREADS /* Launch the thread */ + DEBUG0("**** Locking ****"); pthread_mutex_lock(&(context->mutex)); + DEBUG0("**** Pthread create ****"); xbt_assert0(!pthread_create(context->thread, NULL, __context_wrapper, context), "Unable to create a thread."); + DEBUG0("**** Going to jail ****"); pthread_cond_wait(&(context->cond), &(context->mutex)); + DEBUG0("**** Unlocking ****"); pthread_mutex_unlock(&(context->mutex)); #else makecontext (&(context->uc), (void (*) (void)) __context_wrapper, @@ -213,7 +222,7 @@ xbt_context_t xbt_context_new(xbt_context_function_t code, res->thread = xbt_new0(pthread_t,1); xbt_assert0(!pthread_mutex_init(&(res->mutex), NULL), "Mutex initialization error"); xbt_assert0(!pthread_cond_init(&(res->cond), NULL), "Condition initialization error"); -#else +#else /* FIXME: strerror is not thread safe */ xbt_assert2(getcontext(&(res->uc))==0,"Error in context saving: %d (%s)", errno, strerror(errno)); res->uc.uc_link = NULL; @@ -221,9 +230,11 @@ xbt_context_t xbt_context_new(xbt_context_function_t code, /* WARNING : when this context is over, the current_context (i.e. the father), is awaken... Theorically, the wrapper should prevent using this feature. */ - res->uc.uc_stack.ss_sp = res->stack; - res->uc.uc_stack.ss_size = STACK_SIZE; -#endif +# ifndef USE_WIN_CONTEXT + res->uc.uc_stack.ss_sp = pth_skaddr_makecontext(res->stack,STACK_SIZE); + res->uc.uc_stack.ss_size = pth_sksize_makecontext(res->stack,STACK_SIZE); +# endif /* USE_WIN_CONTEXT */ +#endif /* USE_PTHREADS or not */ res->argc = argc; res->argv = argv; res->startup_func = startup_func;