Changeset 96ade35


Ignore:
Timestamp:
Mar 25, 2011, 3:46:46 AM (12 years ago)
Author:
David Benjamin <davidben@mit.edu>
Children:
87833a8
Parents:
fafb842
git-author:
David Benjamin <davidben@mit.edu> (02/26/11 00:17:01)
git-committer:
David Benjamin <davidben@mit.edu> (03/25/11 03:46:46)
Message:
Punt pre-select actions

The three users are now directly handled with GSources.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.h

    rfafb842 r96ade35  
    552552  GPollFD pollfd;
    553553} owl_io_dispatch;
    554 
    555 typedef struct _owl_ps_action {
    556   int needs_gc;
    557   int (*callback)(struct _owl_ps_action *, void *);
    558   void (*destroy)(struct _owl_ps_action *);
    559   void *data;
    560 } owl_ps_action;
    561554
    562555typedef struct _owl_popexec {
  • select.c

    rfafb842 r96ade35  
    33static GMainLoop *loop = NULL;
    44static int dispatch_active = 0;
    5 static int psa_active = 0;
    65
    76static GSource *owl_timer_source;
     
    131130
    132131static gboolean owl_io_dispatch_prepare(GSource *source, int *timeout) {
    133   owl_select_do_pre_select_actions(); /* HACK */
    134132  *timeout = -1;
    135133  return FALSE;
     
    335333    owl_function_makemsg("Unable to handle keypress");
    336334  }
    337 }
    338 
    339 owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data)
    340 {
    341   owl_ps_action *a = g_new(owl_ps_action, 1);
    342   owl_list *psa_list = owl_global_get_psa_list(&g);
    343   a->needs_gc = 0;
    344   a->callback = cb;
    345   a->destroy = destroy;
    346   a->data = data;
    347   owl_list_append_element(psa_list, a);
    348   return a;
    349 }
    350 
    351 void owl_select_psa_gc(void)
    352 {
    353   int i;
    354   owl_list *psa_list;
    355   owl_ps_action *a;
    356 
    357   psa_list = owl_global_get_psa_list(&g);
    358   for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) {
    359     a = owl_list_get_element(psa_list, i);
    360     if (a->needs_gc) {
    361       owl_list_remove_element(psa_list, i);
    362       if (a->destroy) {
    363         a->destroy(a);
    364       }
    365       g_free(a);
    366     }
    367   }
    368 }
    369 
    370 void owl_select_remove_pre_select_action(owl_ps_action *a)
    371 {
    372   a->needs_gc = 1;
    373   if (!psa_active)
    374     owl_select_psa_gc();
    375 }
    376 
    377 int owl_select_do_pre_select_actions(void)
    378 {
    379   int i, len, ret;
    380   owl_list *psa_list;
    381 
    382   psa_active = 1;
    383   ret = 0;
    384   psa_list = owl_global_get_psa_list(&g);
    385   len = owl_list_get_size(psa_list);
    386   for (i = 0; i < len; i++) {
    387     owl_ps_action *a = owl_list_get_element(psa_list, i);
    388     if (a->callback != NULL && a->callback(a, a->data)) {
    389       ret = 1;
    390     }
    391   }
    392   psa_active = 0;
    393   owl_select_psa_gc();
    394   return ret;
    395335}
    396336
Note: See TracChangeset for help on using the changeset viewer.