Tor  0.4.7.0-alpha-dev
compat_mutex.c
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-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file compat_mutex.c
8  *
9  * \brief Portable wrapper for platform mutex implementations.
10  **/
11 
12 #include "lib/lock/compat_mutex.h"
13 #include "lib/malloc/malloc.h"
14 
15 /** Return a newly allocated, ready-for-use mutex. */
18 {
19  tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
20  tor_mutex_init(m);
21  return m;
22 }
23 /** Return a newly allocated, ready-for-use mutex. This one might be
24  * non-recursive, if that's faster. */
27 {
28  tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
30  return m;
31 }
32 /** Release all storage and system resources held by <b>m</b>.
33  *
34  * Destroying a locked mutex is undefined behaviour. Global mutexes may be
35  * locked when they are passed to this function, because multiple threads can
36  * still access them. So we can either:
37  * - destroy on shutdown, and re-initialise when tor re-initialises, or
38  * - skip destroying and re-initialisation, using a sentinel variable.
39  * See #31735 for details.
40  */
41 void
43 {
44  if (!m)
45  return;
47  tor_free(m);
48 }
tor_mutex_t * tor_mutex_new(void)
Definition: compat_mutex.c:17
void tor_mutex_free_(tor_mutex_t *m)
Definition: compat_mutex.c:42
tor_mutex_t * tor_mutex_new_nonrecursive(void)
Definition: compat_mutex.c:26
Header for compat_mutex.c.
void tor_mutex_init_nonrecursive(tor_mutex_t *m)
void tor_mutex_init(tor_mutex_t *m)
void tor_mutex_uninit(tor_mutex_t *m)
Headers for util_malloc.c.
#define tor_free(p)
Definition: malloc.h:52