[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Specialize handling for mutexes allocated for condition variables
commit 6c9363310aaea9d39fae4d9dd50e78d42c3598b3
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue Sep 24 15:03:51 2013 -0400
Specialize handling for mutexes allocated for condition variables
(These must not be reentrant mutexes with pthreads.)
---
src/common/compat_pthreads.c | 16 ++++++++++++++++
src/common/compat_threads.h | 1 +
src/common/compat_winthreads.c | 6 ++++++
3 files changed, 23 insertions(+)
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index e58b3f7..59b54a6 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)
diff --git a/src/common/compat_threads.h b/src/common/compat_threads.h
index 6d3ba3a..581d8dd 100644
--- a/src/common/compat_threads.h
+++ b/src/common/compat_threads.h
@@ -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);
diff --git a/src/common/compat_winthreads.c b/src/common/compat_winthreads.c
index 11f91c6..2b1527a 100644
--- a/src/common/compat_winthreads.c
+++ b/src/common/compat_winthreads.c
@@ -49,6 +49,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)
{
DeleteCriticalSection(&m->mutex);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits