Changeset c675b39 for select.c


Ignore:
Timestamp:
Dec 17, 2008, 3:24:25 PM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
1631825
Parents:
e0096b7
git-author:
Nelson Elhage <nelhage@mit.edu> (12/15/08 21:26:36)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/17/08 15:24:25)
Message:
Give timers a destructor field.

Perl timers are going to need this in order to free the SV* callback
we're holding onto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • select.c

    r58d1f8a rc675b39  
    1111}
    1212
    13 owl_timer *owl_select_add_timer(int after, int interval, void (*cb)(struct _owl_timer *, void *), void *data)
     13owl_timer *owl_select_add_timer(int after, int interval, void (*cb)(owl_timer *, void *), void (*destroy)(owl_timer*), void *data)
    1414{
    1515  owl_timer *t = owl_malloc(sizeof(owl_timer));
     
    1919  t->interval = interval;
    2020  t->callback = cb;
     21  t->destroy = destroy;
    2122  t->data = data;
    2223
     
    3132  if (t && g_list_find(*timers, t)) {
    3233    *timers = g_list_remove(*timers, t);
     34    if(t->destroy) {
     35      t->destroy(t);
     36    }
    3337    owl_free(t);
    3438  }
     
    4246  while(*timers) {
    4347    owl_timer *t = (*timers)->data;
    44     void (*cb)(struct _owl_timer *, void *);
    45     void *data;
     48    int remove = 0;
    4649
    4750    if(t->time > now)
    4851      break;
    49 
    50     cb = t->callback;
    51     data = t->data;
    5252
    5353    /* Reschedule if appropriate */
     
    5858                                     (GCompareFunc)_owl_select_timer_cmp);
    5959    } else {
     60      remove = 1;
     61    }
     62
     63    /* Do the callback */
     64    t->callback(t, t->data);
     65    if(remove) {
    6066      owl_select_remove_timer(t);
    61       t = NULL;
    62     }
    63 
    64     /* Do the callback */
    65     cb(t, data);
     67    }
    6668  }
    6769
Note: See TracChangeset for help on using the changeset viewer.