From 2ddeda99d05f9e140521dc46f761477377bee675 Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Thu, 11 Sep 2008 14:46:31 -0600 Subject: [PATCH] New empth_name() and empth_set_name() --- include/empthread.h | 10 ++++++++++ include/lwp.h | 2 ++ src/lib/empthread/lwp.c | 12 ++++++++++++ src/lib/empthread/ntthread.c | 21 +++++++++++++++++++++ src/lib/empthread/pthread.c | 19 +++++++++++++++++++ src/lib/lwp/lwp.c | 24 ++++++++++++++++++++++++ 6 files changed, 88 insertions(+) diff --git a/include/empthread.h b/include/empthread.h index adbaa20e..239824e8 100644 --- a/include/empthread.h +++ b/include/empthread.h @@ -127,6 +127,16 @@ empth_t *empth_create(void (*entry)(void *), */ empth_t *empth_self(void); +/* + * Return the name of the current thread. + */ +char *empth_name(void); + +/* + * Sets the name of the current thread. + */ +void empth_set_name(char *); + /* * Terminate the current thread. * The current thread should not be the thread that executed main(). diff --git a/include/lwp.h b/include/lwp.h index c106dd91..4a7ca2ce 100644 --- a/include/lwp.h +++ b/include/lwp.h @@ -52,6 +52,8 @@ int lwpSigWait(sigset_t *set, int *sig); void *lwpGetUD(struct lwpProc * p); void lwpSetUD(struct lwpProc * p, char *ud); int lwpSetPriority(int prio); +char *lwpName(struct lwpProc * p); +void lwpSetName(struct lwpProc * p, char *name); struct lwp_rwlock *lwp_rwlock_create(char *); void lwp_rwlock_destroy(struct lwp_rwlock *); diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index 7f62c5d3..73fc116a 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -74,6 +74,18 @@ empth_self(void) return LwpCurrent; } +char * +empth_name(void) +{ + return lwpName(LwpCurrent); +} + +void +empth_set_name(char *name) +{ + lwpSetName(LwpCurrent, name); +} + void empth_exit(void) { diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index 24684dcb..e7d48866 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -486,6 +486,27 @@ empth_self(void) return pThread; } +/************************ + * empth_name + */ +char * +empth_name(void) +{ + return empth_self()->szName; +} + +/************************ + * empth_set_name + * Set the thread name + */ +void +empth_set_name(char *name) +{ + empth_t *pThread = TlsGetValue(dwTLSIndex); + + strncpy(pThread->szName, name, sizeof(pThread->szName) - 1); +} + /************************ * empth_exit */ diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index a3c9ab44..689868b2 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -247,6 +247,25 @@ empth_self(void) return pthread_getspecific(ctx_key); } +char * +empth_name(void) +{ + return empth_self()->name; +} + +void +empth_set_name(char *name) +{ + empth_t *ctx_ptr; + + ctx_ptr = pthread_getspecific(ctx_key); + + if (ctx_ptr->name != NULL) + free(ctx_ptr->name); + + ctx_ptr->name = strdup(name); +} + void empth_exit(void) { diff --git a/src/lib/lwp/lwp.c b/src/lib/lwp/lwp.c index c9ceda4a..41b8a966 100644 --- a/src/lib/lwp/lwp.c +++ b/src/lib/lwp/lwp.c @@ -405,3 +405,27 @@ lwpStackCheckUsed(struct lwpProc *newp) lwpStatus(newp, "Thread stack %d used, %d left, %d total", used, total - used, total); } + +/* lwpName + * + * Return the name of the thread. + */ +char * +lwpName(struct lwpProc *proc) +{ + return proc->name; +} + +/* lwpSetName + * + * Set the name of the thread. + */ +void +lwpSetName(struct lwpProc *proc, char *name) +{ + if (proc->name != NULL) + free(proc->name); + + proc->name = strdup(name); +} +