Tor
0.4.6.0-alpha-dev
lib
lock
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-2020, 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. */
16
tor_mutex_t
*
17
tor_mutex_new
(
void
)
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. */
25
tor_mutex_t
*
26
tor_mutex_new_nonrecursive
(
void
)
27
{
28
tor_mutex_t
*m = tor_malloc_zero(
sizeof
(
tor_mutex_t
));
29
tor_mutex_init_nonrecursive
(m);
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
42
tor_mutex_free_
(
tor_mutex_t
*m)
43
{
44
if
(!m)
45
return
;
46
tor_mutex_uninit
(m);
47
tor_free
(m);
48
}
tor_free
#define tor_free(p)
Definition:
malloc.h:52
tor_mutex_init_nonrecursive
void tor_mutex_init_nonrecursive(tor_mutex_t *m)
Definition:
compat_mutex_pthreads.c:56
tor_mutex_uninit
void tor_mutex_uninit(tor_mutex_t *m)
Definition:
compat_mutex_pthreads.c:107
tor_mutex_free_
void tor_mutex_free_(tor_mutex_t *m)
Definition:
compat_mutex.c:42
tor_mutex_t
Definition:
compat_mutex.h:40
malloc.h
Headers for util_malloc.c.
tor_mutex_new
tor_mutex_t * tor_mutex_new(void)
Definition:
compat_mutex.c:17
compat_mutex.h
Header for compat_mutex.c.
tor_mutex_init
void tor_mutex_init(tor_mutex_t *m)
Definition:
compat_mutex_pthreads.c:41
tor_mutex_new_nonrecursive
tor_mutex_t * tor_mutex_new_nonrecursive(void)
Definition:
compat_mutex.c:26
Generated by
1.8.20