diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-11-27 17:22:19 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-11-27 17:36:51 -0500 |
commit | 0cd3bb9f3a53cce9a64ce1536d6e171848e8da59 (patch) | |
tree | 6597c900dc2b4cb3ee0018cde1b84fe2499f322c /evthread-internal.h | |
parent | 2df1f82bfa1b432a277b0e1f8fc65aed7898f5e5 (diff) | |
download | libevent-0cd3bb9f3a53cce9a64ce1536d6e171848e8da59.tar.gz |
Improved optional lock debugging.
There were a couple of places in the code where we manually kept lock
counts to make sure we never accessed resources without holding a
lock, and that we never released a lock we didn't have. The
lock-debugging code already puts counts on _every_ lock when lock
debugging is enabled, so there is no need to keep these counts around
otherwise. This patch rewrites the ASSERT_FOO_LOCKED macros to all
use a common EVLOCK_ASSERT_LOCKED().
We also teach the lock debugging code to keep track of who exactly
holds each lock, so that EVLOCK_ASSERT_LOCKED() means "locked by this
thread."
Diffstat (limited to 'evthread-internal.h')
-rw-r--r-- | evthread-internal.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/evthread-internal.h b/evthread-internal.h index b7da22d4..6335a361 100644 --- a/evthread-internal.h +++ b/evthread-internal.h @@ -40,6 +40,7 @@ struct event_base; enabled. */ extern struct evthread_lock_callbacks _evthread_lock_fns; extern unsigned long (*_evthread_id_fn)(void); +extern int _evthread_lock_debugging_enabled; /** True iff the given event_base is set up to use locking */ #define EVBASE_USING_LOCKS(base) \ @@ -129,6 +130,18 @@ extern unsigned long (*_evthread_id_fn)(void); if (EVBASE_USING_LOCKS(base)) \ _evthread_lock_fns.unlock(0, (base)->lockvar); \ } while (0) + +/** If lock debugging is enabled, and lock is non-null, assert that 'lock' is + * locked and held by us. */ +#define EVLOCK_ASSERT_LOCKED(lock) \ + do { \ + if ((lock) && _evthread_lock_debugging_enabled) { \ + EVUTIL_ASSERT(_evthread_is_debug_lock_held(lock)); \ + } \ + } while (0) + +int _evthread_is_debug_lock_held(void *lock); + #else /* _EVENT_DISABLE_THREAD_SUPPORT */ #define EVTHREAD_GET_ID() 1 @@ -143,7 +156,7 @@ extern unsigned long (*_evthread_id_fn)(void); #define EVBASE_IN_THREAD(base) 1 #define EVBASE_ACQUIRE_LOCK(base, lock) _EVUTIL_NIL_STMT #define EVBASE_RELEASE_LOCK(base, lock) _EVUTIL_NIL_STMT - +#define EVLOCK_ASSERT_LOCKED(lock) _EVUTIL_NIL_STMT #endif #ifdef __cplusplus |