summaryrefslogtreecommitdiff
path: root/lib/timer.h
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.h
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.h')
-rw-r--r--lib/timer.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/timer.h b/lib/timer.h
index bc568ee6..b201b8c8 100644
--- a/lib/timer.h
+++ b/lib/timer.h
@@ -14,6 +14,10 @@
#include "lib/buffer.h"
#include "lib/resource.h"
+#include <stdatomic.h>
+
+extern _Atomic btime last_time;
+extern _Atomic btime real_time;
typedef struct timer
{
@@ -31,8 +35,6 @@ typedef struct timer
struct timeloop
{
BUFFER_(timer *) timers;
- btime last_time;
- btime real_time;
};
static inline uint timers_count(struct timeloop *loop)
@@ -44,8 +46,8 @@ static inline timer *timers_first(struct timeloop *loop)
extern struct timeloop main_timeloop;
extern _Thread_local struct timeloop *local_timeloop;
-btime current_time(void);
-btime current_real_time(void);
+#define current_time() atomic_load_explicit(&last_time, memory_order_acquire)
+#define current_real_time() atomic_load_explicit(&real_time, memory_order_acquire)
//#define now (current_time() TO_S)
//#define now_real (current_real_time() TO_S)
@@ -95,9 +97,7 @@ tm_start_max(timer *t, btime after)
}
/* In sysdep code */
-void times_init(struct timeloop *loop);
-void times_update(struct timeloop *loop);
-void times_update_real_time(struct timeloop *loop);
+void times_update(void);
/* For I/O loop */
void timers_init(struct timeloop *loop, pool *p);