Changeset 4f2166b9a2565b2ccc5fbcbb9869b2a41119a342

Show
Ignore:
Timestamp:
10/19/09 22:14:15 (5 weeks ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> / 2009-10-13T03:01:31Z-0400
Parents:
cc1a6d41c20d85ff1ef77c4f918f98a62291088f
Children:
dbf94e9d63a677506783cbdb11f0d965aa5f1d70
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> / 2009-10-19T22:14:15Z-0400
Message:
Add a pre-select action list.

Allow us to add actions that should be performed before calling
pselect(). If the action performs any useful work, it should return
non-zero. If any of the actions return a non-zero value, the timeout
for pselect() will be set to 0s, so that we can process all of these
actions again in case they are interacting with one another, while
still keeping an eye on our file descriptors and timers.
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • global.c

    r40bda84 r4f2166b  
    113113  owl_message_init_fmtext_cache(); 
    114114  owl_list_create(&(g->dispatchlist)); 
     115  owl_list_create(&(g->psa_list)); 
    115116  g->timerlist = NULL; 
    116117  g->interrupted = FALSE; 
     
    953954} 
    954955 
     956owl_list *owl_global_get_psa_list(owl_global *g) 
     957{ 
     958  return &(g->psa_list); 
     959} 
     960 
    955961GList **owl_global_get_timerlist(owl_global *g) 
    956962{ 
  • owl.h

    r40bda84 r4f2166b  
    504504  void *data; 
    505505} owl_dispatch; 
     506 
     507typedef struct _owl_ps_action { 
     508  int needs_gc; 
     509  int (*callback)(struct _owl_ps_action *, void *); 
     510  void (*destroy)(struct _owl_ps_action *); 
     511  void *data; 
     512} owl_ps_action; 
    506513 
    507514typedef struct _owl_popexec { 
     
    584591  owl_obarray obarray; 
    585592  owl_list dispatchlist; 
     593  owl_list psa_list; 
    586594  GList *timerlist; 
    587595  owl_timer *aim_nop_timer; 
  • select.c

    r9f5e847 r4f2166b  
    22 
    33static int dispatch_active = 0; 
     4static int psa_active = 0; 
    45 
    56int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) { 
     
    353354} 
    354355 
     356owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data) 
     357{ 
     358  owl_ps_action *a = owl_malloc(sizeof(owl_ps_action)); 
     359  owl_list *psa_list = owl_global_get_psa_list(&g); 
     360  a->needs_gc = 0; 
     361  a->callback = cb; 
     362  a->destroy = destroy; 
     363  a->data = data; 
     364  owl_list_append_element(psa_list, a); 
     365  return a; 
     366} 
     367 
     368void owl_select_psa_gc(void) 
     369{ 
     370  int i; 
     371  owl_list *psa_list; 
     372  owl_ps_action *a; 
     373 
     374  psa_list = owl_global_get_psa_list(&g); 
     375  for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) { 
     376    a = owl_list_get_element(psa_list, i); 
     377    if (a->needs_gc) { 
     378      owl_list_remove_element(psa_list, i); 
     379      if (a->destroy) { 
     380        a->destroy(a); 
     381      } 
     382      owl_free(a); 
     383    } 
     384  } 
     385} 
     386 
     387void owl_select_remove_pre_select_action(owl_ps_action *a) 
     388{ 
     389  a->needs_gc = 1; 
     390  if (!psa_active) 
     391    owl_select_psa_gc(); 
     392} 
     393 
     394int owl_select_do_pre_select_actions(void) 
     395{ 
     396  int i, len, ret; 
     397  owl_list *psa_list; 
     398 
     399  psa_active = 1; 
     400  ret = 0; 
     401  psa_list = owl_global_get_psa_list(&g); 
     402  len = owl_list_get_size(psa_list); 
     403  for (i = 0; i < len; i++) { 
     404    owl_ps_action *a = owl_list_get_element(psa_list, i); 
     405    if (a->callback != NULL && a->callback(a, a->data)) { 
     406      ret = 1; 
     407    } 
     408  } 
     409  psa_active = 0; 
     410  owl_select_psa_gc(); 
     411  return ret; 
     412} 
     413 
    355414void owl_select(void) 
    356415{ 
     
    400459  /* END AIM HACK */ 
    401460 
     461  if (owl_select_do_pre_select_actions()) { 
     462    timeout.tv_sec = 0; 
     463    timeout.tv_nsec = 0; 
     464  } 
     465 
    402466  ret = pselect(max_fd+1, &r, &aim_wfds, &e, &timeout, &mask); 
    403467