Changeset 47128d9


Ignore:
Timestamp:
May 23, 2011, 8:57:46 PM (14 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.)
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r3535a6e r47128d9  
    29952995      i--;
    29962996    }
    2997 #if 0
    2998     /* FIXME!!! */
    2999     owl_function_mask_sigint(NULL);
    3000     if(owl_global_is_interrupted(&g)) {
    3001       owl_global_unset_interrupted(&g);
    3002       owl_function_unmask_sigint(NULL);
     2997    if (owl_global_take_interrupt(&g)) {
    30032998      owl_function_makemsg("Search interrupted!");
    30042999      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    30053000      return;
    30063001    }
    3007     owl_function_unmask_sigint(NULL);
    3008 #endif
    30093002  }
    30103003  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     
    30893082          ret=ZLocateUser(zstr(user), &numlocs, ZAUTH);
    30903083
    3091 #if 0
    3092           /* FIXME!! */
    3093           owl_function_mask_sigint(NULL);
    3094           if(owl_global_is_interrupted(&g)) {
     3084          if (owl_global_take_interrupt(&g)) {
    30953085            interrupted = 1;
    3096             owl_global_unset_interrupted(&g);
    3097             owl_function_unmask_sigint(NULL);
    30983086            owl_function_makemsg("Interrupted!");
    30993087            break;
    31003088          }
    3101 
    3102           owl_function_unmask_sigint(NULL);
    3103 #endif
    31043089
    31053090          if (ret!=ZERR_NONE) {
     
    35063491}
    35073492
    3508 void owl_function_mask_sigint(sigset_t *oldmask) {
    3509   sigset_t intr;
    3510 
    3511   sigemptyset(&intr);
    3512   sigaddset(&intr, SIGINT);
    3513   sigprocmask(SIG_BLOCK, &intr, oldmask);
    3514 }
    3515 
    3516 void owl_function_unmask_sigint(sigset_t *oldmask) {
    3517   sigset_t intr;
    3518 
    3519   sigemptyset(&intr);
    3520   sigaddset(&intr, SIGINT);
    3521   sigprocmask(SIG_UNBLOCK, &intr, oldmask);
    3522 }
    3523 
    35243493void _owl_function_mark_message(const owl_message *m)
    35253494{
  • 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}
  • owl.c

    r1491439 r47128d9  
    362362  } else if (sig == SIGTERM || sig == SIGHUP) {
    363363    owl_function_quit();
    364   } else if (sig == SIGINT) {
     364  } else if (sig == SIGINT && owl_global_take_interrupt(&g)) {
    365365    owl_input in;
    366366    in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
     
    374374  GSource *source;
    375375
    376   /* TODO: Special-case SIGINT so that it can interrupt outside the
    377    * event loop. */
    378 
     376  /* If it was an interrupt, set a flag so we can handle it earlier if
     377   * needbe. sig_handler_main_thread will check the flag to make sure
     378   * no one else took it. */
     379  if (sig == SIGINT) {
     380    owl_global_add_interrupt(&g);
     381  }
    379382  /* Send a message to the main thread. */
    380383  source = g_idle_source_new();
  • owl.h

    r257b9c4 r47128d9  
    630630  FILE *debug_file;
    631631  char *kill_buffer;
     632  int interrupt_count;
     633  GMutex *interrupt_lock;
    632634} owl_global;
    633635
Note: See TracChangeset for help on using the changeset viewer.