diff options
Diffstat (limited to 'ctl-lib/ctl-timer.c')
-rw-r--r-- | ctl-lib/ctl-timer.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ctl-lib/ctl-timer.c b/ctl-lib/ctl-timer.c index 2139c75..c36d2b1 100644 --- a/ctl-lib/ctl-timer.c +++ b/ctl-lib/ctl-timer.c @@ -19,6 +19,7 @@ #include <stdio.h> #include <string.h> #include <time.h> +#include <systemd/sd-event.h> #include "ctl-config.h" #include "ctl-timer.h" @@ -88,3 +89,16 @@ int TimerEvtInit (AFB_ApiT apiHandle) { return 0; } +uint64_t LockWait(AFB_ApiT apiHandle, uint64_t utimeout) { + uint64_t current_usec, pre_usec; + + struct sd_event *event = AFB_GetEventLoop(apiHandle); + + sd_event_now(event, CLOCK_MONOTONIC, &pre_usec); + sd_event_run(event, utimeout); + sd_event_now(event, CLOCK_MONOTONIC, ¤t_usec); + + uint64_t diff = current_usec - pre_usec; + utimeout = utimeout < diff ? 0 : utimeout - diff; + return utimeout; +} |