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

(cherry picked from commit 998772805c)
This commit is contained in:
Thomas Haller 2015-11-26 23:26:00 +01:00
parent a950a54516
commit 55403cd032

View file

@ -129,16 +129,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