X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=rts%2FThreadLabels.c;h=6919e1ae383efdb3e7feb26a8316dedaa8cae8d9;hp=9b9f1723ffdc0f6a8055279843e8eab6aaeeb4d1;hb=842e9d6628a27cf1f420d53f6a5901935dc50c54;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1 diff --git a/rts/ThreadLabels.c b/rts/ThreadLabels.c index 9b9f172..6919e1a 100644 --- a/rts/ThreadLabels.c +++ b/rts/ThreadLabels.c @@ -8,10 +8,13 @@ * ---------------------------------------------------------------------------*/ #include "PosixSource.h" +#include "Rts.h" #include "ThreadLabels.h" #include "RtsUtils.h" +#include "Hash.h" #include +#include #if defined(DEBUG) /* to the end */ @@ -26,6 +29,15 @@ initThreadLabelTable(void) } void +freeThreadLabelTable(void) +{ + if (threadLabels != NULL) { + freeHashTable(threadLabels, NULL); + threadLabels = NULL; + } +} + +void updateThreadLabel(StgWord key, void *data) { removeThreadLabel(key); @@ -47,4 +59,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 */