aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-05-31 16:46:03 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-05-31 16:49:15 +0200
commit516a159846b9af5180698a8eebcc2a5c32a82fe5 (patch)
treeea96cac6e10479f632b29f07acbd53f2deebf17d
parent5ef63db2994cfe39c72326d13f7b247c1476fed3 (diff)
osmo_timer: cosmetic: add get_time() as abstraction for osmo_gettimeofday()
To move osmo_timer to a monotonic clock, first create a static get_time() in timer.c that wraps osmo_gettimeofday(). In a subsequent step, we can return a monotonic clock from that function instead. Change-Id: Iea9bf4c8f71e50190714215d4d7c702ca1763458
-rw-r--r--src/timer.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/timer.c b/src/timer.c
index 9b82ec91..fa0de441 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -39,6 +39,11 @@
#include <osmocom/core/timer_compat.h>
#include <osmocom/core/linuxlist.h>
+static int get_time(struct timeval *now)
+{
+ return osmo_gettimeofday(&now, NULL);
+}
+
/* These store the amount of time that we wait until next timer expires. */
static struct timeval nearest;
static struct timeval *nearest_p;
@@ -104,7 +109,7 @@ osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds
{
struct timeval current_time;
- osmo_gettimeofday(&current_time, NULL);
+ get_time(&current_time);
timer->timeout.tv_sec = seconds;
timer->timeout.tv_usec = microseconds;
timeradd(&timer->timeout, &current_time, &timer->timeout);
@@ -162,7 +167,7 @@ int osmo_timer_remaining(const struct osmo_timer_list *timer,
struct timeval current_time;
if (!now)
- osmo_gettimeofday(&current_time, NULL);
+ get_time(&current_time);
else
current_time = *now;
@@ -211,7 +216,7 @@ void osmo_timers_prepare(void)
struct rb_node *node;
struct timeval current;
- osmo_gettimeofday(&current, NULL);
+ get_time(&current);
node = rb_first(&timer_root);
if (node) {
@@ -232,7 +237,7 @@ int osmo_timers_update(void)
struct osmo_timer_list *this;
int work = 0;
- osmo_gettimeofday(&current_time, NULL);
+ get_time(&current_time);
INIT_LLIST_HEAD(&timer_eviction_list);
for (node = rb_first(&timer_root); node; node = rb_next(node)) {