Changeset 58d1f8a


Ignore:
Timestamp:
Dec 11, 2008, 10:21:13 PM (12 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
80a465c
Parents:
ca1fc33a
Message:
GSequence is newer than we'd like. Use GList for timers instead.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • global.c

    rb9cb41b r58d1f8a  
    116116  owl_message_init_fmtext_cache();
    117117  owl_list_create(&(g->dispatchlist));
    118   g->timerlist = g_sequence_new(NULL);
     118  g->timerlist = NULL;
    119119}
    120120
     
    957957}
    958958
    959 GSequence *owl_global_get_timerlist(owl_global *g)
    960 {
    961     return g->timerlist;
    962 }
     959GList **owl_global_get_timerlist(owl_global *g)
     960{
     961  return &(g->timerlist);
     962}
  • owl.h

    rb7bb454 r58d1f8a  
    602602  owl_obarray obarray;
    603603  owl_list dispatchlist;
    604   GSequence *timerlist;
     604  GList *timerlist;
    605605  owl_timer *aim_nop_timer;
    606606} owl_global;
  • select.c

    rca1fc33a r58d1f8a  
    33static const char fileIdent[] = "$Id: select.c 894 2008-01-17 07:13:44Z asedeno $";
    44
    5 int _owl_select_timer_cmp(owl_timer *t1, owl_timer *t2, void *data) {
     5int _owl_select_timer_cmp(owl_timer *t1, owl_timer *t2) {
    66  return t1->time - t2->time;
    77}
    88
    9 int _owl_select_timer_eq(owl_timer *t1, owl_timer *t2, void *data) {
     9int _owl_select_timer_eq(owl_timer *t1, owl_timer *t2) {
    1010  return t1 == t2;
    1111}
     
    1414{
    1515  owl_timer *t = owl_malloc(sizeof(owl_timer));
    16   GSequence *timers = owl_global_get_timerlist(&g);
     16  GList **timers = owl_global_get_timerlist(&g);
    1717
    1818  t->time = time(NULL) + after;
     
    2121  t->data = data;
    2222
    23   g_sequence_insert_sorted(timers, t,
    24                            (GCompareDataFunc)_owl_select_timer_cmp, NULL);
     23  *timers = g_list_insert_sorted(*timers, t,
     24                                 (GCompareFunc)_owl_select_timer_cmp);
    2525  return t;
    2626}
     
    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) {
     30  GList **timers = owl_global_get_timerlist(&g);
     31  if (t && g_list_find(*timers, t)) {
     32    *timers = g_list_remove(*timers, t);
    3433    owl_free(t);
    35     g_sequence_remove(it);
    3634  }
    3735}
     
    4038{
    4139  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);
     40  GList **timers = owl_global_get_timerlist(&g);
     41
     42  while(*timers) {
     43    owl_timer *t = (*timers)->data;
    4644    void (*cb)(struct _owl_timer *, void *);
    4745    void *data;
     
    5654    if(t->interval > 0) {
    5755      t->time = now + t->interval;
    58       g_sequence_sort_changed(it, (GCompareDataFunc)_owl_select_timer_cmp, NULL);
     56      *timers = g_list_remove(*timers, t);
     57      *timers = g_list_insert_sorted(*timers, t,
     58                                     (GCompareFunc)_owl_select_timer_cmp);
    5959    } else {
    6060      owl_select_remove_timer(t);
     
    6464    /* Do the callback */
    6565    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)) {
     66  }
     67
     68  if(*timers) {
     69    owl_timer *t = (*timers)->data;
     70    timeout->tv_sec = t->time - now;
     71    if (timeout->tv_sec > 60)
     72      timeout->tv_sec = 60;
     73  } else {
    7174    timeout->tv_sec = 60;
    72   } else {
    73     owl_timer *t = g_sequence_get(it);
    74     timeout->tv_sec = t->time - now;
    7575  }
    7676
Note: See TracChangeset for help on using the changeset viewer.