Add an ASSERT_LOCKED(lock) macro
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 14 Nov 2018 20:43:49 +0000 (15:43 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 16 Nov 2018 18:49:51 +0000 (13:49 -0500)
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 <jeremie.galarneau@efficios.com>
src/common/macros.h

index c521aacd5f3df8f582502ce8faa9f29feb1c9063..c42cddd5050ca163a612e9f1744f9b7aaf03da5b 100644 (file)
@@ -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
This page took 0.025546 seconds and 4 git commands to generate.