From: Jérémie Galarneau Date: Wed, 14 Nov 2018 20:43:49 +0000 (-0500) Subject: Add an ASSERT_LOCKED(lock) macro X-Git-Tag: v2.11.0-rc2~183 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d7d758dd793b7b492fe6f5134f11ea0c7feaf6cc;p=lttng-tools.git Add an ASSERT_LOCKED(lock) macro This macro validates that a given lock is taken by using pthread_mutex_trylock(). The use of this macro is disouraged in hot paths for performance reasons. It is meant to catch errors in "cold" code path (e.g. error handling) where the additional safety it provides has no material effect on performance. Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/macros.h b/src/common/macros.h index c521aacd5..c42cddd50 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -106,6 +106,8 @@ void *zmalloc(size_t len) #define member_sizeof(type, field) sizeof(((type *) 0)->field) +#define ASSERT_LOCKED(lock) assert(pthread_mutex_trylock(&lock)) + /* * lttng_strncpy returns 0 on success, or nonzero on failure. * It checks that the @src string fits into @dst_len before performing