diff options
author | Thomas Haller <thaller@redhat.com> | 2020-02-19 15:28:33 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-19 15:35:07 +0100 |
commit | 14461e7217cc51dc4dd4c0f9ea97b93ccc5d1e5f (patch) | |
tree | 0dc7440ee758b448f89687cb1625b6e1ad2deb1a | |
parent | d9d51dd42d288501bb1af5ef69736dd8f1687e3b (diff) | |
download | NetworkManager-14461e7217cc51dc4dd4c0f9ea97b93ccc5d1e5f.tar.gz |
shared: add NM_MORE_ASSERT_ONCE() macro
-rw-r--r-- | shared/nm-glib-aux/nm-macros-internal.h | 18 |
1 files changed, 18 insertions, 0 deletions
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(...) \ |