Changeset 47128d9 for global.c


Ignore:
Timestamp:
May 23, 2011, 8:57:46 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
6bd485e
Parents:
1491439
git-author:
David Benjamin <davidben@mit.edu> (02/26/11 14:38:04)
git-committer:
David Benjamin <davidben@mit.edu> (05/23/11 20:57: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

    r257b9c4 r47128d9  
    112112  g->timerlist = NULL;
    113113  g->kill_buffer = NULL;
     114
     115  g->interrupt_count = 0;
     116  g->interrupt_lock = g_mutex_new();
    114117}
    115118
     
    924927  g->kill_buffer = g_strndup(kill, len);
    925928}
     929
     930void owl_global_add_interrupt(owl_global *g) {
     931  /* TODO: This can almost certainly be done with atomic
     932   * operations. Whatever. */
     933  g_mutex_lock(g->interrupt_lock);
     934  g->interrupt_count++;
     935  g_mutex_unlock(g->interrupt_lock);
     936}
     937
     938bool owl_global_take_interrupt(owl_global *g) {
     939  bool ans = false;
     940  g_mutex_lock(g->interrupt_lock);
     941  if (g->interrupt_count > 0) {
     942    ans = true;
     943    g->interrupt_count--;
     944  }
     945  g_mutex_unlock(g->interrupt_lock);
     946  return ans;
     947}
Note: See TracChangeset for help on using the changeset viewer.