AwaitEvent.c 1.6 KB
Newer Older
1
#if !defined(THREADED_RTS) /* to the end */
sof's avatar
sof committed
2
3
4
5
6
7
8
9
10
/*
 * Wait/check for external events. Periodically, the
 * Scheduler checks for the completion of external operations,
 * like the expiration of timers, completion of I/O requests
 * issued by Haskell threads.
 *
 * If the Scheduler is otherwise out of work, it'll block
 * herein waiting for external events to occur.
 *
11
 * This file mirrors the select()-based functionality
sof's avatar
sof committed
12
13
14
15
16
17
 * for POSIX / Unix platforms in rts/Select.c, but for
 * Win32.
 *
 */
#include "Rts.h"
#include "Schedule.h"
18
#include "AwaitEvent.h"
sof's avatar
sof committed
19
20
#include <windows.h>
#include "win32/AsyncIO.h"
21
#include "win32/ConsoleHandler.h"
sof's avatar
sof committed
22

23
24
25
26
// Used to avoid calling abandonRequestWait() if we don't need to.
// Protected by sched_mutex.
static nat workerWaitingForRequests = 0;

sof's avatar
sof committed
27
28
29
30
void
awaitEvent(rtsBool wait)
{
  do {
31
32
    /* Try to de-queue completed IO requests
     */
33
    workerWaitingForRequests = 1;
34
    awaitRequests(wait);
35
    workerWaitingForRequests = 0;
36
37
38
39
40
41
42
43
44
45

    // If a signal was raised, we need to service it
    // XXX the scheduler loop really should be calling
    // startSignalHandlers(), but this is the way that posix/Select.c
    // does it and I'm feeling too paranoid to refactor it today --SDM
    if (stg_pending_events != 0) {
        startSignalHandlers(&MainCapability);
        return;
    }

46
47
    // The return value from awaitRequests() is a red herring: ignore
    // it.  Return to the scheduler if !wait, or
48
49
    //
    //  - we were interrupted
50
    //  - the run-queue is now non- empty
sof's avatar
sof committed
51

52
  } while (wait
53
54
           && sched_state == SCHED_RUNNING
           && emptyRunQueue(&MainCapability)
55
      );
sof's avatar
sof committed
56
}
57
#endif