aboutsummaryrefslogtreecommitdiff
path: root/externals/jemalloc/include/internal/mutex.h
blob: 108bfa8abfd73b64fd4044e95aa23b3bfca8b8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************/
#ifdef JEMALLOC_H_TYPES

typedef pthread_mutex_t malloc_mutex_t;

#endif /* JEMALLOC_H_TYPES */
/******************************************************************************/
#ifdef JEMALLOC_H_STRUCTS

#endif /* JEMALLOC_H_STRUCTS */
/******************************************************************************/
#ifdef JEMALLOC_H_EXTERNS

#ifdef JEMALLOC_LAZY_LOCK
extern bool isthreaded;
#else
#  define isthreaded true
#endif

bool	malloc_mutex_init(malloc_mutex_t *mutex);

#endif /* JEMALLOC_H_EXTERNS */
/******************************************************************************/
#ifdef JEMALLOC_H_INLINES

#ifndef JEMALLOC_ENABLE_INLINE
void	malloc_mutex_lock(malloc_mutex_t *mutex);
bool	malloc_mutex_trylock(malloc_mutex_t *mutex);
void	malloc_mutex_unlock(malloc_mutex_t *mutex);
#endif

#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_MUTEX_C_))
JEMALLOC_INLINE void
malloc_mutex_lock(malloc_mutex_t *mutex)
{

	if (isthreaded)
		pthread_mutex_lock(mutex);
}

JEMALLOC_INLINE bool
malloc_mutex_trylock(malloc_mutex_t *mutex)
{

	if (isthreaded)
		return (pthread_mutex_trylock(mutex) != 0);
	else
		return (false);
}

JEMALLOC_INLINE void
malloc_mutex_unlock(malloc_mutex_t *mutex)
{

	if (isthreaded)
		pthread_mutex_unlock(mutex);
}
#endif

#endif /* JEMALLOC_H_INLINES */
/******************************************************************************/