mirror of
https://gitlab.labs.nic.cz/labs/bird.git
synced 2024-05-11 16:54:54 +00:00
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.
This commit is contained in:
29
lib/timer.c
29
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,23 +46,11 @@ struct timeloop main_timeloop;
|
||||
/* Data accessed and modified from proto/bfd/io.c */
|
||||
_Thread_local struct timeloop *local_timeloop;
|
||||
|
||||
_Atomic btime last_time;
|
||||
_Atomic btime real_time;
|
||||
|
||||
void wakeup_kick_current(void);
|
||||
|
||||
btime
|
||||
current_time(void)
|
||||
{
|
||||
return local_timeloop->last_time;
|
||||
}
|
||||
|
||||
btime
|
||||
current_real_time(void)
|
||||
{
|
||||
if (!local_timeloop->real_time)
|
||||
times_update_real_time(local_timeloop);
|
||||
|
||||
return local_timeloop->real_time;
|
||||
}
|
||||
|
||||
|
||||
#define TIMER_LESS(a,b) ((a)->expires < (b)->expires)
|
||||
#define TIMER_SWAP(heap,a,b,t) (t = heap[a], heap[a] = heap[b], heap[b] = t, \
|
||||
@@ -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);
|
||||
|
Reference in New Issue
Block a user