5 #include "chimara-glk-private.h"
7 extern ChimaraGlkPrivate *glk_data;
10 * glk_set_interrupt_handler:
11 * @func: A pointer to an interrupt handler function.
13 * Sets @func to be the interrupt handler. @func should be a pointer to a
14 * function which takes no argument and returns no result. If Glk receives an
15 * interrupt, and you have set an interrupt handler, your handler will be
16 * called, before the process is shut down.
18 * Initially there is no interrupt handler. You can reset to not having any by
19 * calling <code>#glk_set_interrupt_handler(%NULL)</code>.
21 * If you call glk_set_interrupt_handler() with a new handler function while an
22 * older one is set, the new one replaces the old one. Glk does not try to queue
25 * You should not try to interact with the player in your interrupt handler. Do
26 * not call glk_select() or glk_select_poll(). Anything you print to a window
27 * may not be visible to the player.
30 glk_set_interrupt_handler(void (*func)(void))
32 glk_data->interrupt_handler = func;
35 /* Internal function: abort this Glk program, freeing resources and calling the
36 user's interrupt handler. */
40 if(glk_data->interrupt_handler)
41 (*(glk_data->interrupt_handler))();
42 g_signal_emit_by_name(glk_data->self, "stopped");
46 /* Internal function: Signal this Glk thread to abort. Does nothing if the abort
47 mutex has already been freed. (That means the thread already ended.) */
51 if(glk_data && glk_data->abort_lock) {
52 g_mutex_lock(glk_data->abort_lock);
53 glk_data->abort_signalled = TRUE;
54 g_mutex_unlock(glk_data->abort_lock);
55 /* Stop blocking on the event queue condition */
56 event_throw(evtype_Abort, NULL, 0, 0);
60 /* Internal function: check if the Glk program has been interrupted. */
64 g_mutex_lock(glk_data->abort_lock);
65 if(glk_data->abort_signalled)
67 g_mutex_unlock(glk_data->abort_lock);
70 g_mutex_unlock(glk_data->abort_lock);