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)
28 #ifdef RTS_SUPPORTS_THREADS
29 // Small optimisation: we don't want the waiting thread to wake
30 // up straight away just because a previous returning worker has
31 // called abandonRequestWait(). If the event is no longer needed,
32 // reset it. We must do this inside the sched_mutex.
33 if (!needToYieldToReturningWorker()) {
34 resetAbandonRequestWait();
39 /* Try to de-queue completed IO requests
41 RELEASE_LOCK(&sched_mutex);
42 ret = awaitRequests(wait);
43 ACQUIRE_LOCK(&sched_mutex);
45 return; /* still hold the lock */
48 // Return to the scheduler if:
50 // - we were interrupted
51 // - new threads have arrived
52 // - another worker wants to take over (RTS_SUPPORTS_THREADS)
56 && run_queue_hd == END_TSO_QUEUE
57 #ifdef RTS_SUPPORTS_THREADS
58 && !needToYieldToReturningWorker()
63 #ifdef RTS_SUPPORTS_THREADS
65 wakeBlockedWorkerThread()