1 /* -----------------------------------------------------------------------------
4 * (c) The GHC Team 2002-2003
6 * Table of thread labels.
8 * ---------------------------------------------------------------------------*/
10 #include "PosixSource.h"
12 #include "ThreadLabels.h"
21 static HashTable * threadLabels = NULL;
24 initThreadLabelTable(void)
26 if (threadLabels == NULL) {
27 threadLabels = allocHashTable();
32 freeThreadLabelTable(void)
34 if (threadLabels != NULL) {
35 freeHashTable(threadLabels, NULL);
41 updateThreadLabel(StgWord key, void *data)
43 removeThreadLabel(key);
44 insertHashTable(threadLabels,key,data);
48 lookupThreadLabel(StgWord key)
50 return lookupHashTable(threadLabels,key);
54 removeThreadLabel(StgWord key)
57 if ((old = lookupHashTable(threadLabels,key))) {
58 removeHashTable(threadLabels,key,old);
64 labelThread(StgPtr tso, char *label)
69 /* Caveat: Once set, you can only set the thread name to "" */
70 len = strlen(label)+1;
71 buf = stgMallocBytes(len * sizeof(char), "Schedule.c:labelThread()");
72 strncpy(buf,label,len);
73 /* Update will free the old memory for us */
74 updateThreadLabel(((StgTSO *)tso)->id,buf);