New empth_name() and empth_set_name()

This commit is contained in:
Ron Koenderink 2008-09-11 14:46:31 -06:00
parent 2e5915dd09
commit 2ddeda99d0
6 changed files with 88 additions and 0 deletions

View file

@ -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().

View file

@ -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 *);

View file

@ -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)
{

View file

@ -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
*/

View file

@ -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)
{

View file

@ -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);
}