Add getNumberOfProcessors(), FIX MacOS X build problem (hopefully)
[ghc-hetmet.git] / rts / posix / OSThreads.c
index cff3782..6eb2d2b 100644 (file)
@@ -93,19 +93,32 @@ 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);
-    pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_ERRORCHECK_NP);
+    pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_ERRORCHECK);
     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)
@@ -135,6 +148,15 @@ 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 )
 {
@@ -157,6 +179,24 @@ forkOS_createThread ( HsStablePtr entry )
     return result;
 }
 
+nat
+getNumberOfProcessors (void)
+{
+    static nat nproc = 0;
+
+    if (nproc == 0) {
+#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
+        nproc = sysconf(_SC_NPROCESSORS_ONLN);
+#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
+        nproc = sysconf(_SC_NPROCESSORS_CONF);
+#else
+        nproc = 1;
+#endif
+    }
+
+    return nproc;
+}
+
 #else /* !defined(THREADED_RTS) */
 
 int