From d46b0b727d33671bb327a0cc367532e19a43b90f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 11 Sep 2008 19:25:34 -0400 Subject: [PATCH] Make empth_name() and empth_set_name() take a thread argument --- include/empthread.h | 8 ++++---- src/lib/empthread/lwp.c | 8 ++++---- src/lib/empthread/ntthread.c | 10 ++++------ src/lib/empthread/pthread.c | 15 +++++---------- src/lib/player/login.c | 2 +- src/lib/subs/journal.c | 3 ++- 6 files changed, 20 insertions(+), 26 deletions(-) diff --git a/include/empthread.h b/include/empthread.h index 239824e88..4d039f3e7 100644 --- a/include/empthread.h +++ b/include/empthread.h @@ -128,14 +128,14 @@ empth_t *empth_create(void (*entry)(void *), empth_t *empth_self(void); /* - * Return the name of the current thread. + * Return the name THREAD. */ -char *empth_name(void); +char *empth_name(empth_t *thread); /* - * Sets the name of the current thread. + * Set the name of THREAD to NAME. */ -void empth_set_name(char *); +void empth_set_name(empth_t *thread, char *name); /* * Terminate the current thread. diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index 73fc116aa..838bb6b9f 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -75,15 +75,15 @@ empth_self(void) } char * -empth_name(void) +empth_name(empth_t *thread) { - return lwpName(LwpCurrent); + return lwpName(thread); } void -empth_set_name(char *name) +empth_set_name(empth_t *thread, char *name) { - lwpSetName(LwpCurrent, name); + lwpSetName(thread, name); } void diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index e7d488664..4799b0311 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -490,9 +490,9 @@ empth_self(void) * empth_name */ char * -empth_name(void) +empth_name(empth_t *thread) { - return empth_self()->szName; + return thread->szName; } /************************ @@ -500,11 +500,9 @@ empth_name(void) * Set the thread name */ void -empth_set_name(char *name) +empth_set_name(empth_t *thread, char *name) { - empth_t *pThread = TlsGetValue(dwTLSIndex); - - strncpy(pThread->szName, name, sizeof(pThread->szName) - 1); + strncpy(thread->szName, name, sizeof(thread->szName) - 1); } /************************ diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index 689868b21..36abfb7a9 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -248,22 +248,17 @@ empth_self(void) } char * -empth_name(void) +empth_name(empth_t *thread) { - return empth_self()->name; + return thread->name; } void -empth_set_name(char *name) +empth_set_name(empth_t *thread, char *name) { - empth_t *ctx_ptr; - - ctx_ptr = pthread_getspecific(ctx_key); - - if (ctx_ptr->name != NULL) + if (thread->name) free(ctx_ptr->name); - - ctx_ptr->name = strdup(name); + thread->name = strdup(name); } void diff --git a/src/lib/player/login.c b/src/lib/player/login.c index 3b0148a8d..2fe444223 100644 --- a/src/lib/player/login.c +++ b/src/lib/player/login.c @@ -344,7 +344,7 @@ play_cmd(void) return RET_FAIL; } snprintf(buf, sizeof(buf), "Play#%d", player->cnum); - empth_set_name(buf); + empth_set_name(empth_self(), buf); logerror("%s logged in as country #%d", praddr(player), player->cnum); pr_id(player, C_INIT, "%d\n", CLIENTPROTO); player_main(player); diff --git a/src/lib/subs/journal.c b/src/lib/subs/journal.c index fcaa752c5..eeafbef2d 100644 --- a/src/lib/subs/journal.c +++ b/src/lib/subs/journal.c @@ -83,7 +83,8 @@ journal_entry(char *fmt, ...) if (journal) { time(&now); - fprintf(journal, "%.24s %10.10s:", ctime(&now), empth_name()); + fprintf(journal, "%.24s %10.10s:", + ctime(&now), empth_name(empth_self())); va_start(ap, fmt); vsnprintf(buf, sizeof(buf) - 1, fmt, ap); -- 2.43.0