X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=src%2Fabort.c;h=61234a06f5743747687e6fbf397763dae528598c;hb=c6be847cfdfb0dafed7d77bb0895bf4bfb049e0a;hp=63ef3bd1c15a7dfa2e453b70b85a7036a0c76777;hpb=5292406311d31682a850baf059cab01a6f0262b2;p=rodin%2Fchimara.git diff --git a/src/abort.c b/src/abort.c index 63ef3bd..61234a0 100644 --- a/src/abort.c +++ b/src/abort.c @@ -2,38 +2,21 @@ #include #include -static GMutex *abort_lock = NULL; -static gboolean abort_signalled = FALSE; -static void (*interrupt_handler)(void) = NULL; +#include "chimara-glk-private.h" -/* Internal function: initialize the interrupt handling system. */ -void -interrupt_init() -{ - abort_lock = g_mutex_new(); -} - -/* Internal function: free the resources allocated in interrupt_init(). */ -void -interrupt_free() -{ - g_mutex_lock(abort_lock); - /* Make sure no other thread is busy with this */ - g_mutex_unlock(abort_lock); - g_mutex_free(abort_lock); - abort_lock = NULL; -} +extern ChimaraGlkPrivate *glk_data; /** * glk_set_interrupt_handler: - * @func: A pointer to a function which takes no argument and returns no result. + * @func: A pointer to an interrupt handler function. * - * Specifies an interrupt handler function for cleaning up critical resources. - * If Glk receives an interrupt, and you have set an interrupt handler, your - * handler will be called, before the process is shut down. + * Sets @func to be the interrupt handler. @func should be a pointer to a + * function which takes no argument and returns no result. If Glk receives an + * interrupt, and you have set an interrupt handler, your handler will be + * called, before the process is shut down. * * Initially there is no interrupt handler. You can reset to not having any by - * calling glk_set_interrupt_handler(%NULL). + * calling #glk_set_interrupt_handler(%NULL). * * If you call glk_set_interrupt_handler() with a new handler function while an * older one is set, the new one replaces the old one. Glk does not try to queue @@ -46,25 +29,17 @@ interrupt_free() void glk_set_interrupt_handler(void (*func)(void)) { - interrupt_handler = func; -} - -/* Internal function: Free all Glk resources. */ -void -cleanup() -{ - events_free(); - interrupt_free(); + glk_data->interrupt_handler = func; } /* Internal function: abort this Glk program, freeing resources and calling the user's interrupt handler. */ -void +static void abort_glk() { - if(interrupt_handler) - (*interrupt_handler)(); - cleanup(); + if(glk_data->interrupt_handler) + (*(glk_data->interrupt_handler))(); + g_signal_emit_by_name(glk_data->self, "stopped"); g_thread_exit(NULL); } @@ -73,10 +48,10 @@ mutex has already been freed. (That means the thread already ended.) */ void signal_abort() { - if(abort_lock) { - g_mutex_lock(abort_lock); - abort_signalled = TRUE; - g_mutex_unlock(abort_lock); + if(glk_data && glk_data->abort_lock) { + g_mutex_lock(glk_data->abort_lock); + glk_data->abort_signalled = TRUE; + g_mutex_unlock(glk_data->abort_lock); /* Stop blocking on the event queue condition */ event_throw(evtype_Abort, NULL, 0, 0); } @@ -86,13 +61,11 @@ signal_abort() void check_for_abort() { - g_mutex_lock(abort_lock); - if(abort_signalled) + g_mutex_lock(glk_data->abort_lock); + if(glk_data->abort_signalled) { - g_mutex_unlock(abort_lock); + g_mutex_unlock(glk_data->abort_lock); abort_glk(); } - g_mutex_unlock(abort_lock); + g_mutex_unlock(glk_data->abort_lock); } - -