diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-10-05 13:37:07 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-10-17 22:52:47 +0100 |
commit | d11014386f739f43ec5f290714d7c51cc638f172 (patch) | |
tree | 3f548bc5d28829734cf1b61eb02e07d8c3077f84 /src/cairo-mutex-impl-private.h | |
parent | bccfdf7d93c2a92a342127fc212770f4053cb2cf (diff) |
Add support for lockdep.
lockdep is a valgrind skin which performs pthread locking correctness
validation. In particular it allows one to write assert(HOLDS_LOCK(mutex))
which both documents the preconditions for a function and enforces them
when the program is run under lockdep.
As an aide to lockdep (as it works by intercepting the pthread functions),
all the mutexes should be initialised and destroyed using
pthread_mutex_init() and pthread_mutex_destroy() rather than using static
initializers and no-ops.
Diffstat (limited to 'src/cairo-mutex-impl-private.h')
-rw-r--r-- | src/cairo-mutex-impl-private.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cairo-mutex-impl-private.h b/src/cairo-mutex-impl-private.h index 25fee4b6..52519076 100644 --- a/src/cairo-mutex-impl-private.h +++ b/src/cairo-mutex-impl-private.h @@ -47,6 +47,11 @@ #include "config.h" #endif +#if HAVE_LOCKDEP +#include <lockdep.h> +#endif + +CAIRO_BEGIN_DECLS /* A fully qualified no-operation statement */ #define CAIRO_MUTEX_IMPL_NOOP do {/*no-op*/} while (0) @@ -171,10 +176,19 @@ typedef pthread_mutex_t cairo_mutex_impl_t; # define CAIRO_MUTEX_IMPL_PTHREAD 1 +#if HAVE_LOCKDEP +/* expose all mutexes to the validator */ +# define CAIRO_MUTEX_IMPL_INIT(mutex) pthread_mutex_init (&(mutex), NULL) +#endif # define CAIRO_MUTEX_IMPL_LOCK(mutex) pthread_mutex_lock (&(mutex)) # define CAIRO_MUTEX_IMPL_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) +#if HAVE_LOCKDEP +# define CAIRO_HOLDS_MUTEX(mutex) LOCKDEP_HOLDS_LOCK (&(mutex)) +#endif # define CAIRO_MUTEX_IMPL_FINI(mutex) pthread_mutex_destroy (&(mutex)) +#if ! HAVE_LOCKDEP # define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP +#endif # define CAIRO_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER #elif defined(HAVE_WINDOWS_H) || defined(_MSC_VER) /*************************/ |