tor  0.4.2.0-alpha-dev
compat_mutex.h
Go to the documentation of this file.
1 /* Copyright (c) 2003-2004, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
12 #ifndef TOR_COMPAT_MUTEX_H
13 #define TOR_COMPAT_MUTEX_H
14 
15 #include "orconfig.h"
16 #include "lib/cc/torint.h"
17 #include "lib/malloc/malloc.h"
18 
19 #if defined(HAVE_PTHREAD_H) && !defined(_WIN32)
20 #include <pthread.h>
21 #endif
22 
23 #if defined(_WIN32)
24 #include <windows.h>
25 #endif
26 
27 #if defined(_WIN32)
28 #define USE_WIN32_THREADS
29 #elif defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_CREATE)
30 #define USE_PTHREADS
31 #else
32 #error "No threading system was found"
33 #endif /* defined(_WIN32) || ... */
34 
35 /* Because we use threads instead of processes on most platforms (Windows,
36  * Linux, etc), we need locking for them. On platforms with poor thread
37  * support or broken gethostbyname_r, these functions are no-ops. */
38 
40 typedef struct tor_mutex_t {
41 #if defined(USE_WIN32_THREADS)
42 
43  CRITICAL_SECTION mutex;
44 #elif defined(USE_PTHREADS)
45 
47  pthread_mutex_t mutex;
48 #else
49 
50  int _unused;
51 #endif /* defined(USE_WIN32_THREADS) || ... */
52 } tor_mutex_t;
53 
61 #define tor_mutex_free(m) FREE_AND_NULL(tor_mutex_t, tor_mutex_free_, (m))
63 
64 void tor_locking_init(void);
65 
66 #endif /* !defined(TOR_COMPAT_MUTEX_H) */
void tor_mutex_release(tor_mutex_t *m)
tor_mutex_t * tor_mutex_new(void)
Definition: compat_mutex.c:17
void tor_mutex_init_nonrecursive(tor_mutex_t *m)
Integer definitions used throughout Tor.
Headers for util_malloc.c.
void tor_mutex_uninit(tor_mutex_t *m)
void tor_mutex_free_(tor_mutex_t *m)
Definition: compat_mutex.c:34
void tor_mutex_init(tor_mutex_t *m)
struct tor_mutex_t tor_mutex_t
void tor_mutex_acquire(tor_mutex_t *m)
tor_mutex_t * tor_mutex_new_nonrecursive(void)
Definition: compat_mutex.c:26