- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.