X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9e208fa1fce2449fb9d83259d4d4cb2fe9f6cdfb..a2a1aee909cfa9076f9dbe34778140af74dfebd3:/src/xbt/xbt_rl_synchro.c diff --git a/src/xbt/xbt_rl_synchro.c b/src/xbt/xbt_rl_synchro.c index 1a6b52f48b..dfb439a1ee 100644 --- a/src/xbt/xbt_rl_synchro.c +++ b/src/xbt/xbt_rl_synchro.c @@ -22,41 +22,47 @@ /* the implementation would be cleaner (and faster) with ELF symbol aliasing */ -struct xbt_thread_ { - /* KEEP IT IN SYNC WITH xbt_os_thread (both win and lin parts) */ -#ifdef HAVE_PTHREAD_H - pthread_t t; - void *param; - pvoid_f_pvoid_t *start_routine; -#elif defined(WIN32) - HANDLE handle; /* the win thread handle */ - unsigned long id; /* the win thread id */ - pvoid_f_pvoid_t *start_routine; - void* param; -#endif -}; +typedef struct s_xbt_thread_ { + xbt_os_thread_t os_thread; + void_f_pvoid_t *code; + void *userparam; +}s_xbt_thread_t; + +static void *xbt_thread_create_wrapper(void *p) { + xbt_thread_t t = (xbt_thread_t)p; + (*t->code)(t->userparam); + return NULL; +} + + +xbt_thread_t xbt_thread_create(void_f_pvoid_t* code, void* param) { -xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine, - void* param) { - return (xbt_thread_t)xbt_os_thread_create(start_routine,param); + xbt_thread_t res = xbt_new0(s_xbt_thread_t,1); + res->userparam = param; + res->code = code; + res->os_thread = xbt_os_thread_create(xbt_thread_create_wrapper,res); + return res; } void -xbt_thread_join(xbt_thread_t thread,void ** thread_return) { - xbt_os_thread_join( (xbt_os_thread_t)thread, thread_return ); +xbt_thread_join(xbt_thread_t thread) { + xbt_os_thread_join( thread->os_thread, NULL ); } -void xbt_thread_exit(int *retval) { - xbt_os_thread_exit( retval ); +void xbt_thread_exit() { + xbt_os_thread_exit(NULL); } xbt_thread_t xbt_thread_self(void) { - return (xbt_thread_t)xbt_os_thread_self(); + return (xbt_thread_t)xbt_os_thread_getparam(); } void xbt_thread_yield(void) { xbt_os_thread_yield(); } +void xbt_thread_cancel(xbt_thread_t t) { + xbt_os_thread_cancel(t->os_thread); +} /****** mutex related functions ******/ struct xbt_mutex_ { /* KEEP IT IN SYNC WITH OS IMPLEMENTATION (both win and lin) */ @@ -83,6 +89,14 @@ void xbt_mutex_destroy(xbt_mutex_t mutex) { xbt_os_mutex_destroy( (xbt_os_mutex_t)mutex ); } +#ifdef WIN32 + enum { /* KEEP IT IN SYNC WITH OS IMPLEM */ + SIGNAL = 0, + BROADCAST = 1, + MAX_EVENTS = 2 + }; +#endif + /***** condition related functions *****/ typedef struct xbt_cond_ { /* KEEP IT IN SYNC WITH OS IMPLEMENTATION (both win and lin) */ @@ -104,6 +118,10 @@ void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex) { xbt_os_cond_wait( (xbt_os_cond_t)cond, (xbt_os_mutex_t)mutex ); } +void xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay) { + xbt_os_cond_timedwait( (xbt_os_cond_t)cond, (xbt_os_mutex_t)mutex, delay ); +} + void xbt_cond_signal(xbt_cond_t cond) { xbt_os_cond_signal( (xbt_os_cond_t)cond ); }