1 /* -----------------------------------------------------------------------------
4 * (c) The GHC Team 2002-2003
6 * Table of thread labels.
8 * ---------------------------------------------------------------------------*/
10 #include "PosixSource.h"
13 #include "ThreadLabels.h"
22 static HashTable * threadLabels = NULL;
25 initThreadLabelTable(void)
27 if (threadLabels == NULL) {
28 threadLabels = allocHashTable();
33 freeThreadLabelTable(void)
35 if (threadLabels != NULL) {
36 freeHashTable(threadLabels, NULL);
42 updateThreadLabel(StgWord key, void *data)
44 removeThreadLabel(key);
45 insertHashTable(threadLabels,key,data);
49 lookupThreadLabel(StgWord key)
51 return lookupHashTable(threadLabels,key);
55 removeThreadLabel(StgWord key)
58 if ((old = lookupHashTable(threadLabels,key))) {
59 removeHashTable(threadLabels,key,old);
65 labelThread(StgPtr tso, char *label)
70 /* Caveat: Once set, you can only set the thread name to "" */
71 len = strlen(label)+1;
72 buf = stgMallocBytes(len * sizeof(char), "Schedule.c:labelThread()");
73 strncpy(buf,label,len);
74 /* Update will free the old memory for us */
75 updateThreadLabel(((StgTSO *)tso)->id,buf);