diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 52591040e2..3cb11a973f 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -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(...) \