diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-04-22 16:05:11 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-04-22 16:05:11 +0000 |
commit | 8a05bd90ce78c70e0c5a9362bcfda9c24f43f492 (patch) | |
tree | ae80741cdb448bffb67ac4b9fe106a5e6c4bdd35 | |
parent | 68b2a57ffd719c1daf24c387ad37d795152eb8ae (diff) | |
download | tor-8a05bd90ce78c70e0c5a9362bcfda9c24f43f492.tar.gz tor-8a05bd90ce78c70e0c5a9362bcfda9c24f43f492.zip |
r15266@tombo: nickm | 2008-04-22 12:05:07 -0400
Backport: On platforms using pthreads, allow a thread to acquire a lock it already holds. This is crucial for logging: otherwise any log message thrown from inside the logging process (especially from control.c) will deadlock. Win32 CriticalSections are already recursive. Bug spotted by nwf. Bugfix on 0.2.0.16-alpha.
svn:r14407
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/common/compat.c | 5 |
2 files changed, 7 insertions, 1 deletions
@@ -23,6 +23,9 @@ Changes in version 0.2.0.24-rc - 2008-04-0? Fixes bug 660. Bugfix on 0.1.2.x. - Avoid allocating extra space when computing consensuses on 64-bit platforms. Bug spotted by aakova. + - Use recursive pthread mutexes in order to avoid deadlock when + logging debug-level messages to a controller. Bug spotted by + nwf, bugfix on 0.2.0.16-alpha. Changes in version 0.2.0.23-rc - 2008-03-24 diff --git a/src/common/compat.c b/src/common/compat.c index 9b9afb50f7..90905c0194 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1746,13 +1746,14 @@ tor_get_thread_id(void) struct tor_mutex_t { pthread_mutex_t mutex; }; +static pthread_mutexattr_t attr_reentrant; /** Allocate and return new lock. */ tor_mutex_t * tor_mutex_new(void) { int err; tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t)); - err = pthread_mutex_init(&mutex->mutex, NULL); + err = pthread_mutex_init(&mutex->mutex, &attr_reentrant); if (PREDICT_UNLIKELY(err)) { log_err(LD_GENERAL, "Error %d creating a mutex.", err); tor_fragile_assert(); @@ -1868,6 +1869,8 @@ tor_cond_signal_all(tor_cond_t *cond) void tor_threads_init(void) { + pthread_mutexattr_init(&attr_reentrant); + pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE); } #elif defined(USE_WIN32_THREADS) #if 0 |