nmtst: refactor NMTST_BUSY_WAIT() and rename to NMTST_WAIT*()

This commit is contained in:
Thomas Haller
2015-11-26 23:26:00 +01:00
parent c97f7b54fe
commit 998772805c

View File

@@ -128,16 +128,26 @@ nmtst_assert_error (GError *error,
} }
} }
#define NMTST_BUSY_WAIT(max_wait_ms, condition, wait) \ #define NMTST_WAIT(max_wait_ms, wait) \
G_STMT_START { \ ({ \
gboolean _not_expired = TRUE; \
gint64 _nmtst_end, _nmtst_max_wait_us = (max_wait_ms) * 1000L; \ gint64 _nmtst_end, _nmtst_max_wait_us = (max_wait_ms) * 1000L; \
\ \
_nmtst_end = g_get_monotonic_time () + _nmtst_max_wait_us; \ _nmtst_end = g_get_monotonic_time () + _nmtst_max_wait_us; \
while (!(condition)) { \ while (TRUE) { \
{ wait }; \ { wait }; \
if (g_get_monotonic_time () > _nmtst_end) \ if (g_get_monotonic_time () > _nmtst_end) { \
g_assert_not_reached (); \ _not_expired = FALSE; \
break; \
} \
} \ } \
_not_expired; \
})
#define NMTST_WAIT_ASSERT(max_wait_ms, wait) \
G_STMT_START { \
if (!(NMTST_WAIT (max_wait_ms, wait))) \
g_assert_not_reached (); \
} G_STMT_END } G_STMT_END
inline static void inline static void