[or-cvs] r14407: Backport: On platforms using pthreads, allow a thread to acq (in tor/branches/tor-0_2_0-patches: . src/common)

nickm at seul.org nickm at seul.org
Tue Apr 22 16:05:11 UTC 2008


Author: nickm
Date: 2008-04-22 12:05:11 -0400 (Tue, 22 Apr 2008)
New Revision: 14407

Modified:
   tor/branches/tor-0_2_0-patches/
   tor/branches/tor-0_2_0-patches/ChangeLog
   tor/branches/tor-0_2_0-patches/src/common/compat.c
Log:
 r15266 at 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.



Property changes on: tor/branches/tor-0_2_0-patches
___________________________________________________________________
 svk:merge ticket from /tor/020 [r15266] on 49666b30-7950-49c5-bedf-9dc8f3168102

Modified: tor/branches/tor-0_2_0-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_2_0-patches/ChangeLog	2008-04-22 15:59:59 UTC (rev 14406)
+++ tor/branches/tor-0_2_0-patches/ChangeLog	2008-04-22 16:05:11 UTC (rev 14407)
@@ -23,6 +23,9 @@
       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

Modified: tor/branches/tor-0_2_0-patches/src/common/compat.c
===================================================================
--- tor/branches/tor-0_2_0-patches/src/common/compat.c	2008-04-22 15:59:59 UTC (rev 14406)
+++ tor/branches/tor-0_2_0-patches/src/common/compat.c	2008-04-22 16:05:11 UTC (rev 14407)
@@ -1746,13 +1746,14 @@
 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 @@
 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



More information about the tor-commits mailing list