]> git.saurik.com Git - redis.git/blob - deps/jemalloc.orig/include/jemalloc/internal/mutex.h
Jemalloc updated to 3.0.0.
[redis.git] / deps / jemalloc.orig / include / jemalloc / internal / mutex.h
1 /******************************************************************************/
2 #ifdef JEMALLOC_H_TYPES
3
4 #ifdef JEMALLOC_OSSPIN
5 typedef OSSpinLock malloc_mutex_t;
6 #else
7 typedef pthread_mutex_t malloc_mutex_t;
8 #endif
9
10 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
11 # define MALLOC_MUTEX_INITIALIZER PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
12 #else
13 # define MALLOC_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
14 #endif
15
16 #endif /* JEMALLOC_H_TYPES */
17 /******************************************************************************/
18 #ifdef JEMALLOC_H_STRUCTS
19
20 #endif /* JEMALLOC_H_STRUCTS */
21 /******************************************************************************/
22 #ifdef JEMALLOC_H_EXTERNS
23
24 #ifdef JEMALLOC_LAZY_LOCK
25 extern bool isthreaded;
26 #else
27 # define isthreaded true
28 #endif
29
30 bool malloc_mutex_init(malloc_mutex_t *mutex);
31 void malloc_mutex_destroy(malloc_mutex_t *mutex);
32
33 #endif /* JEMALLOC_H_EXTERNS */
34 /******************************************************************************/
35 #ifdef JEMALLOC_H_INLINES
36
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);
41 #endif
42
43 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_MUTEX_C_))
44 JEMALLOC_INLINE void
45 malloc_mutex_lock(malloc_mutex_t *mutex)
46 {
47
48 if (isthreaded) {
49 #ifdef JEMALLOC_OSSPIN
50 OSSpinLockLock(mutex);
51 #else
52 pthread_mutex_lock(mutex);
53 #endif
54 }
55 }
56
57 JEMALLOC_INLINE bool
58 malloc_mutex_trylock(malloc_mutex_t *mutex)
59 {
60
61 if (isthreaded) {
62 #ifdef JEMALLOC_OSSPIN
63 return (OSSpinLockTry(mutex) == false);
64 #else
65 return (pthread_mutex_trylock(mutex) != 0);
66 #endif
67 } else
68 return (false);
69 }
70
71 JEMALLOC_INLINE void
72 malloc_mutex_unlock(malloc_mutex_t *mutex)
73 {
74
75 if (isthreaded) {
76 #ifdef JEMALLOC_OSSPIN
77 OSSpinLockUnlock(mutex);
78 #else
79 pthread_mutex_unlock(mutex);
80 #endif
81 }
82 }
83 #endif
84
85 #endif /* JEMALLOC_H_INLINES */
86 /******************************************************************************/