]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Rename mutex_for_cond -> mutex_nonreentrant
authorNick Mathewson <nickm@torproject.org>
Wed, 25 Sep 2013 15:41:40 +0000 (11:41 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 14 Jan 2015 16:05:56 +0000 (11:05 -0500)
We'll want to use these for other stuff too.

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

index a2e406521f7dfb3cfd072e60ec9abe930b758eec..8d3c60917a38253f2d581118d3ef83668b0efd89 100644 (file)
@@ -97,10 +97,10 @@ tor_mutex_init(tor_mutex_t *mutex)
   }
 }
 
-/** As tor_mutex_init, but initialize a mutex suitable for use with a
- * condition variable. */
+/** As tor_mutex_init, but initialize a mutex suitable that may be
+ * non-reentrant, if the OS supports that. */
 void
-tor_mutex_init_for_cond(tor_mutex_t *mutex)
+tor_mutex_init_nonreentrant(tor_mutex_t *mutex)
 {
   int err;
   if (PREDICT_UNLIKELY(!threads_initialized))
index 024c627cf1a8e3bd178aaa54b9e16e996e42bde9..f2a516a4a3bef2e56f5b743f3b4328bb30b4859e 100644 (file)
@@ -30,6 +30,15 @@ tor_mutex_new(void)
   tor_mutex_init(m);
   return m;
 }
+/** Return a newly allocated, ready-for-use mutex.  This one might be
+ * non-reentrant, if that's faster. */
+tor_mutex_t *
+tor_mutex_new_nonreentrant(void)
+{
+  tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
+  tor_mutex_init_nonreentrant(m);
+  return m;
+}
 /** Release all storage and system resources held by <b>m</b>. */
 void
 tor_mutex_free(tor_mutex_t *m)
index 9070f13e80b52e6eb6743545767211c3f462bb74..245df761789f43aed4786dcd7c0fe91a00c628d9 100644 (file)
@@ -46,8 +46,9 @@ typedef struct tor_mutex_t {
 
 
 tor_mutex_t *tor_mutex_new(void);
+tor_mutex_t *tor_mutex_new_nonreentrant(void);
 void tor_mutex_init(tor_mutex_t *m);
-void tor_mutex_init_for_cond(tor_mutex_t *m);
+void tor_mutex_init_nonreentrant(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);
@@ -55,6 +56,9 @@ void tor_mutex_uninit(tor_mutex_t *m);
 unsigned long tor_get_thread_id(void);
 void tor_threads_init(void);
 
+/** Conditions need nonreentrant mutexes with pthreads. */
+#define tor_mutex_init_for_cond(m) tor_mutex_init_nonreentrant(m)
+
 void set_main_thread(void);
 int in_main_thread(void);
 
index 2b1527ad3476a09a5287c9ef0c8d5e043a02d2a9..0ab26b7ebdc39d1ad447249ee952bc896acb2cc5 100644 (file)
@@ -49,7 +49,7 @@ tor_mutex_init(tor_mutex_t *m)
   InitializeCriticalSection(&m->mutex);
 }
 void
-tor_mutex_init_for_cond(tor_mutex_t *m)
+tor_mutex_init_nonreentrant(tor_mutex_t *m)
 {
   InitializeCriticalSection(&m->mutex);
 }