179 static void lock_real(
Timerset *
set,
const char *
file,
long line,
const char *func);
181 lock_real(ts, __FILE__, __LINE__, __func__) 182 static void unlock_real(
Timerset *
set,
const char *
file,
long line,
const char *func);
184 unlock_real(ts, __FILE__, __LINE__, __func__) 209 while (set->heap->len > 0)
229 while (set->heap->len > 0)
249 ret =
set->heap->len;
259 t = gw_malloc(
sizeof(*t));
279 if (timer->
output != NULL)
290 if (timer->
output != NULL)
301 if (timer->
output != NULL)
323 if (interval < timer->elapses && timer->
index == 0)
339 wakeup = timer->
index == 0;
369 if (interval < timer->elapses && timer->
index == 0)
386 wakeup = timer->
index == 0;
414 if (interval < timer->elapses && timer->
index == 0)
431 wakeup = timer->
index == 0;
507 if (set->heap->len == 0) {
515 while (set->heap->len > 0) {
516 Timer *timer =
set->heap->tab[0];
547 static void lock_real(
Timerset *
set,
const char *
file,
long line,
const char *func)
551 debug(
"gw-timer",0,
"timerset lock from %s:%ld:%s",
file, line, func);
554 static void unlock_real(
Timerset *
set,
const char *
file,
long line,
const char *func)
558 debug(
"gw-timer",0,
"timerset unlock from %s:%ld:%s",
file, line, func);
588 if (timer->
output != NULL)
600 heap = gw_malloc(
sizeof(*heap));
601 heap->
tab = gw_malloc(
sizeof(heap->
tab[0]));
630 last = heap->
len - 1;
646 heap->
tab = gw_realloc(heap->
tab,
647 heap->
len *
sizeof(heap->
tab[0]));
650 heap->
tab[heap->
len - 1] = timer;
668 if (index1 == index2)
671 t = heap->
tab[index1];
672 heap->
tab[index1] = heap->
tab[index2];
673 heap->
tab[index2] = t;
707 t = heap->
tab[index];
708 parent = heap->
tab[index / 2];
715 parent = heap->
tab[index / 2];
723 child_index = index * 2;
724 if (child_index >= heap->
len)
726 if (child_index == heap->
len - 1) {
763 if (timer->
output != NULL)
780 while (!set->stopping) {
785 while (set->heap->len > 0 && set->heap->tab[0]->elapses <= now) {
786 Timer *timer =
set->heap->tab[0];
797 if (set->heap->len == 0) {
801 top_time =
set->heap->tab[0]->elapses;
void gw_timerset_destroy(Timerset *set)
void gw_timer_elapsed_destroy_cb(Timer *timer)
void gw_timerset_elapsed_destroy(Timerset *set)
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
void gwlist_produce(List *list, void *item)
volatile sig_atomic_t stopping
void gwthread_join(long thread)
long gw_timerset_count(Timerset *set)
static void abort_elapsed(Timer *timer)
Timer * gw_timer_create(Timerset *set, List *outputlist, void(*callback)(void *))
static void heap_destroy(TimerHeap *heap)
static void heap_insert(TimerHeap *heap, Timer *timer)
void gw_timer_elapsed_stop_cb(Timer *timer)
void gw_timer_elapsed_stop(Timer *timer)
static void lock(Timerset *set)
Timerset * gw_timerset_create(void)
void(* callback)(void *data)
static void elapse_timer(Timer *timer)
void gw_timer_stop(Timer *timer)
void gwlist_remove_producer(List *list)
void gw_timer_elapsed_start_cb(Timer *timer, int interval, void *data)
long gwlist_delete_equal(List *list, void *item)
void gw_timer_destroy(Timer *timer)
static void watch_timers(void *arg)
#define gwthread_create(func, arg)
void gwthread_sleep(double seconds)
void mutex_destroy(Mutex *mutex)
static void heap_swap(TimerHeap *heap, long index1, long index2)
static TimerHeap * heap_create(void)
void gw_timer_elapsed_destroy(Timer *timer)
void debug(const char *place, int err, const char *fmt,...)
void gw_timer_start(Timer *timer, int interval, void *data)
void gw_timer_elapsed_start(Timer *timer, int interval, void *data)
void gwthread_wakeup(long thread)
List * gw_timer_break(Timerset *set)
static void unlock(Timerset *set)
static void heap_delete(TimerHeap *heap, long index)
void gwlist_add_producer(List *list)
static int heap_adjust(TimerHeap *heap, long index)
void * gw_timer_data(Timer *timer)