diff --git a/include/ucore/timers.h b/include/ucore/timers.h index 7182962..19c9744 100644 --- a/include/ucore/timers.h +++ b/include/ucore/timers.h @@ -92,17 +92,17 @@ void uc_timers_init_ex(struct UCTimers *t, struct UCoreClock *uclock); * @param sec seconds from now until the timer filres * @param usec microseconds (after the @sec) until the timer fires. */ -void uc_timer_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int usec); +void uc_timers_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int usec); /** Remove a timer. * Note, the timer memory must have been zeroed out or the timer must have been added at least once - * before uc_timer_remove can be called on a UCTimer. - * uc_timer_remove does nothing if the timer has expired. + * before uc_timers_remove can be called on a UCTimer. + * uc_timers_remove does nothing if the timer has expired. * * @param timers timer engine to remove from * @param timer timer to remove */ -void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer); +void uc_timers_remove(struct UCTimers *timers, struct UCTimer *timer); /** Get time of the first timer that will run. * @@ -118,7 +118,7 @@ int uc_timers_first(const struct UCTimers *timers, struct timeval *first); * @param timers timer engine to query * @return the number of timers the engine keeps */ -size_t uc_timer_count(const struct UCTimers *timers); +size_t uc_timers_count(const struct UCTimers *timers); /** Check if a timer is running (i.e. hasn't expired and fired) * diff --git a/src/timers.c b/src/timers.c index 3dd3bb7..0aca525 100644 --- a/src/timers.c +++ b/src/timers.c @@ -26,9 +26,9 @@ static int timers_cmp(const void *a_, const void *b_) return 0; //silence compiler } -static void uc_timer_real_add(struct UCTimers *timers, struct UCTimer *timer) +static void uc_timers_real_add(struct UCTimers *timers, struct UCTimer *timer) { - uc_timer_remove(timers, timer); //re schedule it if it's already running + uc_timers_remove(timers, timer); //re schedule it if it's already running timer->state = UC_TIMER_ACTIVE; timer->seq = timers->seq++; timer->rb_node.data = timer; //point the data in a RBNode back to the timer that contains it. @@ -49,7 +49,7 @@ void uc_timers_init_ex(struct UCTimers *t, struct UCoreClock *uclock) TAILQ_INIT(&t->ready_list); } -void uc_timer_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int usec) +void uc_timers_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int usec) { struct timeval now; struct timeval tmp; @@ -63,10 +63,10 @@ void uc_timer_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int u timers->uclock->now(timers->uclock, &now); timeradd(&now, &tmp, &timer->timeout); - uc_timer_real_add(timers, timer); + uc_timers_real_add(timers, timer); } -void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer) +void uc_timers_remove(struct UCTimers *timers, struct UCTimer *timer) { if (timer->state == UC_TIMER_INACTIVE) { //already removed , or never added. //debugging bandaid @@ -97,7 +97,7 @@ int uc_timers_first(const struct UCTimers *timers, struct timeval *first) return 1; } -size_t uc_timer_count(const struct UCTimers *timers) +size_t uc_timers_count(const struct UCTimers *timers) { struct RBNode *n; size_t count = 0; @@ -134,7 +134,7 @@ int uc_timers_run(struct UCTimers *timers) //Note, timercmp does not work for >= if (!timercmp(&now, &t->timeout, <)) { TAILQ_INSERT_TAIL(&timers->ready_list, t, ready_entry); - t->state = UC_TIMER_PENDING; //so uc_timer_remove knows + t->state = UC_TIMER_PENDING; //so uc_timers_remove knows //it have to remove it from the ready_list } else { break; @@ -147,12 +147,12 @@ int uc_timers_run(struct UCTimers *timers) * Need to always pick the first item in the tail queue * since a timer callback could remove/free a timer * we had in the list. - * uc_timer_remove will unlink the timer from this list. + * uc_timers_remove will unlink the timer from this list. */ while (!TAILQ_EMPTY(&timers->ready_list)) { struct UCTimer *t = TAILQ_FIRST(&timers->ready_list); - uc_timer_remove(timers, t); + uc_timers_remove(timers, t); assert(t->callback != NULL); t->callback(timers, t); //fire // callback might have free'd its timer. diff --git a/test/iomux_test3.c b/test/iomux_test3.c index c81b2e2..3008480 100644 --- a/test/iomux_test3.c +++ b/test/iomux_test3.c @@ -100,11 +100,11 @@ void timer_cb(struct UCTimers *timers, struct UCTimer *timer) struct UCTimer *t = calloc(1, sizeof *t); t->callback = timer_cb; t->cookie_int = timer->cookie_int + 1; - uc_timer_add(timers, t, 5,5); + uc_timers_add(timers, t, 5,5); t = calloc(1, sizeof *t); t->callback = timer_cb; t->cookie_int = timer->cookie_int + 2; - uc_timer_add(timers, t, 5,4); + uc_timers_add(timers, t, 5,4); } @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) struct IOMux *mux = iomux_create(IOMUX_TYPE_EPOLL); iomux_register_fd(mux, ©_ctx.in); - uc_timer_add(iomux_get_timers(mux), &timer, 5, 0); + uc_timers_add(iomux_get_timers(mux), &timer, 5, 0); iomux_run(mux); diff --git a/test/test_timers.c b/test/test_timers.c index 5ac4b2c..a563cd4 100644 --- a/test/test_timers.c +++ b/test/test_timers.c @@ -18,13 +18,13 @@ static void timer_test_cb_add(struct UCTimers *timers, struct UCTimer *timer) { struct TimerTest *tt = timer->cookie_ptr; tt->cnt++; - uc_timer_add(timers, timer, 10, 0); + uc_timers_add(timers, timer, 10, 0); } static void timer_test_cb_remove(struct UCTimers *timers, struct UCTimer *timer) { struct UCTimer *timer2 = timer->cookie_ptr; - uc_timer_remove(timers, timer2); + uc_timers_remove(timers, timer2); } static void common_init(struct UCoreSettableClock *clk, @@ -54,7 +54,7 @@ START_TEST (test_timers_simple) timer.callback = timer_test_cb; - uc_timer_add(&timers, &timer, 10, 0); + uc_timers_add(&timers, &timer, 10, 0); //5 seconds into the future, no timer should fire t += 5; @@ -62,7 +62,7 @@ START_TEST (test_timers_simple) rc = uc_timers_run(&timers); fail_if(rc != 0); fail_if(tt.cnt != 0); - fail_if(uc_timer_count(&timers) != 1); + fail_if(uc_timers_count(&timers) != 1); //10 seconds into the future, our timer should fire t += 5; @@ -77,7 +77,7 @@ START_TEST (test_timers_simple) rc = uc_timers_run(&timers); fail_if(rc != 0); fail_if(tt.cnt != 1); - fail_if(uc_timer_count(&timers) != 0); + fail_if(uc_timers_count(&timers) != 0); fail_if(uc_timer_running(&timer) != 0); END_TEST @@ -94,7 +94,7 @@ START_TEST (test_timers_add_from_callback) timer.callback = timer_test_cb_add; - uc_timer_add(&timers, &timer, 10, 0); + uc_timers_add(&timers, &timer, 10, 0); //10 seconds into the future, our timer should fire t += 10; @@ -112,7 +112,7 @@ START_TEST (test_timers_add_from_callback) fail_if(tt.cnt != 2); fail_if(uc_timer_running(&timer) == 0); - fail_if(uc_timer_count(&timers) != 1); + fail_if(uc_timers_count(&timers) != 1); END_TEST @@ -133,10 +133,10 @@ START_TEST (test_timers_remove_from_callback) memset(&timer2, 0, sizeof timer2); timer2.callback = timer_test_cb; - uc_timer_add(&timers, &timer, 5, 0); - uc_timer_add(&timers, &timer2, 10, 0); + uc_timers_add(&timers, &timer, 5, 0); + uc_timers_add(&timers, &timer2, 10, 0); - fail_if(uc_timer_count(&timers) != 2); + fail_if(uc_timers_count(&timers) != 2); rc = uc_timers_first(&timers, &tv); fail_if(rc != 0); fail_if(tv.tv_sec != TEST_TIMER_START + 5); @@ -152,7 +152,7 @@ START_TEST (test_timers_remove_from_callback) //and our timer2 should be removed, and timer has fired so it //should be removed too - fail_if(uc_timer_count(&timers) != 0); + fail_if(uc_timers_count(&timers) != 0); fail_if(uc_timer_running(&timer) != 0); fail_if(uc_timer_running(&timer2) != 0); rc = uc_timers_first(&timers, &tv); diff --git a/test/timers.c b/test/timers.c index fe37df4..a708b77 100644 --- a/test/timers.c +++ b/test/timers.c @@ -25,7 +25,7 @@ void mystruct1_cb(struct UCTimers *timers, struct UCTimer *timer) struct MyStruct *mystruct = CONTAINER_OF(timer, struct MyStruct, timer); TRACEF("MyStruct1 timer: %s\n", mystruct->str); - uc_timer_add(timers, timer, 1, 0); + uc_timers_add(timers, timer, 1, 0); } void mystruct2_cb(struct UCTimers *timers, struct UCTimer *timer) @@ -33,7 +33,7 @@ void mystruct2_cb(struct UCTimers *timers, struct UCTimer *timer) struct MyStruct *mystruct = timer->cookie_ptr; TRACEF("MyStruct2 timer: %s\n", mystruct->str); - uc_timer_add(timers, timer, 5, 0); + uc_timers_add(timers, timer, 5, 0); } int main(int argc, char *argv[]) @@ -63,10 +63,10 @@ int main(int argc, char *argv[]) }; uc_timers_init(&timers); - uc_timer_add(&timers, &t1, 2, 0); - uc_timer_add(&timers, &t2, 5, 0); - uc_timer_add(&timers, &my_struct1.timer, 10, 0); - uc_timer_add(&timers, &my_struct2.timer, 10, 0); + uc_timers_add(&timers, &t1, 2, 0); + uc_timers_add(&timers, &t2, 5, 0); + uc_timers_add(&timers, &my_struct1.timer, 10, 0); + uc_timers_add(&timers, &my_struct2.timer, 10, 0); for(;;) { uc_timers_run(&timers); diff --git a/test/udp_heartbeat.c b/test/udp_heartbeat.c index 32604f0..18fa205 100644 --- a/test/udp_heartbeat.c +++ b/test/udp_heartbeat.c @@ -74,7 +74,7 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer) struct HBContext *ctx = timer->cookie_ptr; time_t now; - uc_timer_add(timers, timer, PEER_HB_MISS , 0); + uc_timers_add(timers, timer, PEER_HB_MISS , 0); now = time(NULL); if (now - peer->last_ok > PEER_HB_MISS * PEER_HB_SEC) { @@ -106,7 +106,7 @@ void peer_add_addr(struct HBContext *ctx, const struct sockaddr_in *addr) sec = rand() % PEER_HB_SEC; usec = rand() % 1000000; - uc_timer_add(iomux_get_timers(ctx->mux), &peer->timer, sec, usec); + uc_timers_add(iomux_get_timers(ctx->mux), &peer->timer, sec, usec); } void peer_add(struct HBContext *ctx, const char *host, uint16_t port)