1 /******************************************************************************/
2 #ifdef JEMALLOC_H_TYPES
5 typedef OSSpinLock malloc_mutex_t
;
7 typedef pthread_mutex_t malloc_mutex_t
;
10 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
11 # define MALLOC_MUTEX_INITIALIZER PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
13 # define MALLOC_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
16 #endif /* JEMALLOC_H_TYPES */
17 /******************************************************************************/
18 #ifdef JEMALLOC_H_STRUCTS
20 #endif /* JEMALLOC_H_STRUCTS */
21 /******************************************************************************/
22 #ifdef JEMALLOC_H_EXTERNS
24 #ifdef JEMALLOC_LAZY_LOCK
25 extern bool isthreaded
;
27 # define isthreaded true
30 bool malloc_mutex_init(malloc_mutex_t
*mutex
);
31 void malloc_mutex_destroy(malloc_mutex_t
*mutex
);
33 #endif /* JEMALLOC_H_EXTERNS */
34 /******************************************************************************/
35 #ifdef JEMALLOC_H_INLINES
37 #ifndef JEMALLOC_ENABLE_INLINE
38 void malloc_mutex_lock(malloc_mutex_t
*mutex
);
39 bool malloc_mutex_trylock(malloc_mutex_t
*mutex
);
40 void malloc_mutex_unlock(malloc_mutex_t
*mutex
);
43 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_MUTEX_C_))
45 malloc_mutex_lock(malloc_mutex_t
*mutex
)
49 #ifdef JEMALLOC_OSSPIN
50 OSSpinLockLock(mutex
);
52 pthread_mutex_lock(mutex
);
58 malloc_mutex_trylock(malloc_mutex_t
*mutex
)
62 #ifdef JEMALLOC_OSSPIN
63 return (OSSpinLockTry(mutex
) == false);
65 return (pthread_mutex_trylock(mutex
) != 0);
72 malloc_mutex_unlock(malloc_mutex_t
*mutex
)
76 #ifdef JEMALLOC_OSSPIN
77 OSSpinLockUnlock(mutex
);
79 pthread_mutex_unlock(mutex
);
85 #endif /* JEMALLOC_H_INLINES */
86 /******************************************************************************/