66 |
|
|
67 |
/* Node in timer queue. */ |
/* Node in timer queue. */ |
68 |
struct timer_pq_node { |
struct timer_pq_node { |
|
timer_id id; |
|
69 |
time_t next_alarm; |
time_t next_alarm; |
70 |
unsigned long int time_incr; |
unsigned long int time_incr; |
71 |
long int time_shift; |
long int time_shift; |
313 |
dmx_dispatch_timer (timer_id id) |
dmx_dispatch_timer (timer_id id) |
314 |
{ |
{ |
315 |
struct timer_pq_node *node; |
struct timer_pq_node *node; |
|
struct timer_pq_node tmp_node; |
|
316 |
|
|
317 |
tmp_node.id = id; |
node = pq_get_func (id, &timer_q); |
|
node = pq_get_func (&tmp_node, &timer_q); |
|
318 |
|
|
319 |
if (node && get_uptime() >= node->next_alarm) |
if (node && get_uptime() >= node->next_alarm) |
320 |
proc_timer (node); |
proc_timer (node); |
358 |
void * |
void * |
359 |
dmx_remove_timer (timer_id id) |
dmx_remove_timer (timer_id id) |
360 |
{ |
{ |
|
struct timer_pq_node tmp_node; |
|
361 |
struct timer_pq_node* node; |
struct timer_pq_node* node; |
362 |
void *data = NULL; |
void *data = NULL; |
363 |
|
|
364 |
tmp_node.id = id; |
node = (struct timer_pq_node *)pq_del_func (id, &timer_q); |
|
node = (struct timer_pq_node *)pq_del_func (&tmp_node, &timer_q); |
|
365 |
if (node) { |
if (node) { |
366 |
data = node->data; |
data = node->data; |
367 |
free (node); |
free (node); |
374 |
static int |
static int |
375 |
timer_eq (void *timer, void *timer2) |
timer_eq (void *timer, void *timer2) |
376 |
{ |
{ |
377 |
return timer && timer2 && ((struct timer_pq_node *)timer)->id |
/* check if it's the same timer, copies not supported */ |
378 |
== ((struct timer_pq_node *)timer2)->id; |
return timer == timer2; |
379 |
} |
} |
380 |
|
|
381 |
/* Stop reporting signal 'signum'. Restores default action for the signal. */ |
/* Stop reporting signal 'signum'. Restores default action for the signal. */ |
485 |
if (timer_q.size == 0) { |
if (timer_q.size == 0) { |
486 |
/* not yet initialized */ |
/* not yet initialized */ |
487 |
if (pq_new (&timer_q, 127, timer_eq) < 0) |
if (pq_new (&timer_q, 127, timer_eq) < 0) |
488 |
return -1; |
return NULL; |
489 |
} |
} |
490 |
|
|
491 |
new_node = (struct timer_pq_node*)malloc (sizeof(struct timer_pq_node)); |
new_node = (struct timer_pq_node*)malloc (sizeof(struct timer_pq_node)); |
|
new_node->id = (int)new_node; |
|
492 |
new_node->next_alarm = next_alarm; |
new_node->next_alarm = next_alarm; |
493 |
new_node->time_incr = time_incr; |
new_node->time_incr = time_incr; |
494 |
new_node->time_shift = time_shift; |
new_node->time_shift = time_shift; |
497 |
|
|
498 |
pq_add (next_alarm, new_node, &timer_q); |
pq_add (next_alarm, new_node, &timer_q); |
499 |
|
|
500 |
return new_node->id; |
return new_node; |
501 |
} |
} |
502 |
|
|
503 |
/* Remove all nodes from the timer queue. */ |
/* Remove all nodes from the timer queue. */ |
572 |
pq_chpri (timer, timer->next_alarm, &timer_q); |
pq_chpri (timer, timer->next_alarm, &timer_q); |
573 |
} |
} |
574 |
else { |
else { |
575 |
dmx_remove_timer (timer->id); |
dmx_remove_timer (timer); |
576 |
} |
} |
577 |
|
|
578 |
callback (data); |
callback (data); |