]> git.meshlink.io Git - meshlink/blobdiff - test/utils.h
Add reset_sync_flag().
[meshlink] / test / utils.h
index bce2f9a5cc1e1a37fbca7b8d85292ad73e6f6c76..2a56ed83a0b24dedaf59340cb66719ef28cbfe91 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef MESHLINK_TEST_UTILS_H
 #define MESHLINK_TEST_UTILS_H
 
+#include <assert.h>
+#include <time.h>
+
 #include "../src/meshlink.h"
 
 // Simple synchronisation between threads
@@ -10,7 +13,9 @@ struct sync_flag {
        bool flag;
 };
 
+extern void init_sync_flag(struct sync_flag *s);
 extern void set_sync_flag(struct sync_flag *s, bool value);
+extern void reset_sync_flag(struct sync_flag *s);
 extern bool check_sync_flag(struct sync_flag *s);
 extern bool wait_sync_flag(struct sync_flag *s, int seconds);
 
@@ -44,3 +49,12 @@ extern void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const ch
        } while(0)
 
 #endif
+
+/// Compare two timespec values.
+static inline bool timespec_lt(const struct timespec *a, const struct timespec *b) {
+       if(a->tv_sec == b->tv_sec) {
+               return a->tv_nsec < b->tv_nsec;
+       } else {
+               return a->tv_sec < b->tv_sec;
+       }
+}