2 * Wait/check for external events. Periodically, the
3 * Scheduler checks for the completion of external operations,
4 * like the expiration of timers, completion of I/O requests
5 * issued by Haskell threads.
7 * If the Scheduler is otherwise out of work, it'll block
8 * herein waiting for external events to occur.
10 * This file mirrors the select()-based functionality
11 * for POSIX / Unix platforms in rts/Select.c, but for
18 #include "win32/AsyncIO.h"
19 #if defined(RTS_SUPPORTS_THREADS)
20 #include "Capability.h"
24 awaitEvent(rtsBool wait)
26 RELEASE_LOCK(&sched_mutex);
28 /* Try to de-queue completed IO requests */
29 if (!awaitRequests(wait)) {
32 ACQUIRE_LOCK(&sched_mutex);
33 /* we were interrupted, return to the scheduler immediately.
36 return; /* still hold the lock */
39 /* If new runnable threads have arrived, stop waiting for
42 if (run_queue_hd != END_TSO_QUEUE) {
43 return; /* still hold the lock */
46 #ifdef RTS_SUPPORTS_THREADS
47 /* If another worker thread wants to take over,
48 * return to the scheduler
50 if (needToYieldToReturningWorker()) {
51 return; /* still hold the lock */
54 RELEASE_LOCK(&sched_mutex);
55 } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE);
58 #ifdef RTS_SUPPORTS_THREADS
60 wakeBlockedWorkerThread()