Changeset 37d188f for global.c


Ignore:
Timestamp:
Mar 25, 2011, 3:46:46 AM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Children:
0af5f9d
Parents:
87833a8
git-author:
David Benjamin <davidben@mit.edu> (02/26/11 14:38:04)
git-committer:
David Benjamin <davidben@mit.edu> (03/25/11 03:46:46)
Message:
Allow interrupts to be taken at any point

This way we can catch SIGINT in the middle of a search if we care.
(Though ideally we wouldn't block the event loop when searching like
this.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    rfafb842 r37d188f  
    113113  g->timerlist = NULL;
    114114  g->kill_buffer = NULL;
     115
     116  g->interrupt_count = 0;
     117  g->interrupt_lock = g_mutex_new();
    115118}
    116119
     
    930933  g->kill_buffer = g_strndup(kill, len);
    931934}
     935
     936void owl_global_add_interrupt(owl_global *g) {
     937  /* TODO: This can almost certainly be done with atomic
     938   * operations. Whatever. */
     939  g_mutex_lock(g->interrupt_lock);
     940  g->interrupt_count++;
     941  g_mutex_unlock(g->interrupt_lock);
     942}
     943
     944bool owl_global_take_interrupt(owl_global *g) {
     945  bool ans = false;
     946  g_mutex_lock(g->interrupt_lock);
     947  if (g->interrupt_count > 0) {
     948    ans = true;
     949    g->interrupt_count--;
     950  }
     951  g_mutex_unlock(g->interrupt_lock);
     952  return ans;
     953}
Note: See TracChangeset for help on using the changeset viewer.