diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-08-22 16:24:52 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-08-22 16:24:52 +0000 |
commit | 88e61626492741ee045cef1e716abf6ca580eb88 (patch) | |
tree | 0f4096860cd8e12e6e397c3c06ea921574cae01e /src/common/compat.h | |
parent | 0800b332a0ccd82ad63fcd1b7bf42b3a8f854422 (diff) | |
download | tor-88e61626492741ee045cef1e716abf6ca580eb88.tar.gz tor-88e61626492741ee045cef1e716abf6ca580eb88.zip |
r17848@tombo: nickm | 2008-08-22 12:10:11 -0400
Make definition of tor_mutex_t go into compat.h, so that it is possible to inline mutexes in critical objects. Add init/uninit functions for mutexes allocated inside other structs.
svn:r16623
Diffstat (limited to 'src/common/compat.h')
-rw-r--r-- | src/common/compat.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index da181ad399..f21a208ed3 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -426,19 +426,33 @@ void spawn_exit(void) ATTR_NORETURN; * Linux, etc), we need locking for them. On platforms with poor thread * support or broken gethostbyname_r, these functions are no-ops. */ -typedef struct tor_mutex_t tor_mutex_t; +/** A generic lock structure for multithreaded builds. */ +typedef struct tor_mutex_t { +#if defined(USE_WIN32_THREADS) + CRITICAL_SECTION mutex; +#elif defined(USE_PTHREADS) + pthread_mutex_t mutex; +#else + int _unused; +#endif +} tor_mutex_t; + #ifdef TOR_IS_MULTITHREADED tor_mutex_t *tor_mutex_new(void); +void tor_mutex_init(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); +void tor_mutex_uninit(tor_mutex_t *m); unsigned long tor_get_thread_id(void); void tor_threads_init(void); #else #define tor_mutex_new() ((tor_mutex_t*)tor_malloc(sizeof(int))) +#define tor_mutex_init(m) STMT_NIL #define tor_mutex_acquire(m) STMT_NIL #define tor_mutex_release(m) STMT_NIL #define tor_mutex_free(m) STMT_BEGIN tor_free(m); STMT_END +#define tor_mutex_uninit(m) STMT_NIL #define tor_get_thread_id() (1UL) #define tor_threads_init() STMT_NIL #endif |