From d7d758dd793b7b492fe6f5134f11ea0c7feaf6cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 14 Nov 2018 15:43:49 -0500 Subject: [PATCH] Add an ASSERT_LOCKED(lock) macro MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/common/macros.h | 2 ++ 1 file changed, 2 insertions(+) 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 -- 2.34.1