summaryrefslogtreecommitdiff
path: root/lib/timer.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2021-08-04 22:48:51 +0200
committerMaria Matejka <mq@ucw.cz>2021-11-22 19:05:43 +0100
commita4451535c69b8f934523905a8131ae2f16be2146 (patch)
treea600241cfdb94b6ecafb1b965c554789b453ca75 /lib/timer.c
parenta2af807357875f866f149b0f6db4d463d4533204 (diff)
Unified time for whole BIRD
In previous versions, every thread used its own time structures, effectively leading to different time in every thread and strange logging messages. The time processing code now uses global atomic variables to keep current time available for fast concurrent reading and safe updates.
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);