diff options
author | Felix Fietkau <nbd@nbd.name> | 2017-06-01 12:24:37 +0300 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2017-06-01 12:24:44 +0300 |
commit | 368fd2645878edadc72c60948d1f19c6769751d6 (patch) | |
tree | adae81a2dfe43e5d47f81715d150d0a0329c9f40 /uloop.c | |
parent | fa9937cc4f8e60ddfc2dd9b5820eac49bef3de6e (diff) |
uloop: allow specifying a timeout for uloop_run()
This can be useful for cleanup with pending timers, or for hooking into
existing code that does not use uloop
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'uloop.c')
-rw-r--r-- | uloop.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -520,8 +520,9 @@ bool uloop_cancelling(void) return uloop_run_depth > 0 && uloop_cancelled; } -int uloop_run(void) +int uloop_run_timeout(int timeout) { + int next_time = 0; struct timeval tv; /* @@ -545,7 +546,11 @@ int uloop_run(void) break; uloop_gettime(&tv); - uloop_run_events(uloop_get_next_timeout(&tv)); + + next_time = uloop_get_next_timeout(&tv); + if (timeout > 0 && next_time < timeout) + timeout = next_time; + uloop_run_events(timeout); } if (!--uloop_run_depth) |