summaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-timer.c
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-07-03 18:34:11 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:55 +0100
commit6b99ed2192c8c24f00d2d14c20e2136e4b89741e (patch)
tree1feae5ee3fe194c25ca6057c9673a72f8fd35c48 /ctl-lib/ctl-timer.c
parent95d249caff27a1ad870a68075e7e9c9d155d9ab5 (diff)
asynchronism for test: LockWait added
added LockWait to wait for incoming events, as soon as an event is received, the wait is unlocked You can indicate the timeout Change-Id: If29ca754618edb5b9fdc32c1c40b47016c6fc88a Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-timer.c')
-rw-r--r--ctl-lib/ctl-timer.c14
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, &current_usec);
+
+ uint64_t diff = current_usec - pre_usec;
+ utimeout = utimeout < diff ? 0 : utimeout - diff;
+ return utimeout;
+}