[project @ 2003-12-15 14:31:48 by simonmar]
authorsimonmar <unknown>
Mon, 15 Dec 2003 14:31:48 +0000 (14:31 +0000)
committersimonmar <unknown>
Mon, 15 Dec 2003 14:31:48 +0000 (14:31 +0000)
Fix locking bug in awaitEvent(): in one code path it could return with
sched_lock unlocked.

ghc/rts/win32/AwaitEvent.c

index a8f73ff..0df8023 100644 (file)
 void
 awaitEvent(rtsBool wait)
 {
-  RELEASE_LOCK(&sched_mutex);
+  int ret;
+
   do {
-    /* Try to de-queue completed IO requests */
-    if (!awaitRequests(wait)) {
-      return;
-    }
+    /* Try to de-queue completed IO requests
+     */
+    RELEASE_LOCK(&sched_mutex);
+    ret = awaitRequests(wait);
     ACQUIRE_LOCK(&sched_mutex);
+    if (!ret) { 
+      return; /* still hold the lock */
+    }
+
     /* we were interrupted, return to the scheduler immediately.
      */
     if (interrupted) {
@@ -51,7 +56,6 @@ awaitEvent(rtsBool wait)
       return; /* still hold the lock */
     }
 #endif
-    RELEASE_LOCK(&sched_mutex);
   } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE);
 }