Changeset 6fc40a7


Ignore:
Timestamp:
Oct 27, 2009, 12:41:17 AM (14 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:
f1a2736
Parents:
18fdd5f9
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> (10/24/09 17:38:24)
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> (10/27/09 00:41:17)
Message:
Rip out the old dispatch API.

Signed-off-by: Alejandro R. Sedeño <asedeno@mit.edu>
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • global.c

    rdf0138f r6fc40a7  
    112112
    113113  owl_message_init_fmtext_cache();
    114   owl_list_create(&(g->dispatchlist));
    115114  owl_list_create(&(g->io_dispatch_list));
    116115  owl_list_create(&(g->psa_list));
     
    941940}
    942941
    943 owl_list *owl_global_get_dispatchlist(owl_global *g)
    944 {
    945   return &(g->dispatchlist);
    946 }
    947 
    948942owl_list *owl_global_get_io_dispatch_list(owl_global *g)
    949943{
  • owl.h

    r18fdd5f9 r6fc40a7  
    500500  owl_list strings;
    501501} owl_obarray;
    502 
    503 typedef struct _owl_dispatch {
    504   int fd;                                 /* FD to watch for dispatch. */
    505   int needs_gc;
    506   void (*cfunc)(struct _owl_dispatch*);   /* C function to dispatch to. */
    507   void (*destroy)(struct _owl_dispatch*); /* Destructor */
    508   void *data;
    509 } owl_dispatch;
    510502
    511503typedef struct _owl_io_dispatch {
     
    603595  struct termios startup_tio;
    604596  owl_obarray obarray;
    605   owl_list dispatchlist;
    606597  owl_list io_dispatch_list;
    607598  owl_list psa_list;
  • select.c

    rffc4df6 r6fc40a7  
    7979
    8080  timeout->tv_nsec = 0;
    81 }
    82 
    83 /* Returns the index of the dispatch for the file descriptor. */
    84 int owl_select_find_dispatch(int fd)
    85 {
    86   int i, len;
    87   const owl_list *dl;
    88   const owl_dispatch *d;
    89  
    90   dl = owl_global_get_dispatchlist(&g);
    91   len = owl_list_get_size(dl);
    92   for(i = 0; i < len; i++) {
    93     d = owl_list_get_element(dl, i);
    94     if (d->fd == fd) return i;
    95   }
    96   return -1;
    97 }
    98 
    99 void owl_select_remove_dispatch_at(int elt) /* noproto */
    100 {
    101   owl_list *dl;
    102   owl_dispatch *d;
    103 
    104   dl = owl_global_get_dispatchlist(&g);
    105   d = owl_list_get_element(dl, elt);
    106   owl_list_remove_element(dl, elt);
    107   if (d->destroy) {
    108     d->destroy(d);
    109   }
    110 }
    111 
    112 /* Adds a new owl_dispatch to the list, replacing existing ones if needed. */
    113 void owl_select_add_dispatch(owl_dispatch *d)
    114 {
    115   int elt;
    116   owl_list *dl;
    117 
    118   d->needs_gc = 0;
    119 
    120   elt = owl_select_find_dispatch(d->fd);
    121   dl = owl_global_get_dispatchlist(&g);
    122  
    123   if (elt != -1) {  /* If we have a dispatch for this FD */
    124     owl_dispatch *d_old;
    125     d_old = owl_list_get_element(dl, elt);
    126     /* Ignore if we're adding the same dispatch again.  Otherwise
    127        replace the old dispatch. */
    128     if (d_old != d) {
    129       owl_select_remove_dispatch_at(elt);
    130     }
    131   }
    132   owl_list_append_element(dl, d);
    133 }
    134 
    135 /* Removes an owl_dispatch to the list, based on it's file descriptor. */
    136 void owl_select_remove_dispatch(int fd)
    137 {
    138   int elt;
    139   owl_list *dl;
    140   owl_dispatch *d;
    141 
    142   elt = owl_select_find_dispatch(fd);
    143   if(elt == -1) {
    144     return;
    145   } else if(dispatch_active) {
    146     /* Defer the removal until dispatch is done walking the list */
    147     dl = owl_global_get_dispatchlist(&g);
    148     d = owl_list_get_element(dl, elt);
    149     d->needs_gc = 1;
    150   } else {
    151     owl_select_remove_dispatch_at(elt);
    152   }
    153 }
    154 
    155 int owl_select_dispatch_count(void)
    156 {
    157   return owl_list_get_size(owl_global_get_dispatchlist(&g));
    158 }
    159 
    160 int owl_select_dispatch_prepare_fd_sets(fd_set *r, fd_set *e)
    161 {
    162   int i, len, max_fd;
    163   owl_dispatch *d;
    164   const owl_list *dl;
    165 
    166   dl = owl_global_get_dispatchlist(&g);
    167   max_fd = 0;
    168   len = owl_select_dispatch_count();
    169   for(i = 0; i < len; i++) {
    170     d = owl_list_get_element(dl, i);
    171     FD_SET(d->fd, r);
    172     FD_SET(d->fd, e);
    173     if (max_fd < d->fd) max_fd = d->fd;
    174   }
    175   return max_fd + 1;
    176 }
    177 
    178 void owl_select_gc(void)
    179 {
    180   int i;
    181   owl_list *dl;
    182 
    183   dl = owl_global_get_dispatchlist(&g);
    184   /*
    185    * Count down so we aren't set off by removing items from the list
    186    * during the iteration.
    187    */
    188   for(i = owl_list_get_size(dl) - 1; i >= 0; i--) {
    189     const owl_dispatch *d = owl_list_get_element(dl, i);
    190     if(d->needs_gc) {
    191       owl_select_remove_dispatch_at(i);
    192     }
    193   }
    194 }
    195 
    196 void owl_select_dispatch(fd_set *fds, int max_fd)
    197 {
    198   int i, len;
    199   owl_dispatch *d;
    200   const owl_list *dl;
    201 
    202   dl = owl_global_get_dispatchlist(&g);
    203   len = owl_select_dispatch_count();
    204 
    205   dispatch_active = 1;
    206 
    207   for(i = 0; i < len; i++) {
    208     d = owl_list_get_element(dl, i);
    209     /* While d shouldn't normally be null, the list may be altered by
    210      * functions we dispatch to. */
    211     if (d != NULL && !d->needs_gc && FD_ISSET(d->fd, fds)) {
    212       if (d->cfunc != NULL) {
    213         d->cfunc(d);
    214       }
    215     }
    216   }
    217 
    218   dispatch_active = 0;
    219   owl_select_gc();
    22081}
    22182
     
    546407  FD_ZERO(&e);
    547408
    548   max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e);
    549   max_fd2 = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e);
    550   if (max_fd < max_fd2) max_fd = max_fd2;
     409  max_fd = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e);
    551410
    552411  /* AIM HACK:
     
    617476    /* NOTE: the same dispatch function is called for both exceptional
    618477       and read ready FDs. */
    619     owl_select_dispatch(&r, max_fd);
    620478    owl_select_io_dispatch(&r, &w, &e, max_fd);
    621479  }
Note: See TracChangeset for help on using the changeset viewer.