[project @ 2003-10-20 17:15:27 by sof]
[ghc-hetmet.git] / ghc / rts / win32 / ConsoleHandler.h
1 /*
2  * Console control handler support.
3  *
4  */
5 #ifndef __CONSOLEHANDLER_H__
6 #define __CONSOLEHANDLER_H__
7
8 /*
9  * Console control handlers lets an application handle Ctrl+C, Ctrl+Break etc.
10  * in Haskell under Win32. Akin to the Unix signal SIGINT.
11  *
12  * The API offered by ConsoleHandler.h is identical to that of the signal handling
13  * code (which isn't supported under win32.) Unsurprisingly, the underlying impl 
14  * is derived from the signal handling code also.
15  */
16
17 /*
18  * Function: initUserSignals()
19  *
20  * Initialize the console handling substrate.
21  */
22 extern void initUserSignals(void);
23
24 /*
25  * Function: initDefaultHandlers()
26  *
27  * Install any default signal/console handlers. Currently we install a
28  * Ctrl+C handler that shuts down the RTS in an orderly manner.
29  */
30 extern void initDefaultHandlers(void);
31
32 /*
33  * Function: signals_pending() 
34  * 
35  * Used by the RTS to check whether new signals have been 'recently' reported.
36  * If so, the RTS arranges for the delivered signals to be handled by 
37  * de-queueing them from their table, running the associated Haskell 
38  * signal handler.
39  */
40 extern StgInt stg_pending_events;
41
42 #define signals_pending() ( stg_pending_events > 0)
43
44 /* 
45  * Function: anyUserHandlers()
46  *
47  * Used by the Scheduler to decide whether its worth its while to stick
48  * around waiting for an external signal when there are no threads
49  * runnable. A console handler is used to handle termination events (Ctrl+C)
50  * and isn't considered a 'user handler'.
51  */
52 #define anyUserHandlers() (rtsFalse)
53
54 /*
55  * Function: blockUserSignals()
56  *
57  * Temporarily block the delivery of further console events. Needed to
58  * avoid race conditions when GCing the queue of outstanding handlers or
59  * when emptying the queue by running the handlers.
60  * 
61  */
62 extern void blockUserSignals(void);
63
64 /*
65  * Function: unblockUserSignals()
66  *
67  * The inverse of blockUserSignals(); re-enable the deliver of console events.
68  */
69 extern void unblockUserSignals(void);
70
71 /*
72  * Function: awaitUserSignals()
73  *
74  * Wait for the next console event. Currently a NOP (returns immediately.)
75  */
76 extern void awaitUserSignals(void);
77
78 /*
79  * Function: startSignalHandlers()
80  *
81  * Run the handlers associated with the queued up console events. Console
82  * event delivery is blocked for the duration of this call.
83  */
84 extern void startSignalHandlers(void);
85
86 /*
87  * Function: markSignalHandlers()
88  *
89  * Evacuate the handler queue. _Assumes_ that console event delivery
90  * has already been blocked.
91  */
92 extern void markSignalHandlers (evac_fn evac);
93
94 /*
95  * Function: handleSignalsInThisThread()
96  * 
97  * Have current (OS) thread assume responsibility of handling console events/signals.
98  * Currently not used (by the console event handling code.)
99  */
100 extern void handleSignalsInThisThread(void);
101
102 #endif /* __CONSOLEHANDLER_H__ */