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 /evbuffer-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 'evbuffer-internal.h')
-rw-r--r-- | evbuffer-internal.h | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/evbuffer-internal.h b/evbuffer-internal.h index 2808b6ef..7e08ee9b 100644 --- a/evbuffer-internal.h +++ b/evbuffer-internal.h @@ -121,9 +121,6 @@ struct evbuffer { /** Used to implement deferred callbacks. */ struct deferred_cb_queue *cb_queue; - /** For debugging: how many times have we acquired the lock for this - * evbuffer? */ - int lock_count; /** A reference count on this evbuffer. When the reference count * reaches 0, the buffer is destroyed. Manipulated with * evbuffer_incref and evbuffer_decref_and_unlock and @@ -202,47 +199,24 @@ struct evbuffer_chain_reference { /** Return a pointer to extra data allocated along with an evbuffer. */ #define EVBUFFER_CHAIN_EXTRA(t, c) (t *)((struct evbuffer_chain *)(c) + 1) -/** Assert that somebody (hopefully us) is holding the lock on an evbuffer */ +/** Assert that we are holding the lock on an evbuffer */ #define ASSERT_EVBUFFER_LOCKED(buffer) \ - do { \ - EVUTIL_ASSERT((buffer)->lock_count > 0); \ - } while (0) -/** Assert that nobody is holding the lock on an evbuffer */ -#define ASSERT_EVBUFFER_UNLOCKED(buffer) \ - do { \ - EVUTIL_ASSERT((buffer)->lock_count == 0); \ - } while (0) -#define _EVBUFFER_INCREMENT_LOCK_COUNT(buffer) \ - do { \ - ((struct evbuffer*)(buffer))->lock_count++; \ - } while (0) -#define _EVBUFFER_DECREMENT_LOCK_COUNT(buffer) \ - do { \ - ASSERT_EVBUFFER_LOCKED(buffer); \ - ((struct evbuffer*)(buffer))->lock_count--; \ - } while (0) + EVLOCK_ASSERT_LOCKED((buffer)->lock) #define EVBUFFER_LOCK(buffer) \ do { \ EVLOCK_LOCK((buffer)->lock, 0); \ - _EVBUFFER_INCREMENT_LOCK_COUNT(buffer); \ } while(0) #define EVBUFFER_UNLOCK(buffer) \ do { \ - _EVBUFFER_DECREMENT_LOCK_COUNT(buffer); \ EVLOCK_UNLOCK((buffer)->lock, 0); \ } while(0) - #define EVBUFFER_LOCK2(buffer1, buffer2) \ do { \ EVLOCK_LOCK2((buffer1)->lock, (buffer2)->lock, 0, 0); \ - _EVBUFFER_INCREMENT_LOCK_COUNT(buffer1); \ - _EVBUFFER_INCREMENT_LOCK_COUNT(buffer2); \ } while(0) #define EVBUFFER_UNLOCK2(buffer1, buffer2) \ do { \ - _EVBUFFER_DECREMENT_LOCK_COUNT(buffer1); \ - _EVBUFFER_DECREMENT_LOCK_COUNT(buffer2); \ EVLOCK_UNLOCK2((buffer1)->lock, (buffer2)->lock, 0, 0); \ } while(0) |