From: mquinson Date: Wed, 11 Jul 2007 16:07:37 +0000 (+0000) Subject: implement versatile threads (working both on simulator and in situ); the simulated... X-Git-Tag: v3.3~1623 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/44ca997a01460e17c9affb8fd4915daf91c439d5 implement versatile threads (working both on simulator and in situ); the simulated conditions aren't working yet git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3737 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/xbt/xbt_rl_synchro.c b/src/xbt/xbt_rl_synchro.c index 32a2b6998c..9c6bde4530 100644 --- a/src/xbt/xbt_rl_synchro.c +++ b/src/xbt/xbt_rl_synchro.c @@ -22,36 +22,39 @@ /* 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) { diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index db4fe50e99..ee00c07ba3 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -21,36 +21,51 @@ /* the implementation would be cleaner (and faster) with ELF symbol aliasing */ typedef struct s_xbt_thread_ { - /* KEEP IT IN SYNC WITH s_smx_process_ from src/include/simix/datatypes.h */ - char *name; /**< @brief process name if any */ - smx_simdata_process_t simdata; /**< @brief simulator data */ - s_xbt_swag_hookup_t process_hookup; - s_xbt_swag_hookup_t synchro_hookup; - s_xbt_swag_hookup_t host_proc_hookup; - void *data; /**< @brief user data */ - /* KEEP IT IN SYNC WITH s_smx_process_ from src/include/simix/datatypes.h */ + smx_process_t s_process; + void_f_pvoid_t *code; + void *userparam; } s_xbt_thread_t; -xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine, void* param) { - THROW_UNIMPLEMENTED; /* FIXME */ +static int xbt_thread_create_wrapper(int argc, char *argv[]) { + xbt_thread_t t = (xbt_thread_t)SIMIX_process_get_data(SIMIX_process_self()); + (*t->code)(t->userparam); + return 0; +} + +xbt_thread_t xbt_thread_create(void_f_pvoid_t* code, void* param) { + xbt_thread_t res = xbt_new0(s_xbt_thread_t,1); + res->userparam = param; + res->code = code; + res->s_process = SIMIX_process_create(NULL, + xbt_thread_create_wrapper, res, + SIMIX_host_get_name(SIMIX_host_self()), + 0, NULL); + return res; } void -xbt_thread_join(xbt_thread_t thread,void ** thread_return) { +xbt_thread_join(xbt_thread_t thread) { THROW_UNIMPLEMENTED; /* FIXME */ } -void xbt_thread_exit(int *retval) { - THROW_UNIMPLEMENTED; /* FIXME */ +void +xbt_thread_destroy(xbt_thread_t thread) { + SIMIX_process_kill(thread->s_process); + free(thread); +} + +void xbt_thread_exit() { + xbt_thread_destroy(xbt_thread_self()); } xbt_thread_t xbt_thread_self(void) { - THROW_UNIMPLEMENTED; /* FIXME */ + return SIMIX_process_get_data(SIMIX_process_self()); } void xbt_thread_yield(void) { THROW_UNIMPLEMENTED; /* FIXME */ } + /****** mutex related functions ******/ struct s_xbt_mutex_ {