diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-04-22 12:01:25 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-04-22 14:06:33 -0400 |
commit | b683cae3cb98b48c4dc5caa0b1768f7bb13b92f1 (patch) | |
tree | 89c2c36e4e461f7e81a89cb01bf4952ebb8c9bdd /evthread-internal.h | |
parent | b4f89f00c607689d867a83d9d52535f371c5d750 (diff) | |
download | libevent-b683cae3cb98b48c4dc5caa0b1768f7bb13b92f1.tar.gz |
Avoid race-condition when initializing global locks
Previously, we did stuff like
if (!lock)
EVTHREAD_ALLOC_LOCK(lock,0);
for the evsig base global lock, the arc4random lock, and the debug_map
lock. But that's potentially racy! Instead, we move the
responisiblity for global lock initialization to the functions where
we set up the lock callbacks.
(Rationale: We already require that you set up the locking callbacks
before you create any event_base, and that you do so exatly once.)
Diffstat (limited to 'evthread-internal.h')
-rw-r--r-- | evthread-internal.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/evthread-internal.h b/evthread-internal.h index 9317fdf1..fbb1c0d4 100644 --- a/evthread-internal.h +++ b/evthread-internal.h @@ -345,6 +345,24 @@ EVLOCK_TRY_LOCK(void *lock) int _evthread_is_debug_lock_held(void *lock); void *_evthread_debug_get_real_lock(void *lock); + +void *evthread_setup_global_lock_(void *lock_, unsigned locktype, + int enable_locks); + +#define EVTHREAD_SETUP_GLOBAL_LOCK(lockvar, locktype) \ + do { \ + lockvar = evthread_setup_global_lock_(lockvar, \ + (locktype), enable_locks); \ + if (!lockvar) { \ + event_warn("Couldn't allocate %s", #lockvar); \ + return -1; \ + } \ + } while (0); + +int event_global_setup_locks_(const int enable_locks); +int evsig_global_setup_locks_(const int enable_locks); +int evutil_secure_rng_global_setup_locks_(const int enable_locks); + #endif #ifdef __cplusplus |