aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat_pthreads.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-09-24 15:03:51 -0400
committerNick Mathewson <nickm@torproject.org>2015-01-14 10:52:56 -0500
commit6c9363310aaea9d39fae4d9dd50e78d42c3598b3 (patch)
treee5749f3411c28182ecfe7204d0579891f44977b2 /src/common/compat_pthreads.c
parent65016304d23503e230e8b097b5cdc1e4897b9b57 (diff)
downloadtor-6c9363310aaea9d39fae4d9dd50e78d42c3598b3.tar.gz
tor-6c9363310aaea9d39fae4d9dd50e78d42c3598b3.zip
Specialize handling for mutexes allocated for condition variables
(These must not be reentrant mutexes with pthreads.)
Diffstat (limited to 'src/common/compat_pthreads.c')
-rw-r--r--src/common/compat_pthreads.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index e58b3f7b57..59b54a600a 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -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)