]> git.pond.sub.org Git - empserver/commitdiff
New empth_name() and empth_set_name()
authorRon Koenderink <rkoenderink@yahoo.ca>
Thu, 11 Sep 2008 20:46:31 +0000 (14:46 -0600)
committerRon Koenderink <rkoenderink@yahoo.ca>
Thu, 11 Sep 2008 20:46:31 +0000 (14:46 -0600)
include/empthread.h
include/lwp.h
src/lib/empthread/lwp.c
src/lib/empthread/ntthread.c
src/lib/empthread/pthread.c
src/lib/lwp/lwp.c

index adbaa20e0d641276bdfb4a10a848444c7f8ced2c..239824e887891d421d94270d1760348a1db9ec48 100644 (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().
index c106dd913aee9dd6aca64adbbdf7afc56d6a75f2..4a7ca2ce8f92db4e045f1dbc6c78488464b63db7 100644 (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 *);
index 7f62c5d384bbfe172382ff96058ef9fa3175d089..73fc116aa472545513286c35ec4b40c2b55918c0 100644 (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)
 {
index 24684dcb27319a8debf3a4ea272f10999fa9d13a..e7d4886646a30e45e81311b1590b4b7b16544c05 100644 (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
  */
index a3c9ab445bd1a38932ae86d1b16737a23ea7ba08..689868b21c2bf503ee04e7f83b6f83a63ccdf23e 100644 (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)
 {
index c9ceda4a41c87c53c60eb80a090628b5ffaf96fe..41b8a966f36d4f606275bf5e191ff9fbd11520f7 100644 (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);
+}
+