RTS tidyup sweep, first phase
[ghc-hetmet.git] / rts / ThreadLabels.c
index 9b9f172..aa620f0 100644 (file)
@@ -8,10 +8,14 @@
  * ---------------------------------------------------------------------------*/
 
 #include "PosixSource.h"
+#include "Rts.h"
+
 #include "ThreadLabels.h"
 #include "RtsUtils.h"
+#include "Hash.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 #if defined(DEBUG)
 /* to the end */
@@ -26,6 +30,15 @@ initThreadLabelTable(void)
 }
 
 void
+freeThreadLabelTable(void)
+{
+    if (threadLabels != NULL) {
+        freeHashTable(threadLabels, NULL);
+        threadLabels = NULL;
+    }
+}
+
+void
 updateThreadLabel(StgWord key, void *data)
 {
   removeThreadLabel(key);
@@ -47,4 +60,19 @@ removeThreadLabel(StgWord key)
     stgFree(old);
   }  
 }
+
+void
+labelThread(StgPtr tso, char *label)
+{
+  int len;
+  void *buf;
+
+  /* Caveat: Once set, you can only set the thread name to "" */
+  len = strlen(label)+1;
+  buf = stgMallocBytes(len * sizeof(char), "Schedule.c:labelThread()");
+  strncpy(buf,label,len);
+  /* Update will free the old memory for us */
+  updateThreadLabel(((StgTSO *)tso)->id,buf);
+}
+
 #endif /* DEBUG */