Make empth_name() and empth_set_name() take a thread argument

This commit is contained in:
Markus Armbruster 2008-09-11 19:25:34 -04:00
parent 7581b50eb6
commit d46b0b727d
6 changed files with 20 additions and 26 deletions

View file

@ -128,14 +128,14 @@ empth_t *empth_create(void (*entry)(void *),
empth_t *empth_self(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. * Terminate the current thread.

View file

@ -75,15 +75,15 @@ empth_self(void)
} }
char * char *
empth_name(void) empth_name(empth_t *thread)
{ {
return lwpName(LwpCurrent); return lwpName(thread);
} }
void void
empth_set_name(char *name) empth_set_name(empth_t *thread, char *name)
{ {
lwpSetName(LwpCurrent, name); lwpSetName(thread, name);
} }
void void

View file

@ -490,9 +490,9 @@ empth_self(void)
* empth_name * empth_name
*/ */
char * 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 * Set the thread name
*/ */
void void
empth_set_name(char *name) empth_set_name(empth_t *thread, char *name)
{ {
empth_t *pThread = TlsGetValue(dwTLSIndex); strncpy(thread->szName, name, sizeof(thread->szName) - 1);
strncpy(pThread->szName, name, sizeof(pThread->szName) - 1);
} }
/************************ /************************

View file

@ -248,22 +248,17 @@ empth_self(void)
} }
char * char *
empth_name(void) empth_name(empth_t *thread)
{ {
return empth_self()->name; return thread->name;
} }
void void
empth_set_name(char *name) empth_set_name(empth_t *thread, char *name)
{ {
empth_t *ctx_ptr; if (thread->name)
ctx_ptr = pthread_getspecific(ctx_key);
if (ctx_ptr->name != NULL)
free(ctx_ptr->name); free(ctx_ptr->name);
thread->name = strdup(name);
ctx_ptr->name = strdup(name);
} }
void void

View file

@ -344,7 +344,7 @@ play_cmd(void)
return RET_FAIL; return RET_FAIL;
} }
snprintf(buf, sizeof(buf), "Play#%d", player->cnum); 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); logerror("%s logged in as country #%d", praddr(player), player->cnum);
pr_id(player, C_INIT, "%d\n", CLIENTPROTO); pr_id(player, C_INIT, "%d\n", CLIENTPROTO);
player_main(player); player_main(player);

View file

@ -83,7 +83,8 @@ journal_entry(char *fmt, ...)
if (journal) { if (journal) {
time(&now); 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); va_start(ap, fmt);
vsnprintf(buf, sizeof(buf) - 1, fmt, ap); vsnprintf(buf, sizeof(buf) - 1, fmt, ap);