]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Specialize handling for mutexes allocated for condition variables
authorNick Mathewson <nickm@torproject.org>
Tue, 24 Sep 2013 19:03:51 +0000 (15:03 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 14 Jan 2015 15:52:56 +0000 (10:52 -0500)
(These must not be reentrant mutexes with pthreads.)

src/common/compat_pthreads.c
src/common/compat_threads.h
src/common/compat_winthreads.c

index e58b3f7b5764b1ff2ee284471e1dd39661123c18..59b54a600a27a415635b7edd2273dff3e9d43353 100644 (file)
@@ -96,6 +96,22 @@ tor_mutex_init(tor_mutex_t *mutex)
     tor_fragile_assert();
   }
 }
+
+/** As tor_mutex_init, but initialize a mutex suitable for use with a
+ * condition variable. */
+void
+tor_mutex_init_for_cond(tor_mutex_t *mutex)
+{
+  int err;
+  if (PREDICT_UNLIKELY(!threads_initialized))
+    tor_threads_init();
+  err = pthread_mutex_init(&mutex->mutex, NULL);
+  if (PREDICT_UNLIKELY(err)) {
+    log_err(LD_GENERAL, "Error %d creating a mutex.", err);
+    tor_fragile_assert();
+  }
+}
+
 /** Wait until <b>m</b> is free, then acquire it. */
 void
 tor_mutex_acquire(tor_mutex_t *m)
index 6d3ba3ae2109f695e7d896347bb9c2493b81c939..581d8dd7b971d811cfb569a61009f81d09dcdf3e 100644 (file)
@@ -47,6 +47,7 @@ typedef struct tor_mutex_t {
 
 tor_mutex_t *tor_mutex_new(void);
 void tor_mutex_init(tor_mutex_t *m);
+void tor_mutex_init_for_cond(tor_mutex_t *m);
 void tor_mutex_acquire(tor_mutex_t *m);
 void tor_mutex_release(tor_mutex_t *m);
 void tor_mutex_free(tor_mutex_t *m);
index 11f91c63dfb19b28f4d824cb4137b8e9c01fb669..2b1527ad3476a09a5287c9ef0c8d5e043a02d2a9 100644 (file)
@@ -48,6 +48,12 @@ tor_mutex_init(tor_mutex_t *m)
 {
   InitializeCriticalSection(&m->mutex);
 }
+void
+tor_mutex_init_for_cond(tor_mutex_t *m)
+{
+  InitializeCriticalSection(&m->mutex);
+}
+
 void
 tor_mutex_uninit(tor_mutex_t *m)
 {