1 /* -----------------------------------------------------------------------------
4 * (c) The GHC Team 2002-2003
6 * Table of thread labels.
8 * ---------------------------------------------------------------------------*/
10 #include "PosixSource.h"
12 #include "ThreadLabels.h"
20 static HashTable * threadLabels = NULL;
23 initThreadLabelTable(void)
25 if (threadLabels == NULL) {
26 threadLabels = allocHashTable();
31 updateThreadLabel(StgWord key, void *data)
33 removeThreadLabel(key);
34 insertHashTable(threadLabels,key,data);
38 lookupThreadLabel(StgWord key)
40 return lookupHashTable(threadLabels,key);
44 removeThreadLabel(StgWord key)
47 if ((old = lookupHashTable(threadLabels,key))) {
48 removeHashTable(threadLabels,key,old);
54 labelThread(StgPtr tso, char *label)
59 /* Caveat: Once set, you can only set the thread name to "" */
60 len = strlen(label)+1;
61 buf = stgMallocBytes(len * sizeof(char), "Schedule.c:labelThread()");
62 strncpy(buf,label,len);
63 /* Update will free the old memory for us */
64 updateThreadLabel(((StgTSO *)tso)->id,buf);