summaryrefslogtreecommitdiff
path: root/lib/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/timer.c')
-rw-r--r--lib/timer.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/lib/timer.c b/lib/timer.c
index 6efcadb4..ff1fb5ef 100644
--- a/lib/timer.c
+++ b/lib/timer.c
@@ -32,6 +32,7 @@
#include "nest/bird.h"
+#include "lib/coro.h"
#include "lib/heap.h"
#include "lib/resource.h"
#include "lib/timer.h"
@@ -45,22 +46,10 @@ struct timeloop main_timeloop;
/* Data accessed and modified from proto/bfd/io.c */
_Thread_local struct timeloop *local_timeloop;
-void wakeup_kick_current(void);
-
-btime
-current_time(void)
-{
- return local_timeloop->last_time;
-}
+_Atomic btime last_time;
+_Atomic btime real_time;
-btime
-current_real_time(void)
-{
- if (!local_timeloop->real_time)
- times_update_real_time(local_timeloop);
-
- return local_timeloop->real_time;
-}
+void wakeup_kick_current(void);
#define TIMER_LESS(a,b) ((a)->expires < (b)->expires)
@@ -164,8 +153,6 @@ tm_stop(timer *t)
void
timers_init(struct timeloop *loop, pool *p)
{
- times_init(loop);
-
BUFFER_INIT(loop->timers, p, 4);
BUFFER_PUSH(loop->timers) = NULL;
}
@@ -178,8 +165,8 @@ timers_fire(struct timeloop *loop)
btime base_time;
timer *t;
- times_update(loop);
- base_time = loop->last_time;
+ times_update();
+ base_time = current_time();
while (t = timers_first(loop))
{
@@ -190,8 +177,8 @@ timers_fire(struct timeloop *loop)
{
btime when = t->expires + t->recurrent;
- if (when <= loop->last_time)
- when = loop->last_time + t->recurrent;
+ if (when <= base_time)
+ when = base_time + t->recurrent;
if (t->randomize)
when += random() % (t->randomize + 1);