fix Win32 build
[ghc-hetmet.git] / ghc / rts / win32 / OSThreads.c
index d2e3d17..c772be3 100644 (file)
@@ -98,7 +98,7 @@ createOSThread (OSThreadId* pId, OSThreadProc *startProc, void *param)
   
   return (_beginthreadex ( NULL,  /* default security attributes */
                           0,
-                          startProc,
+                          (unsigned (__stdcall *)(void *)) startProc,
                           param,
                           0,
                           (unsigned*)pId) == 0);
@@ -110,6 +110,13 @@ osThreadId()
   return GetCurrentThreadId();
 }
 
+#ifdef USE_CRITICAL_SECTIONS
+void
+initMutex (Mutex* pMut)
+{
+    InitializeCriticalSectionAndSpinCount(pMut,4000);
+}
+#else
 void
 initMutex (Mutex* pMut)
 {
@@ -120,6 +127,7 @@ initMutex (Mutex* pMut)
   *pMut = h;
   return;
 }
+#endif
 
 void
 newThreadLocalKey (ThreadLocalKey *key)
@@ -137,9 +145,13 @@ getThreadLocalVar (ThreadLocalKey *key)
 {
     void *r;
     r = TlsGetValue(*key);
-    if (r == NULL) {
+#ifdef DEBUG
+    // r is allowed to be NULL - it can mean that either there was an
+    // error or the stored value is in fact NULL.
+    if (GetLastError() != NO_ERROR) {
        barf("getThreadLocalVar: key not found");
     }
+#endif
     return r;
 }
 
@@ -159,7 +171,7 @@ forkOS_createThreadWrapper ( void * entry )
 {
     Capability *cap;
     cap = rts_lock();
-    rts_evalStableIO(cap, (HsStablePtr) entry, NULL);
+    cap = rts_evalStableIO(cap, (HsStablePtr) entry, NULL);
     rts_unlock(cap);
     return 0;
 }