summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/timer.h20
-rw-r--r--src/rate_ctr.c6
-rw-r--r--src/select.c8
-rw-r--r--src/timer.c29
-rw-r--r--tests/timer/timer_test.c16
5 files changed, 40 insertions, 39 deletions
diff --git a/include/osmocom/core/timer.h b/include/osmocom/core/timer.h
index 19664781..db2ecbf7 100644
--- a/include/osmocom/core/timer.h
+++ b/include/osmocom/core/timer.h
@@ -27,7 +27,7 @@
/**
* Timer management:
- * - Create a struct timer_list
+ * - Create a struct osmo_timer_list
* - Fill out timeout and use add_timer or
* use schedule_timer to schedule a timer in
* x seconds and microseconds from now...
@@ -41,7 +41,7 @@
* the timers.
*
*/
-struct timer_list {
+struct osmo_timer_list {
struct llist_head entry;
struct timeval timeout;
unsigned int active : 1;
@@ -55,18 +55,18 @@ struct timer_list {
/**
* timer management
*/
-void bsc_add_timer(struct timer_list *timer);
-void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds);
-void bsc_del_timer(struct timer_list *timer);
-int bsc_timer_pending(struct timer_list *timer);
+void osmo_timer_add(struct osmo_timer_list *timer);
+void osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds);
+void osmo_timer_del(struct osmo_timer_list *timer);
+int osmo_timer_pending(struct osmo_timer_list *timer);
/**
* internal timer list management
*/
-struct timeval *bsc_nearest_timer();
-void bsc_prepare_timers();
-int bsc_update_timers();
-int bsc_timer_check(void);
+struct timeval *osmo_timers_nearest();
+void osmo_timers_prepare();
+int osmo_timers_update();
+int osmo_timers_check(void);
#endif
diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index a0e18148..6d771a44 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -82,7 +82,7 @@ static void interval_expired(struct rate_ctr *ctr, enum rate_ctr_intv intv)
ctr->intv[intv+1].rate += ctr->intv[intv].rate;
}
-static struct timer_list rate_ctr_timer;
+static struct osmo_timer_list rate_ctr_timer;
static uint64_t timer_ticks;
/* The one-second interval has expired */
@@ -114,14 +114,14 @@ static void rate_ctr_timer_cb(void *data)
llist_for_each_entry(ctrg, &rate_ctr_groups, list)
rate_ctr_group_intv(ctrg);
- bsc_schedule_timer(&rate_ctr_timer, 1, 0);
+ osmo_timer_schedule(&rate_ctr_timer, 1, 0);
}
int rate_ctr_init(void *tall_ctx)
{
tall_rate_ctr_ctx = tall_ctx;
rate_ctr_timer.cb = rate_ctr_timer_cb;
- bsc_schedule_timer(&rate_ctr_timer, 1, 0);
+ osmo_timer_schedule(&rate_ctr_timer, 1, 0);
return 0;
}
diff --git a/src/select.c b/src/select.c
index adf36194..6c44f355 100644
--- a/src/select.c
+++ b/src/select.c
@@ -95,16 +95,16 @@ int bsc_select_main(int polling)
FD_SET(ufd->fd, &exceptset);
}
- bsc_timer_check();
+ osmo_timers_check();
if (!polling)
- bsc_prepare_timers();
- rc = select(maxfd+1, &readset, &writeset, &exceptset, polling ? &no_time : bsc_nearest_timer());
+ osmo_timers_prepare();
+ rc = select(maxfd+1, &readset, &writeset, &exceptset, polling ? &no_time : osmo_timers_nearest());
if (rc < 0)
return 0;
/* fire timers */
- bsc_update_timers();
+ osmo_timers_update();
/* call registered callback functions */
restart:
diff --git a/src/timer.c b/src/timer.c
index 9b2dd9e9..ec752123 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -31,9 +31,9 @@ static struct timeval s_select_time;
#define TIME_SMALLER(left, right) \
(left.tv_sec*MICRO_SECONDS+left.tv_usec) <= (right.tv_sec*MICRO_SECONDS+right.tv_usec)
-void bsc_add_timer(struct timer_list *timer)
+void osmo_timer_add(struct osmo_timer_list *timer)
{
- struct timer_list *list_timer;
+ struct osmo_timer_list *list_timer;
/* TODO: Optimize and remember the closest item... */
timer->active = 1;
@@ -47,7 +47,8 @@ void bsc_add_timer(struct timer_list *timer)
llist_add(&timer->entry, &timer_list);
}
-void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds)
+void
+osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds)
{
struct timeval current_time;
@@ -56,10 +57,10 @@ void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds)
currentTime += seconds * MICRO_SECONDS + microseconds;
timer->timeout.tv_sec = currentTime / MICRO_SECONDS;
timer->timeout.tv_usec = currentTime % MICRO_SECONDS;
- bsc_add_timer(timer);
+ osmo_timer_add(timer);
}
-void bsc_del_timer(struct timer_list *timer)
+void osmo_timer_del(struct osmo_timer_list *timer)
{
if (timer->in_list) {
timer->active = 0;
@@ -68,7 +69,7 @@ void bsc_del_timer(struct timer_list *timer)
}
}
-int bsc_timer_pending(struct timer_list *timer)
+int osmo_timer_pending(struct osmo_timer_list *timer)
{
return timer->active;
}
@@ -79,7 +80,7 @@ int bsc_timer_pending(struct timer_list *timer)
* If the nearest timer timed out return NULL and then we will
* dispatch everything after the select
*/
-struct timeval *bsc_nearest_timer()
+struct timeval *osmo_timers_nearest()
{
struct timeval current_time;
@@ -106,9 +107,9 @@ struct timeval *bsc_nearest_timer()
/*
* Find the nearest time and update s_nearest_time
*/
-void bsc_prepare_timers()
+void osmo_timers_prepare()
{
- struct timer_list *timer, *nearest_timer = NULL;
+ struct osmo_timer_list *timer, *nearest_timer = NULL;
llist_for_each_entry(timer, &timer_list, entry) {
if (!nearest_timer || TIME_SMALLER(timer->timeout, nearest_timer->timeout)) {
nearest_timer = timer;
@@ -125,10 +126,10 @@ void bsc_prepare_timers()
/*
* fire all timers... and remove them
*/
-int bsc_update_timers()
+int osmo_timers_update()
{
struct timeval current_time;
- struct timer_list *timer, *tmp;
+ struct osmo_timer_list *timer, *tmp;
int work = 0;
gettimeofday(&current_time, NULL);
@@ -166,16 +167,16 @@ restart:
llist_for_each_entry_safe(timer, tmp, &timer_list, entry) {
timer->handled = 0;
if (!timer->active) {
- bsc_del_timer(timer);
+ osmo_timer_del(timer);
}
}
return work;
}
-int bsc_timer_check(void)
+int osmo_timers_check(void)
{
- struct timer_list *timer;
+ struct osmo_timer_list *timer;
int i = 0;
llist_for_each_entry(timer, &timer_list, entry) {
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 30b08ad0..69bcad92 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -27,17 +27,17 @@
static void timer_fired(void *data);
-static struct timer_list timer_one = {
+static struct osmo_timer_list timer_one = {
.cb = timer_fired,
.data = (void*)1,
};
-static struct timer_list timer_two = {
+static struct osmo_timer_list timer_two = {
.cb = timer_fired,
.data = (void*)2,
};
-static struct timer_list timer_three = {
+static struct osmo_timer_list timer_three = {
.cb = timer_fired,
.data = (void*)3,
};
@@ -48,8 +48,8 @@ static void timer_fired(void *_data)
printf("Fired timer: %lu\n", data);
if (data == 1) {
- bsc_schedule_timer(&timer_one, 3, 0);
- bsc_del_timer(&timer_two);
+ osmo_timer_schedule(&timer_one, 3, 0);
+ osmo_timer_del(&timer_two);
} else if (data == 2) {
printf("Should not be fired... bug in del_timer\n");
} else if (data == 3) {
@@ -63,9 +63,9 @@ int main(int argc, char** argv)
{
printf("Starting... timer\n");
- bsc_schedule_timer(&timer_one, 3, 0);
- bsc_schedule_timer(&timer_two, 5, 0);
- bsc_schedule_timer(&timer_three, 4, 0);
+ osmo_timer_schedule(&timer_one, 3, 0);
+ osmo_timer_schedule(&timer_two, 5, 0);
+ osmo_timer_schedule(&timer_three, 4, 0);
#ifdef HAVE_SYS_SELECT_H
while (1) {