Remove unused function: dns_randfn_() in dns.c.
[tor.git] / src / lib / lock / compat_mutex.h
blobb63ce240243f2826e75b97bf797785147f8ec02f
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 */
6 /**
7 * \file compat_mutex.h
9 * \brief Header for compat_mutex.c
10 **/
12 #ifndef TOR_COMPAT_MUTEX_H
13 #define TOR_COMPAT_MUTEX_H
15 #include "orconfig.h"
16 #include "lib/cc/torint.h"
17 #include "lib/malloc/malloc.h"
19 #if defined(HAVE_PTHREAD_H) && !defined(_WIN32)
20 #include <pthread.h>
21 #endif
23 #if defined(_WIN32)
24 #include <windows.h>
25 #endif
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) || ... */
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. */
39 /** A generic lock structure for multithreaded builds. */
40 typedef struct tor_mutex_t {
41 #if defined(USE_WIN32_THREADS)
42 /** Windows-only: on windows, we implement locks with CRITICAL_SECTIONS. */
43 CRITICAL_SECTION mutex;
44 #elif defined(USE_PTHREADS)
45 /** Pthreads-only: with pthreads, we implement locks with
46 * pthread_mutex_t. */
47 pthread_mutex_t mutex;
48 #else
49 /** No-threads only: Dummy variable so that tor_mutex_t takes up space. */
50 int _unused;
51 #endif /* defined(USE_WIN32_MUTEX) || ... */
52 } tor_mutex_t;
54 tor_mutex_t *tor_mutex_new(void);
55 tor_mutex_t *tor_mutex_new_nonrecursive(void);
56 void tor_mutex_init(tor_mutex_t *m);
57 void tor_mutex_init_nonrecursive(tor_mutex_t *m);
58 void tor_mutex_acquire(tor_mutex_t *m);
59 void tor_mutex_release(tor_mutex_t *m);
60 void tor_mutex_free_(tor_mutex_t *m);
61 #define tor_mutex_free(m) FREE_AND_NULL(tor_mutex_t, tor_mutex_free_, (m))
62 void tor_mutex_uninit(tor_mutex_t *m);
64 void tor_locking_init(void);
66 #endif /* !defined(TOR_COMPAT_MUTEX_H) */