diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-09-25 11:41:40 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-01-14 11:05:56 -0500 |
commit | 3868b5d210f8bccbfb88464f62089447cb3330ed (patch) | |
tree | 875204c3978e3f2ebd5a3522d1e6abb87b33951d /src | |
parent | 93ad89e9d219d6cea764652a05c236210c7de3fa (diff) | |
download | tor-3868b5d210f8bccbfb88464f62089447cb3330ed.tar.gz tor-3868b5d210f8bccbfb88464f62089447cb3330ed.zip |
Rename mutex_for_cond -> mutex_nonreentrant
We'll want to use these for other stuff too.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/compat_pthreads.c | 6 | ||||
-rw-r--r-- | src/common/compat_threads.c | 9 | ||||
-rw-r--r-- | src/common/compat_threads.h | 6 | ||||
-rw-r--r-- | src/common/compat_winthreads.c | 2 |
4 files changed, 18 insertions, 5 deletions
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c index a2e406521f..8d3c60917a 100644 --- a/src/common/compat_pthreads.c +++ b/src/common/compat_pthreads.c @@ -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)) diff --git a/src/common/compat_threads.c b/src/common/compat_threads.c index 024c627cf1..f2a516a4a3 100644 --- a/src/common/compat_threads.c +++ b/src/common/compat_threads.c @@ -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) diff --git a/src/common/compat_threads.h b/src/common/compat_threads.h index 9070f13e80..245df76178 100644 --- a/src/common/compat_threads.h +++ b/src/common/compat_threads.h @@ -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); diff --git a/src/common/compat_winthreads.c b/src/common/compat_winthreads.c index 2b1527ad34..0ab26b7ebd 100644 --- a/src/common/compat_winthreads.c +++ b/src/common/compat_winthreads.c @@ -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); } |