Name uc_timers_XXX consistently
This commit is contained in:
@@ -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 sec seconds from now until the timer filres
|
||||||
* @param usec microseconds (after the @sec) until the timer fires.
|
* @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.
|
/** Remove a timer.
|
||||||
* Note, the timer memory must have been zeroed out or the timer must have been added at least once
|
* 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.
|
* before uc_timers_remove can be called on a UCTimer.
|
||||||
* uc_timer_remove does nothing if the timer has expired.
|
* uc_timers_remove does nothing if the timer has expired.
|
||||||
*
|
*
|
||||||
* @param timers timer engine to remove from
|
* @param timers timer engine to remove from
|
||||||
* @param timer timer to remove
|
* @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.
|
/** 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
|
* @param timers timer engine to query
|
||||||
* @return the number of timers the engine keeps
|
* @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)
|
/** Check if a timer is running (i.e. hasn't expired and fired)
|
||||||
*
|
*
|
||||||
|
|||||||
+9
-9
@@ -26,9 +26,9 @@ static int timers_cmp(const void *a_, const void *b_)
|
|||||||
return 0; //silence compiler
|
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->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.
|
||||||
@@ -49,7 +49,7 @@ void uc_timers_init_ex(struct UCTimers *t, struct UCoreClock *uclock)
|
|||||||
TAILQ_INIT(&t->ready_list);
|
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 now;
|
||||||
struct timeval tmp;
|
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);
|
timers->uclock->now(timers->uclock, &now);
|
||||||
timeradd(&now, &tmp, &timer->timeout);
|
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.
|
if (timer->state == UC_TIMER_INACTIVE) { //already removed , or never added.
|
||||||
//debugging bandaid
|
//debugging bandaid
|
||||||
@@ -97,7 +97,7 @@ int uc_timers_first(const struct UCTimers *timers, struct timeval *first)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t uc_timer_count(const struct UCTimers *timers)
|
size_t uc_timers_count(const struct UCTimers *timers)
|
||||||
{
|
{
|
||||||
struct RBNode *n;
|
struct RBNode *n;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
@@ -134,7 +134,7 @@ int uc_timers_run(struct UCTimers *timers)
|
|||||||
//Note, timercmp does not work for >=
|
//Note, timercmp does not work for >=
|
||||||
if (!timercmp(&now, &t->timeout, <)) {
|
if (!timercmp(&now, &t->timeout, <)) {
|
||||||
TAILQ_INSERT_TAIL(&timers->ready_list, t, ready_entry);
|
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
|
//it have to remove it from the ready_list
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@@ -147,12 +147,12 @@ int uc_timers_run(struct UCTimers *timers)
|
|||||||
* Need to always pick the first item in the tail queue
|
* Need to always pick the first item in the tail queue
|
||||||
* since a timer callback could remove/free a timer
|
* since a timer callback could remove/free a timer
|
||||||
* we had in the list.
|
* 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)) {
|
while (!TAILQ_EMPTY(&timers->ready_list)) {
|
||||||
struct UCTimer *t = TAILQ_FIRST(&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);
|
assert(t->callback != NULL);
|
||||||
t->callback(timers, t); //fire
|
t->callback(timers, t); //fire
|
||||||
// callback might have free'd its timer.
|
// callback might have free'd its timer.
|
||||||
|
|||||||
+3
-3
@@ -100,11 +100,11 @@ void timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
struct UCTimer *t = calloc(1, sizeof *t);
|
struct UCTimer *t = calloc(1, sizeof *t);
|
||||||
t->callback = timer_cb;
|
t->callback = timer_cb;
|
||||||
t->cookie_int = timer->cookie_int + 1;
|
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 = calloc(1, sizeof *t);
|
||||||
t->callback = timer_cb;
|
t->callback = timer_cb;
|
||||||
t->cookie_int = timer->cookie_int + 2;
|
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);
|
struct IOMux *mux = iomux_create(IOMUX_TYPE_EPOLL);
|
||||||
iomux_register_fd(mux, ©_ctx.in);
|
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);
|
iomux_run(mux);
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -18,13 +18,13 @@ static void timer_test_cb_add(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
{
|
{
|
||||||
struct TimerTest *tt = timer->cookie_ptr;
|
struct TimerTest *tt = timer->cookie_ptr;
|
||||||
tt->cnt++;
|
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)
|
static void timer_test_cb_remove(struct UCTimers *timers, struct UCTimer *timer)
|
||||||
{
|
{
|
||||||
struct UCTimer *timer2 = timer->cookie_ptr;
|
struct UCTimer *timer2 = timer->cookie_ptr;
|
||||||
uc_timer_remove(timers, timer2);
|
uc_timers_remove(timers, timer2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void common_init(struct UCoreSettableClock *clk,
|
static void common_init(struct UCoreSettableClock *clk,
|
||||||
@@ -54,7 +54,7 @@ START_TEST (test_timers_simple)
|
|||||||
|
|
||||||
timer.callback = timer_test_cb;
|
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
|
//5 seconds into the future, no timer should fire
|
||||||
t += 5;
|
t += 5;
|
||||||
@@ -62,7 +62,7 @@ START_TEST (test_timers_simple)
|
|||||||
rc = uc_timers_run(&timers);
|
rc = uc_timers_run(&timers);
|
||||||
fail_if(rc != 0);
|
fail_if(rc != 0);
|
||||||
fail_if(tt.cnt != 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
|
//10 seconds into the future, our timer should fire
|
||||||
t += 5;
|
t += 5;
|
||||||
@@ -77,7 +77,7 @@ START_TEST (test_timers_simple)
|
|||||||
rc = uc_timers_run(&timers);
|
rc = uc_timers_run(&timers);
|
||||||
fail_if(rc != 0);
|
fail_if(rc != 0);
|
||||||
fail_if(tt.cnt != 1);
|
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);
|
fail_if(uc_timer_running(&timer) != 0);
|
||||||
|
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -94,7 +94,7 @@ START_TEST (test_timers_add_from_callback)
|
|||||||
|
|
||||||
timer.callback = timer_test_cb_add;
|
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
|
//10 seconds into the future, our timer should fire
|
||||||
t += 10;
|
t += 10;
|
||||||
@@ -112,7 +112,7 @@ START_TEST (test_timers_add_from_callback)
|
|||||||
fail_if(tt.cnt != 2);
|
fail_if(tt.cnt != 2);
|
||||||
|
|
||||||
fail_if(uc_timer_running(&timer) == 0);
|
fail_if(uc_timer_running(&timer) == 0);
|
||||||
fail_if(uc_timer_count(&timers) != 1);
|
fail_if(uc_timers_count(&timers) != 1);
|
||||||
|
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -133,10 +133,10 @@ START_TEST (test_timers_remove_from_callback)
|
|||||||
memset(&timer2, 0, sizeof timer2);
|
memset(&timer2, 0, sizeof timer2);
|
||||||
timer2.callback = timer_test_cb;
|
timer2.callback = timer_test_cb;
|
||||||
|
|
||||||
uc_timer_add(&timers, &timer, 5, 0);
|
uc_timers_add(&timers, &timer, 5, 0);
|
||||||
uc_timer_add(&timers, &timer2, 10, 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);
|
rc = uc_timers_first(&timers, &tv);
|
||||||
fail_if(rc != 0);
|
fail_if(rc != 0);
|
||||||
fail_if(tv.tv_sec != TEST_TIMER_START + 5);
|
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
|
//and our timer2 should be removed, and timer has fired so it
|
||||||
//should be removed too
|
//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(&timer) != 0);
|
||||||
fail_if(uc_timer_running(&timer2) != 0);
|
fail_if(uc_timer_running(&timer2) != 0);
|
||||||
rc = uc_timers_first(&timers, &tv);
|
rc = uc_timers_first(&timers, &tv);
|
||||||
|
|||||||
+6
-6
@@ -25,7 +25,7 @@ void mystruct1_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
struct MyStruct *mystruct = CONTAINER_OF(timer, struct MyStruct, timer);
|
struct MyStruct *mystruct = CONTAINER_OF(timer, struct MyStruct, timer);
|
||||||
|
|
||||||
TRACEF("MyStruct1 timer: %s\n", mystruct->str);
|
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)
|
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;
|
struct MyStruct *mystruct = timer->cookie_ptr;
|
||||||
|
|
||||||
TRACEF("MyStruct2 timer: %s\n", mystruct->str);
|
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[])
|
int main(int argc, char *argv[])
|
||||||
@@ -63,10 +63,10 @@ int main(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
uc_timers_init(&timers);
|
uc_timers_init(&timers);
|
||||||
uc_timer_add(&timers, &t1, 2, 0);
|
uc_timers_add(&timers, &t1, 2, 0);
|
||||||
uc_timer_add(&timers, &t2, 5, 0);
|
uc_timers_add(&timers, &t2, 5, 0);
|
||||||
uc_timer_add(&timers, &my_struct1.timer, 10, 0);
|
uc_timers_add(&timers, &my_struct1.timer, 10, 0);
|
||||||
uc_timer_add(&timers, &my_struct2.timer, 10, 0);
|
uc_timers_add(&timers, &my_struct2.timer, 10, 0);
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
uc_timers_run(&timers);
|
uc_timers_run(&timers);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
struct HBContext *ctx = timer->cookie_ptr;
|
struct HBContext *ctx = timer->cookie_ptr;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
uc_timer_add(timers, timer, PEER_HB_MISS , 0);
|
uc_timers_add(timers, timer, PEER_HB_MISS , 0);
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
|
|
||||||
if (now - peer->last_ok > PEER_HB_MISS * PEER_HB_SEC) {
|
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;
|
sec = rand() % PEER_HB_SEC;
|
||||||
usec = rand() % 1000000;
|
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)
|
void peer_add(struct HBContext *ctx, const char *host, uint16_t port)
|
||||||
|
|||||||
Reference in New Issue
Block a user