X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Futils.h;h=883b9154cedde7cc81865796afc7e674eaba8aa0;hb=6b125b5b68e2657eae9b36f23d7f569fb9e49f8d;hp=bce2f9a5cc1e1a37fbca7b8d85292ad73e6f6c76;hpb=9a2520c36431a8a5fd90451e97f488c22f4decc5;p=meshlink diff --git a/test/utils.h b/test/utils.h index bce2f9a5..883b9154 100644 --- a/test/utils.h +++ b/test/utils.h @@ -1,6 +1,9 @@ #ifndef MESHLINK_TEST_UTILS_H #define MESHLINK_TEST_UTILS_H +#include +#include + #include "../src/meshlink.h" // Simple synchronisation between threads @@ -10,6 +13,7 @@ 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 bool check_sync_flag(struct sync_flag *s); extern bool wait_sync_flag(struct sync_flag *s, int seconds); @@ -44,3 +48,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; + } +}