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-07-10 07:51:56 +0000
commitbac7d6da81ef3876dc8cf6f50b1d602000a96749 (patch)
tree1feae5ee3fe194c25ca6057c9673a72f8fd35c48 /ctl-lib/ctl-timer.c
parent4a72073d15248dbb3c9d88377405ad44e75f6d1b (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;
+}