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 updateThreadLabel(StgWord key, void *data)
34 removeThreadLabel(key);
35 insertHashTable(threadLabels,key,data);
39 lookupThreadLabel(StgWord key)
41 return lookupHashTable(threadLabels,key);
45 removeThreadLabel(StgWord key)
48 if ((old = lookupHashTable(threadLabels,key))) {
49 removeHashTable(threadLabels,key,old);
55 labelThread(StgPtr tso, char *label)
60 /* Caveat: Once set, you can only set the thread name to "" */
61 len = strlen(label)+1;
62 buf = stgMallocBytes(len * sizeof(char), "Schedule.c:labelThread()");
63 strncpy(buf,label,len);
64 /* Update will free the old memory for us */
65 updateThreadLabel(((StgTSO *)tso)->id,buf);