Changeset 87833a8 for signal.c


Ignore:
Timestamp:
Mar 25, 2011, 3:46:46 AM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
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)
Message:
Make owl_signal_init take a signal-thread callback

Instead of pushing the work directly the main thread. This will allow us
to react to SIGINT earlier.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • signal.c

    rfafb842 r87833a8  
    1212
    1313static gpointer signal_thread_func(gpointer data);
    14 static gboolean signal_thunk(gpointer data);
    1514
     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.) */
    1621void owl_signal_init(const sigset_t *set, void (*callback)(int, void*), void *data) {
    1722  GError *error = NULL;
     
    2328  pthread_sigmask(SIG_BLOCK, set, NULL);
    2429  /* 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);
    2731  if (signal_thread == NULL) {
    2832    fprintf(stderr, "Failed to create signal thread: %s\n", error->message);
     
    3236
    3337static gpointer signal_thread_func(gpointer data) {
    34   GMainContext *context = data;
    35 
    3638  while (1) {
    37     GSource *source;
    38     int signal;
     39     int signal;
    3940    int ret;
    4041
     
    4445      continue;
    4546
    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);
    5248  }
    5349  return NULL;
    5450}
    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.