static gboolean owl_timer_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { GList **timers = owl_global_get_timerlist(&g); GTimeVal now; /* TODO: In the far /far/ future, g_source_get_time is what the cool * kids use to get system monotonic time. */ g_source_get_current_time(source, &now); /* FIXME: bother with millisecond accuracy now that we can? */ while(*timers) { owl_timer *t = (*timers)->data; int remove = 0; if(t->time > now.tv_sec) break; /* Reschedule if appropriate */ if(t->interval > 0) { t->time = now.tv_sec + t->interval; *timers = g_list_remove(*timers, t); *timers = g_list_insert_sorted(*timers, t, (GCompareFunc)_owl_select_timer_cmp); } else { remove = 1; } /* Do the callback */ t->callback(t, t->data); if(remove) { owl_select_remove_timer(t); } } return TRUE; }
int owl_variable_pseudologins_set(owl_variable *v, const void *newval) { static owl_timer *timer = NULL; if (newval) { if (*(const int*)newval == 1) { owl_function_zephyr_buddy_check(0); if (timer == NULL) { timer = owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL); } } else { if (timer != NULL) { owl_select_remove_timer(timer); timer = NULL; } } } return owl_variable_bool_set_default(v, newval); }
void owl_select_process_timers(struct timespec *timeout) { time_t now = time(NULL); GList **timers = owl_global_get_timerlist(&g); while(*timers) { owl_timer *t = (*timers)->data; int remove = 0; if(t->time > now) break; /* Reschedule if appropriate */ if(t->interval > 0) { t->time = now + t->interval; *timers = g_list_remove(*timers, t); *timers = g_list_insert_sorted(*timers, t, (GCompareFunc)_owl_select_timer_cmp); } else { remove = 1; } /* Do the callback */ t->callback(t, t->data); if(remove) { owl_select_remove_timer(t); } } if(*timers) { owl_timer *t = (*timers)->data; timeout->tv_sec = t->time - now; if (timeout->tv_sec > 60) timeout->tv_sec = 60; } else { timeout->tv_sec = 60; } timeout->tv_nsec = 0; }