2 #ifdef JEMALLOC_H_TYPES
4 typedef struct malloc_mutex_s malloc_mutex_t;
7 # define MALLOC_MUTEX_INITIALIZER
8 #elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
9 # define MALLOC_MUTEX_INITIALIZER \
10 {OS_UNFAIR_LOCK_INIT, WITNESS_INITIALIZER(WITNESS_RANK_OMIT)}
11 #elif (defined(JEMALLOC_OSSPIN))
12 # define MALLOC_MUTEX_INITIALIZER {0, WITNESS_INITIALIZER(WITNESS_RANK_OMIT)}
13 #elif (defined(JEMALLOC_MUTEX_INIT_CB))
14 # define MALLOC_MUTEX_INITIALIZER \
15 {PTHREAD_MUTEX_INITIALIZER, NULL, WITNESS_INITIALIZER(WITNESS_RANK_OMIT)}
17 # if (defined(JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP) && \
18 defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP))
19 # define MALLOC_MUTEX_TYPE PTHREAD_MUTEX_ADAPTIVE_NP
20 # define MALLOC_MUTEX_INITIALIZER \
21 {PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP, \
22 WITNESS_INITIALIZER(WITNESS_RANK_OMIT)}
24 # define MALLOC_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT
25 # define MALLOC_MUTEX_INITIALIZER \
26 {PTHREAD_MUTEX_INITIALIZER, WITNESS_INITIALIZER(WITNESS_RANK_OMIT)}
32 #ifdef JEMALLOC_H_STRUCTS
34 struct malloc_mutex_s {
36 # if _WIN32_WINNT >= 0x0600
39 CRITICAL_SECTION
lock;
41 #elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
43 #elif (defined(JEMALLOC_OSSPIN))
45 #elif (defined(JEMALLOC_MUTEX_INIT_CB))
47 malloc_mutex_t *postponed_next;
56 #ifdef JEMALLOC_H_EXTERNS
58 #ifdef JEMALLOC_LAZY_LOCK
62 # define isthreaded true
74 #ifdef JEMALLOC_H_INLINES
76 #ifndef JEMALLOC_ENABLE_INLINE
83 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_MUTEX_C_))
91 # if _WIN32_WINNT >= 0x0600
92 AcquireSRWLockExclusive(&
mutex->lock);
94 EnterCriticalSection(&
mutex->lock);
96 #elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
97 os_unfair_lock_lock(&
mutex->lock);
98 #elif (defined(JEMALLOC_OSSPIN))
99 OSSpinLockLock(&
mutex->lock);
101 pthread_mutex_lock(&
mutex->lock);
114 # if _WIN32_WINNT >= 0x0600
115 ReleaseSRWLockExclusive(&
mutex->lock);
117 LeaveCriticalSection(&
mutex->lock);
119 #elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
120 os_unfair_lock_unlock(&
mutex->lock);
121 #elif (defined(JEMALLOC_OSSPIN))
122 OSSpinLockUnlock(&
mutex->lock);
124 pthread_mutex_unlock(&
mutex->lock);
#define malloc_mutex_lock
#define witness_assert_not_owner
#define malloc_mutex_assert_owner
#define malloc_mutex_boot
#define malloc_mutex_init
#define malloc_mutex_postfork_parent
#define malloc_mutex_unlock
#define malloc_mutex_postfork_child
#define malloc_mutex_prefork
#define witness_assert_owner
#define malloc_mutex_assert_not_owner
static void lock(volatile int *lk)