shared: add NM_MORE_ASSERT_ONCE() macro

This commit is contained in:
Thomas Haller 2020-02-19 15:28:33 +01:00
parent d9d51dd42d
commit 14461e7217

View file

@ -1023,6 +1023,24 @@ nm_str_realloc (char *str)
#define nm_assert_not_reached() G_STMT_START { ; } G_STMT_END
#endif
/* Usage:
*
* if (NM_MORE_ASSERT_ONCE (5)) { extra_check (); }
*
* This will only run the check once, and only if NM_MORE_ASSERT is >= than
* more_assert_level.
*/
#define NM_MORE_ASSERT_ONCE(more_assert_level) \
( (NM_MORE_ASSERTS >= (more_assert_level)) \
&& ({ \
static volatile int _assert_once = 0; \
\
G_STATIC_ASSERT_EXPR ((more_assert_level) >= 0); \
\
G_UNLIKELY ( _assert_once == 0 \
&& g_atomic_int_compare_and_exchange (&_assert_once, 0, 1)); \
}))
/*****************************************************************************/
#define NM_GOBJECT_PROPERTIES_DEFINE_BASE(...) \