Rename RB timers to timer_tree

This commit is contained in:
Nils Olav Selåsdal
2013-02-21 15:34:12 +01:00
parent df041ccae4
commit 36ac0bffb1
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ struct UCTimer {
/** Timer engine. Must be initialized onnce.*/ /** Timer engine. Must be initialized onnce.*/
struct UCTimers { struct UCTimers {
RBTree timers; RBTree timer_tree;
size_t seq; //used to generate unique timers size_t seq; //used to generate unique timers
TAILQ_HEAD(, UCTimer) ready_list; //pending timers to be fired while inside uc_timers_run TAILQ_HEAD(, UCTimer) ready_list; //pending timers to be fired while inside uc_timers_run
}; };
+7 -7
View File
@@ -31,13 +31,13 @@ static void uc_timer_real_add(struct UCTimers *timers, struct UCTimer *timer)
timer->state = UC_TIMER_ACTIVE; timer->state = UC_TIMER_ACTIVE;
timer->seq = timers->seq++; timer->seq = timers->seq++;
timer->rb_node.data = timer; //point the data in a RBNode back to the timer that contains it. timer->rb_node.data = timer; //point the data in a RBNode back to the timer that contains it.
uc_rb_insert(&timers->timers, &timer->rb_node); uc_rb_insert(&timers->timer_tree, &timer->rb_node);
} }
void uc_timers_init(struct UCTimers *t) void uc_timers_init(struct UCTimers *t)
{ {
t->timers.node = NULL; t->timer_tree.node = NULL;
t->timers.compare = timers_cmp; t->timer_tree.compare = timers_cmp;
t->seq = 0; t->seq = 0;
TAILQ_INIT(&t->ready_list); TAILQ_INIT(&t->ready_list);
} }
@@ -68,7 +68,7 @@ void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer)
return; return;
} }
uc_rb_remove(&timers->timers, &timer->rb_node); //remove it, safe for the uc_rb_remove(&timers->timer_tree, &timer->rb_node); //remove it, safe for the
//callback to re_add it //callback to re_add it
if (timer->state == UC_TIMER_PENDING) { if (timer->state == UC_TIMER_PENDING) {
//timer is pending for callback, remove it from the list //timer is pending for callback, remove it from the list
@@ -80,7 +80,7 @@ void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer)
int uc_timers_first(const struct UCTimers *timers, struct timeval *first) int uc_timers_first(const struct UCTimers *timers, struct timeval *first)
{ {
const RBNode *n = uc_rb_first(&timers->timers); const RBNode *n = uc_rb_first(&timers->timer_tree);
if (n) { if (n) {
struct UCTimer *timer = n->data; struct UCTimer *timer = n->data;
*first = timer->timeout; *first = timer->timeout;
@@ -95,7 +95,7 @@ size_t uc_timer_count(const struct UCTimers *timers)
struct RBNode *n; struct RBNode *n;
size_t count = 0; size_t count = 0;
for (n = uc_rb_first(&timers->timers); n ; n = uc_rb_next(n)) { for (n = uc_rb_first(&timers->timer_tree); n ; n = uc_rb_next(n)) {
count++; count++;
} }
@@ -119,7 +119,7 @@ int uc_timers_run(struct UCTimers *timers, const struct timeval *now)
*/ */
assert(TAILQ_EMPTY(&timers->ready_list)); //somethings serious wrong if it isn't already empty assert(TAILQ_EMPTY(&timers->ready_list)); //somethings serious wrong if it isn't already empty
TAILQ_INIT(&timers->ready_list); TAILQ_INIT(&timers->ready_list);
for (node = uc_rb_first(&timers->timers); node ; node = uc_rb_next(node)) { for (node = uc_rb_first(&timers->timer_tree); node ; node = uc_rb_next(node)) {
struct UCTimer *t = node->data; struct UCTimer *t = node->data;
//Note, timercmp does not work for >= //Note, timercmp does not work for >=
if (!timercmp(now, &t->timeout, <)) { if (!timercmp(now, &t->timeout, <)) {