Use error-checking mutexes on all platforms when DEBUG is on
[ghc-hetmet.git] / rts / posix / OSThreads.c
index 07bd762..ee4958a 100644 (file)
@@ -16,6 +16,7 @@
 #if defined(THREADED_RTS)
 #include "OSThreads.h"
 #include "RtsUtils.h"
+#include "Task.h"
 
 #if HAVE_STRING_H
 #include <string.h>
@@ -92,19 +93,36 @@ osThreadId()
   return pthread_self();
 }
 
+rtsBool
+osThreadIsAlive(OSThreadId id STG_UNUSED)
+{
+    // no good way to implement this on POSIX, AFAICT.  Returning true
+    // is safe.
+    return rtsTrue;
+}
+
 void
 initMutex(Mutex* pMut)
 {
-#if defined(DEBUG) && defined(linux_HOST_OS)
+#if defined(DEBUG)
     pthread_mutexattr_t attr;
     pthread_mutexattr_init(&attr);
+#if defined(linux_HOST_OS)
     pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_ERRORCHECK_NP);
+#else
+    pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_ERRORCHECK);
+#endif
     pthread_mutex_init(pMut,&attr);
 #else
     pthread_mutex_init(pMut,NULL);
 #endif
     return;
 }
+void
+closeMutex(Mutex* pMut)
+{
+    pthread_mutex_destroy(pMut);
+}
 
 void
 newThreadLocalKey (ThreadLocalKey *key)
@@ -134,12 +152,22 @@ setThreadLocalVar (ThreadLocalKey *key, void *value)
     }
 }
 
+void
+freeThreadLocalKey (ThreadLocalKey *key)
+{
+    int r;
+    if ((r = pthread_key_delete(*key)) != 0) {
+       barf("freeThreadLocalKey: %s", strerror(r));
+    }
+}
+
 static void *
 forkOS_createThreadWrapper ( void * entry )
 {
     Capability *cap;
     cap = rts_lock();
     cap = rts_evalStableIO(cap, (HsStablePtr) entry, NULL);
+    taskTimeStamp(myTask());
     rts_unlock(cap);
     return NULL;
 }