fix Win32 build
[ghc-hetmet.git] / ghc / rts / win32 / AwaitEvent.c
index a8f73ff..43e188f 100644 (file)
@@ -1,3 +1,4 @@
+#if !defined(THREADED_RTS) /* to the end */
 /*
  * Wait/check for external events. Periodically, the
  * Scheduler checks for the completion of external operations,
  */
 #include "Rts.h"
 #include "Schedule.h"
+#include "AwaitEvent.h"
 #include <windows.h>
 #include "win32/AsyncIO.h"
-#if defined(RTS_SUPPORTS_THREADS)
-#include "Capability.h"
-#endif
+
+// Used to avoid calling abandonRequestWait() if we don't need to.
+// Protected by sched_mutex.
+static nat workerWaitingForRequests = 0;
 
 void
 awaitEvent(rtsBool wait)
 {
-  RELEASE_LOCK(&sched_mutex);
-  do {
-    /* Try to de-queue completed IO requests */
-    if (!awaitRequests(wait)) {
-      return;
-    }
-    ACQUIRE_LOCK(&sched_mutex);
-    /* we were interrupted, return to the scheduler immediately.
-     */
-    if (interrupted) {
-      return; /* still hold the lock */
-    }
+  int ret;
 
-    /* If new runnable threads have arrived, stop waiting for
-     * I/O and run them.
+  do {
+    /* Try to de-queue completed IO requests
      */
-    if (run_queue_hd != END_TSO_QUEUE) {
+    workerWaitingForRequests = 1;
+    ret = awaitRequests(wait);
+    workerWaitingForRequests = 0;
+    if (!ret) { 
       return; /* still hold the lock */
     }
 
-#ifdef RTS_SUPPORTS_THREADS
-    /* If another worker thread wants to take over,
-     * return to the scheduler
-     */
-    if (needToYieldToReturningWorker()) {
-      return; /* still hold the lock */
-    }
-#endif
-    RELEASE_LOCK(&sched_mutex);
-  } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE);
-}
+    // Return to the scheduler if:
+    //
+    //  - we were interrupted
+    //  - new threads have arrived
 
-#ifdef RTS_SUPPORTS_THREADS
-void
-wakeBlockedWorkerThread()
-{
-  abandonRequestWait();
+  } while (wait
+          && sched_state == SCHED_RUNNING
+          && emptyRunQueue(&MainCapability)
+      );
 }
 #endif
-