Revert "rts: add Emacs 'Local Variables' to every .c file"
[ghc.git] / rts / win32 / AwaitEvent.c
1 #if !defined(THREADED_RTS) /* to the end */
2 /*
3 * Wait/check for external events. Periodically, the
4 * Scheduler checks for the completion of external operations,
5 * like the expiration of timers, completion of I/O requests
6 * issued by Haskell threads.
7 *
8 * If the Scheduler is otherwise out of work, it'll block
9 * herein waiting for external events to occur.
10 *
11 * This file mirrors the select()-based functionality
12 * for POSIX / Unix platforms in rts/Select.c, but for
13 * Win32.
14 *
15 */
16 #include "Rts.h"
17 #include "Schedule.h"
18 #include "AwaitEvent.h"
19 #include <windows.h>
20 #include "win32/AsyncIO.h"
21 #include "win32/ConsoleHandler.h"
22
23 // Used to avoid calling abandonRequestWait() if we don't need to.
24 // Protected by sched_mutex.
25 static nat workerWaitingForRequests = 0;
26
27 void
28 awaitEvent(rtsBool wait)
29 {
30 do {
31 /* Try to de-queue completed IO requests
32 */
33 workerWaitingForRequests = 1;
34 awaitRequests(wait);
35 workerWaitingForRequests = 0;
36
37 // If a signal was raised, we need to service it
38 // XXX the scheduler loop really should be calling
39 // startSignalHandlers(), but this is the way that posix/Select.c
40 // does it and I'm feeling too paranoid to refactor it today --SDM
41 if (stg_pending_events != 0) {
42 startSignalHandlers(&MainCapability);
43 return;
44 }
45
46 // The return value from awaitRequests() is a red herring: ignore
47 // it. Return to the scheduler if !wait, or
48 //
49 // - we were interrupted
50 // - the run-queue is now non- empty
51
52 } while (wait
53 && sched_state == SCHED_RUNNING
54 && emptyRunQueue(&MainCapability)
55 );
56 }
57 #endif