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