2 * Console control handler support.
5 #ifndef __CONSOLEHANDLER_H__
6 #define __CONSOLEHANDLER_H__
9 * Console control handlers lets an application handle Ctrl+C, Ctrl+Break etc.
10 * in Haskell under Win32. Akin to the Unix signal SIGINT.
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.
18 * Function: initUserSignals()
20 * Initialize the console handling substrate.
22 extern void initUserSignals(void);
25 * Function: initDefaultHandlers()
27 * Install any default signal/console handlers. Currently we install a
28 * Ctrl+C handler that shuts down the RTS in an orderly manner.
30 extern void initDefaultHandlers(void);
33 * Function: signals_pending()
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
40 extern StgInt stg_pending_events;
42 #define signals_pending() ( stg_pending_events > 0)
45 * Function: anyUserHandlers()
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'.
52 #define anyUserHandlers() (rtsFalse)
55 * Function: blockUserSignals()
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.
62 extern void blockUserSignals(void);
65 * Function: unblockUserSignals()
67 * The inverse of blockUserSignals(); re-enable the deliver of console events.
69 extern void unblockUserSignals(void);
72 * Function: awaitUserSignals()
74 * Wait for the next console event. Currently a NOP (returns immediately.)
76 extern void awaitUserSignals(void);
79 * Function: startSignalHandlers()
81 * Run the handlers associated with the queued up console events. Console
82 * event delivery is blocked for the duration of this call.
84 extern void startSignalHandlers(void);
87 * Function: markSignalHandlers()
89 * Evacuate the handler queue. _Assumes_ that console event delivery
90 * has already been blocked.
92 extern void markSignalHandlers (evac_fn evac);
95 * Function: handleSignalsInThisThread()
97 * Have current (OS) thread assume responsibility of handling console events/signals.
98 * Currently not used (by the console event handling code.)
100 extern void handleSignalsInThisThread(void);
102 #endif /* __CONSOLEHANDLER_H__ */