Changeset 4f2166b for select.c


Ignore:
Timestamp:
Oct 19, 2009, 10:14:15 PM (15 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.10, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
dbf94e9
Parents:
cc1a6d4
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> (10/13/09 03:01:31)
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> (10/19/09 22:14:15)
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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.