Changeset ca1fc33a


Ignore:
Timestamp:
Dec 11, 2008, 4:37:41 PM (12 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:
58d1f8a
Parents:
86bf047
Message:
Nit: Make indentation a consistent 2 spaces
File:
1 edited

Legend:

Unmodified
Added
Removed
  • select.c

    r86bf047 rca1fc33a  
    44
    55int _owl_select_timer_cmp(owl_timer *t1, owl_timer *t2, void *data) {
    6     return t1->time - t2->time;
     6  return t1->time - t2->time;
    77}
    88
    99int _owl_select_timer_eq(owl_timer *t1, owl_timer *t2, void *data) {
    10     return t1 == t2;
     10  return t1 == t2;
    1111}
    1212
    1313owl_timer *owl_select_add_timer(int after, int interval, void (*cb)(struct _owl_timer *, void *), void *data)
    1414{
    15     owl_timer *t = owl_malloc(sizeof(owl_timer));
    16     GSequence *timers = owl_global_get_timerlist(&g);
    17 
    18     t->time = time(NULL) + after;
    19     t->interval = interval;
    20     t->callback = cb;
    21     t->data = data;
    22 
    23     g_sequence_insert_sorted(timers, t,
    24                              (GCompareDataFunc)_owl_select_timer_cmp, NULL);
    25     return t;
     15  owl_timer *t = owl_malloc(sizeof(owl_timer));
     16  GSequence *timers = owl_global_get_timerlist(&g);
     17
     18  t->time = time(NULL) + after;
     19  t->interval = interval;
     20  t->callback = cb;
     21  t->data = data;
     22
     23  g_sequence_insert_sorted(timers, t,
     24                           (GCompareDataFunc)_owl_select_timer_cmp, NULL);
     25  return t;
    2626}
    2727
    2828void owl_select_remove_timer(owl_timer *t)
    2929{
    30     GSequenceIter *it = g_sequence_search(owl_global_get_timerlist(&g),
    31                                           t, (GCompareDataFunc)_owl_select_timer_eq, NULL);
    32     if(!g_sequence_iter_is_end(it) &&
    33        g_sequence_get(it) == t) {
    34         owl_free(t);
    35         g_sequence_remove(it);
    36     }
     30  GSequenceIter *it = g_sequence_search(owl_global_get_timerlist(&g),
     31                                        t, (GCompareDataFunc)_owl_select_timer_eq, NULL);
     32  if(!g_sequence_iter_is_end(it) &&
     33     g_sequence_get(it) == t) {
     34    owl_free(t);
     35    g_sequence_remove(it);
     36  }
    3737}
    3838
    3939void owl_select_process_timers(struct timeval *timeout)
    4040{
    41     time_t now = time(NULL);
    42     GSequenceIter *it = g_sequence_get_begin_iter(owl_global_get_timerlist(&g));
    43 
    44     while(!g_sequence_iter_is_end(it)) {
    45         owl_timer *t = g_sequence_get(it);
    46         void (*cb)(struct _owl_timer *, void *);
    47         void *data;
    48 
    49         if(t->time > now)
    50             break;
    51 
    52         cb = t->callback;
    53         data = t->data;
    54 
    55         /* Reschedule if appropriate */
    56         if(t->interval > 0) {
    57           t->time = now + t->interval;
    58           g_sequence_sort_changed(it, (GCompareDataFunc)_owl_select_timer_cmp, NULL);
    59         } else {
    60           owl_select_remove_timer(t);
    61           t = NULL;
    62         }
    63 
    64         /* Do the callback */
    65         cb(t, data);
    66 
    67         it = g_sequence_get_begin_iter(owl_global_get_timerlist(&g));
    68     }
    69 
    70     if(g_sequence_iter_is_end(it)) {
    71         timeout->tv_sec = 60;
     41  time_t now = time(NULL);
     42  GSequenceIter *it = g_sequence_get_begin_iter(owl_global_get_timerlist(&g));
     43
     44  while(!g_sequence_iter_is_end(it)) {
     45    owl_timer *t = g_sequence_get(it);
     46    void (*cb)(struct _owl_timer *, void *);
     47    void *data;
     48
     49    if(t->time > now)
     50      break;
     51
     52    cb = t->callback;
     53    data = t->data;
     54
     55    /* Reschedule if appropriate */
     56    if(t->interval > 0) {
     57      t->time = now + t->interval;
     58      g_sequence_sort_changed(it, (GCompareDataFunc)_owl_select_timer_cmp, NULL);
    7259    } else {
    73         owl_timer *t = g_sequence_get(it);
    74         timeout->tv_sec = t->time - now;
    75     }
    76 
    77     timeout->tv_usec = 0;
     60      owl_select_remove_timer(t);
     61      t = NULL;
     62    }
     63
     64    /* Do the callback */
     65    cb(t, data);
     66
     67    it = g_sequence_get_begin_iter(owl_global_get_timerlist(&g));
     68  }
     69
     70  if(g_sequence_iter_is_end(it)) {
     71    timeout->tv_sec = 60;
     72  } else {
     73    owl_timer *t = g_sequence_get(it);
     74    timeout->tv_sec = t->time - now;
     75  }
     76
     77  timeout->tv_usec = 0;
    7878}
    7979
Note: See TracChangeset for help on using the changeset viewer.