diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-05-30 19:12:35 +0200 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-12-07 13:46:53 +0100 |
commit | 534215a18fb3fb7ce5b26c9e6ec1fdb32bf22ae6 (patch) | |
tree | b805e7f9dcf6e999dfad01117bc72f4bee6f2a6d /sysdep/unix | |
parent | 7c454d918682c072a6ae6ad8e0cd8d35b9edd2aa (diff) |
Timers: Split microsecond timers from BFD code to lib
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/io.c | 42 | ||||
-rw-r--r-- | sysdep/unix/main.c | 2 |
2 files changed, 44 insertions, 0 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 0cf48c9d..ebd380ba 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -37,6 +37,7 @@ #include "sysdep/unix/timer.h" #include "lib/socket.h" #include "lib/event.h" +#include "lib/timer.h" #include "lib/string.h" #include "nest/iface.h" @@ -479,6 +480,47 @@ tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t) } +/* + * Time clock + */ + +void +times_init(struct timeloop *loop) +{ + struct timespec ts; + int rv; + + rv = clock_gettime(CLOCK_MONOTONIC, &ts); + if (rv < 0) + die("Monotonic clock is missing"); + + if ((ts.tv_sec < 0) || (((s64) ts.tv_sec) > ((s64) 1 << 40))) + log(L_WARN "Monotonic clock is crazy"); + + loop->last_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000); + loop->real_time = 0; +} + +void +times_update(struct timeloop *loop) +{ + struct timespec ts; + int rv; + + rv = clock_gettime(CLOCK_MONOTONIC, &ts); + if (rv < 0) + die("clock_gettime: %m"); + + btime new_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000); + + if (new_time < loop->last_time) + log(L_ERR "Monotonic clock is broken"); + + loop->last_time = new_time; + loop->real_time = 0; +} + + /** * DOC: Sockets * diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index c1b92b7e..396310fd 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -27,6 +27,7 @@ #include "lib/resource.h" #include "lib/socket.h" #include "lib/event.h" +#include "lib/timer.h" #include "lib/string.h" #include "nest/route.h" #include "nest/protocol.h" @@ -820,6 +821,7 @@ main(int argc, char **argv) log_switch(debug_flag, NULL, NULL); resource_init(); + timer_init(); olock_init(); io_init(); rt_init(); |