From: mquinson Date: Tue, 7 Aug 2007 18:45:38 +0000 (+0000) Subject: allow to retrieve the name of threads X-Git-Tag: v3.3~1346 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/46bade924148e45d2fd389682cddc4c3eabdff96?hp=ddccd2f0e340dd7befc8c921ac1fc168af1b1333 allow to retrieve the name of threads git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4014 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/xbt/synchro.h b/include/xbt/synchro.h index d77af7e043..333df9562f 100644 --- a/include/xbt/synchro.h +++ b/include/xbt/synchro.h @@ -35,6 +35,8 @@ SG_BEGIN_DECL() XBT_PUBLIC(xbt_thread_t) xbt_thread_create(const char *name, void_f_pvoid_t start_routine,void* param); XBT_PUBLIC(void) xbt_thread_exit(); XBT_PUBLIC(xbt_thread_t) xbt_thread_self(void); + XBT_PUBLIC(const char*) xbt_thread_name(xbt_thread_t t); + XBT_PUBLIC(const char*) xbt_thread_self_name(void); /* xbt_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */ XBT_PUBLIC(void) xbt_thread_join(xbt_thread_t thread); /* Ends the life of the poor victim (not always working if it's computing, but working if it's blocked in the OS) */ diff --git a/src/include/xbt/xbt_os_thread.h b/src/include/xbt/xbt_os_thread.h index b3860d50f2..e42d2ec0f4 100644 --- a/src/include/xbt/xbt_os_thread.h +++ b/src/include/xbt/xbt_os_thread.h @@ -31,6 +31,8 @@ SG_BEGIN_DECL() XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name,pvoid_f_pvoid_t start_routine,void* param); XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode); XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void); + XBT_PUBLIC(const char*) xbt_os_thread_self_name(void); + XBT_PUBLIC(const char*) xbt_os_thread_name(xbt_os_thread_t); /* xbt_os_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */ XBT_PUBLIC(void) xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return); XBT_PUBLIC(void) xbt_os_thread_yield(void); diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index 56c15e11b9..dad3c66461 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -66,6 +66,7 @@ void xbt_os_thread_mod_init(void) { THROW0(system_error,errcode,"pthread_key_create failed for xbt_self_thread_key"); main_thread=xbt_new(s_xbt_os_thread_t,1); + main_thread->name = (char*)"main"; main_thread->start_routine = NULL; main_thread->param = NULL; main_thread->exception = xbt_new(ex_ctx_t, 1); @@ -111,6 +112,14 @@ xbt_os_thread_t xbt_os_thread_create(const char*name, return res_thread; } +const char* xbt_os_thread_name(xbt_os_thread_t t) { + return t->name; +} + +const char* xbt_os_thread_self_name(void) { + xbt_os_thread_t self = xbt_os_thread_self(); + return self?self->name:"main"; +} void xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) { @@ -322,6 +331,15 @@ xbt_os_thread_t xbt_os_thread_create(const char *name,pvoid_f_pvoid_t start_rout return t; } +const char* xbt_os_thread_name(xbt_os_thread_t t) { + return t->name; +} + +const char* xbt_os_thread_self_name(void) { + xbt_os_thread_t t = xbt_os_thread_self(); + return t?t->name:"main"; +} + void xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) { diff --git a/src/xbt/xbt_rl_synchro.c b/src/xbt/xbt_rl_synchro.c index 356313f7dc..140bb5c2d2 100644 --- a/src/xbt/xbt_rl_synchro.c +++ b/src/xbt/xbt_rl_synchro.c @@ -46,6 +46,14 @@ xbt_thread_t xbt_thread_create(const char*name,void_f_pvoid_t* code, void* param return res; } +const char* xbt_thread_name(xbt_thread_t t) { + return xbt_os_thread_name(t->os_thread); +} + +const char* xbt_thread_self_name(void) { + return xbt_os_thread_self_name(); +} + void xbt_thread_join(xbt_thread_t thread) { DEBUG1("Join thread %p",thread); diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index 3788d37ec1..d78d28ed52 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -50,6 +50,15 @@ xbt_thread_t xbt_thread_create(const char*name,void_f_pvoid_t* code, void* param return res; } +const char* xbt_thread_name(xbt_thread_t t) { + return t->name; +} + +const char* xbt_thread_self_name(void) { + return xbt_thread_self()->name; +} + + void xbt_thread_join(xbt_thread_t thread) { THROW_UNIMPLEMENTED; /* FIXME */