From: alegrand Date: Wed, 14 Mar 2007 15:15:21 +0000 (+0000) Subject: Fixing the setkey getkey mechanism (it wasn't functionnal at all). X-Git-Tag: v3.3~2089 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a222d3b19b7286192a3426b11ea412b1e0ec119c Fixing the setkey getkey mechanism (it wasn't functionnal at all). git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3270 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/xbt/xbt_thread.c b/src/xbt/xbt_thread.c index 024e50fc1c..16da050e07 100644 --- a/src/xbt/xbt_thread.c +++ b/src/xbt/xbt_thread.c @@ -35,7 +35,7 @@ static void xbt_thread_free_thread_data(void*d){ void xbt_thread_mod_init(void) { int errcode; - if ((errcode=pthread_key_create(&xbt_self_thread_key, &xbt_thread_free_thread_data))) + if ((errcode=pthread_key_create(&xbt_self_thread_key, NULL))) THROW0(system_error,errcode,"pthread_key_create failed for xbt_self_thread_key"); } void xbt_thread_mod_exit(void) { @@ -46,23 +46,41 @@ void xbt_thread_mod_exit(void) { // THROW0(system_error,errcode,"pthread_key_delete failed for xbt_self_thread_key"); } +typedef struct s_xbt_thread_wrapper_for_restart__ { + pvoid_f_pvoid_t *start_routine; + void* param; + xbt_thread_t res; +} s_xbt_thread_wrapper_for_restart_t, *xbt_thread_wrapper_for_restart_t; + +static void * wrapper_start_routine(void *s) { + xbt_thread_wrapper_for_restart_t stub = s; + int errcode; + + if ((errcode=pthread_setspecific(xbt_self_thread_key,stub->res))) + THROW0(system_error,errcode,"pthread_setspecific failed for xbt_self_thread_key"); + return stub->start_routine(stub->param); +} xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine, void* param) { - xbt_thread_t res = xbt_new(s_xbt_thread_t,1); int errcode; + xbt_thread_wrapper_for_restart_t stub = xbt_new0(s_xbt_thread_wrapper_for_restart_t,1); - if ((errcode=pthread_setspecific(xbt_self_thread_key,res))) - THROW0(system_error,errcode,"pthread_setspecific failed for xbt_self_thread_key"); - - if ((errcode = pthread_create(&(res->t), NULL, start_routine, param))) + stub->start_routine = start_routine ; + stub->param = param; + stub->res = xbt_new(s_xbt_thread_t,1); + + + if ((errcode = pthread_create(&(stub->res->t), NULL, wrapper_start_routine, stub))) THROW0(system_error,errcode, "pthread_create failed"); - return res; + return stub->res; } + void xbt_thread_exit(int *retval) { pthread_exit(retval); } + xbt_thread_t xbt_thread_self(void) { return pthread_getspecific(xbt_self_thread_key); }