Changeset 87833a8
- Timestamp:
- Mar 25, 2011, 3:46:46 AM (14 years ago)
- Children:
- 37d188f
- Parents:
- 96ade35
- git-author:
- David Benjamin <davidben@mit.edu> (02/26/11 14:11:26)
- git-committer:
- David Benjamin <davidben@mit.edu> (03/25/11 03:46:46)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.c
rfafb842 r87833a8 354 354 } 355 355 356 static void sig_handler(int sig, void *data) { 356 static gboolean sig_handler_main_thread(gpointer data) { 357 int sig = GPOINTER_TO_INT(data); 358 357 359 owl_function_debugmsg("Got signal %d", sig); 358 360 /* TODO: These don't need to be re-entrant anymore! */ … … 372 374 owl_process_input_char(in); 373 375 } 376 return FALSE; 377 } 378 379 static void sig_handler(int sig, void *data) { 380 GMainContext *context = data; 381 GSource *source; 382 383 /* TODO: Special-case SIGINT so that it can interrupt outside the 384 * event loop. */ 385 386 /* Send a message to the main thread. */ 387 source = g_idle_source_new(); 388 g_source_set_priority(source, G_PRIORITY_DEFAULT); 389 g_source_set_callback(source, sig_handler_main_thread, 390 GINT_TO_POINTER(sig), NULL); 391 g_source_attach(source, context); 392 g_source_unref(source); 374 393 } 375 394 … … 385 404 sigaddset(&sigset, SIGINT); 386 405 387 owl_signal_init(&sigset, sig_handler, NULL);406 owl_signal_init(&sigset, sig_handler, g_main_context_default()); 388 407 } 389 408 -
signal.c
rfafb842 r87833a8 12 12 13 13 static gpointer signal_thread_func(gpointer data); 14 static gboolean signal_thunk(gpointer data);15 14 15 /* Initializes the signal thread to listen for 'set' on a dedicated 16 * thread. 'callback' is called *on the signal thread* when a signal 17 * is received. 18 * 19 * This function /must/ be called before any other threads are 20 * created. (Otherwise the signals will not get blocked correctly.) */ 16 21 void owl_signal_init(const sigset_t *set, void (*callback)(int, void*), void *data) { 17 22 GError *error = NULL; … … 23 28 pthread_sigmask(SIG_BLOCK, set, NULL); 24 29 /* Spawn a dedicated thread to sigwait. */ 25 signal_thread = g_thread_create(signal_thread_func, g_main_context_default(), 26 FALSE, &error); 30 signal_thread = g_thread_create(signal_thread_func, NULL, FALSE, &error); 27 31 if (signal_thread == NULL) { 28 32 fprintf(stderr, "Failed to create signal thread: %s\n", error->message); … … 32 36 33 37 static gpointer signal_thread_func(gpointer data) { 34 GMainContext *context = data;35 36 38 while (1) { 37 GSource *source; 38 int signal; 39 int signal; 39 40 int ret; 40 41 … … 44 45 continue; 45 46 46 /* Send a message to the other main. */ 47 source = g_idle_source_new(); 48 g_source_set_priority(source, G_PRIORITY_DEFAULT); 49 g_source_set_callback(source, signal_thunk, GINT_TO_POINTER(signal), NULL); 50 g_source_attach(source, context); 51 g_source_unref(source); 47 signal_cb(signal, signal_cbdata); 52 48 } 53 49 return NULL; 54 50 } 55 56 static gboolean signal_thunk(gpointer data) {57 signal_cb(GPOINTER_TO_INT(data), signal_cbdata);58 return FALSE;59 }
Note: See TracChangeset
for help on using the changeset viewer.