diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-05-31 15:46:04 +0200 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-12-07 13:46:53 +0100 |
commit | 28a7d3943ef915c405b3552ae06f639a86f4dc1e (patch) | |
tree | 2ef01e56d3f049a2d1ae2144747d99e88040a0da /sysdep | |
parent | 534215a18fb3fb7ce5b26c9e6ec1fdb32bf22ae6 (diff) |
Timers: Integrate microsecond timers to the main loop
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/unix/io.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index ebd380ba..13635586 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -2507,9 +2507,10 @@ static int short_loops = 0; void io_loop(void) { - int poll_tout; + int poll_tout, timeout; time_t tout; int nfds, events, pout; + timer2 *t; sock *s; node *n; int fdmax = 256; @@ -2518,7 +2519,9 @@ io_loop(void) watchdog_start1(); for(;;) { + times_update(&main_timeloop); events = ev_run_list(&global_event_list); + timers_fire(&main_timeloop); timers: update_times(); tout = tm_first_shot(); @@ -2527,10 +2530,16 @@ io_loop(void) tm_shot(); goto timers; } - poll_tout = (events ? 0 : MIN(tout - now, 3)) * 1000; /* Time in milliseconds */ - io_close_event(); + poll_tout = (events ? 0 : MIN(tout - now, 3)) * 1000; /* Time in milliseconds */ + if (t = timers_first(&main_timeloop)) + { + times_update(&main_timeloop); + timeout = (tm2_remains(t) TO_MS) + 1; + poll_tout = MIN(poll_tout, timeout); + } + nfds = 0; WALK_LIST(n, sock_list) { @@ -2601,6 +2610,8 @@ io_loop(void) } if (pout) { + times_update(&main_timeloop); + /* guaranteed to be non-empty */ current_sock = SKIP_BACK(sock, n, HEAD(sock_list)); |