| 
														
															@@ -45,7 +45,6 @@ static pthread_attr_t attr_detached; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** True iff we've called tor_threads_init() */ 
														 | 
														
														 | 
														
															 /** True iff we've called tor_threads_init() */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 static int threads_initialized = 0; 
														 | 
														
														 | 
														
															 static int threads_initialized = 0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** Minimalist interface to run a void function in the background.  On 
														 | 
														
														 | 
														
															 /** Minimalist interface to run a void function in the background.  On 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * Unix calls fork, on win32 calls beginthread.  Returns -1 on failure. 
														 | 
														
														 | 
														
															  * Unix calls fork, on win32 calls beginthread.  Returns -1 on failure. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * func should not return, but rather should call spawn_exit. 
														 | 
														
														 | 
														
															  * func should not return, but rather should call spawn_exit. 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -79,9 +78,10 @@ spawn_exit(void) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** A mutex attribute that we're going to use to tell pthreads that we want 
														 | 
														
														 | 
														
															 /** A mutex attribute that we're going to use to tell pthreads that we want 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * "reentrant" mutexes (i.e., once we can re-lock if we're already holding 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ * "recursive" mutexes (i.e., once we can re-lock if we're already holding 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * them.) */ 
														 | 
														
														 | 
														
															  * them.) */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-static pthread_mutexattr_t attr_reentrant; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+static pthread_mutexattr_t attr_recursive; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** Initialize <b>mutex</b> so it can be locked.  Every mutex must be set 
														 | 
														
														 | 
														
															 /** Initialize <b>mutex</b> so it can be locked.  Every mutex must be set 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * up with tor_mutex_init() or tor_mutex_new(); not both. */ 
														 | 
														
														 | 
														
															  * up with tor_mutex_init() or tor_mutex_new(); not both. */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 void 
														 | 
														
														 | 
														
															 void 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -90,7 +90,7 @@ tor_mutex_init(tor_mutex_t *mutex) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   int err; 
														 | 
														
														 | 
														
															   int err; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if (PREDICT_UNLIKELY(!threads_initialized)) 
														 | 
														
														 | 
														
															   if (PREDICT_UNLIKELY(!threads_initialized)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     tor_threads_init(); 
														 | 
														
														 | 
														
															     tor_threads_init(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  err = pthread_mutex_init(&mutex->mutex, &attr_reentrant); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  err = pthread_mutex_init(&mutex->mutex, &attr_recursive); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if (PREDICT_UNLIKELY(err)) { 
														 | 
														
														 | 
														
															   if (PREDICT_UNLIKELY(err)) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     log_err(LD_GENERAL, "Error %d creating a mutex.", err); 
														 | 
														
														 | 
														
															     log_err(LD_GENERAL, "Error %d creating a mutex.", err); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     tor_fragile_assert(); 
														 | 
														
														 | 
														
															     tor_fragile_assert(); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -98,9 +98,9 @@ tor_mutex_init(tor_mutex_t *mutex) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** As tor_mutex_init, but initialize a mutex suitable that may be 
														 | 
														
														 | 
														
															 /** As tor_mutex_init, but initialize a mutex suitable that may be 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * non-reentrant, if the OS supports that. */ 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ * non-recursive, if the OS supports that. */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 void 
														 | 
														
														 | 
														
															 void 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-tor_mutex_init_nonreentrant(tor_mutex_t *mutex) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+tor_mutex_init_nonrecursive(tor_mutex_t *mutex) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 { 
														 | 
														
														 | 
														
															 { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   int err; 
														 | 
														
														 | 
														
															   int err; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if (PREDICT_UNLIKELY(!threads_initialized)) 
														 | 
														
														 | 
														
															   if (PREDICT_UNLIKELY(!threads_initialized)) 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -232,8 +232,8 @@ void 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 tor_threads_init(void) 
														 | 
														
														 | 
														
															 tor_threads_init(void) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 { 
														 | 
														
														 | 
														
															 { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if (!threads_initialized) { 
														 | 
														
														 | 
														
															   if (!threads_initialized) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    pthread_mutexattr_init(&attr_reentrant); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    pthread_mutexattr_init(&attr_recursive); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    pthread_mutexattr_settype(&attr_recursive, PTHREAD_MUTEX_RECURSIVE); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     tor_assert(0==pthread_attr_init(&attr_detached)); 
														 | 
														
														 | 
														
															     tor_assert(0==pthread_attr_init(&attr_detached)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     tor_assert(0==pthread_attr_setdetachstate(&attr_detached, 1)); 
														 | 
														
														 | 
														
															     tor_assert(0==pthread_attr_setdetachstate(&attr_detached, 1)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     threads_initialized = 1; 
														 | 
														
														 | 
														
															     threads_initialized = 1; 
														 |