1#ifndef THR_MUTEX_INCLUDED
2#define THR_MUTEX_INCLUDED
61#define MY_MUTEX_INIT_SLOW NULL
64#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
66#define MY_MUTEX_INIT_FAST &my_fast_mutexattr
68#define MY_MUTEX_INIT_FAST NULL
72#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
74#define MY_MUTEX_INIT_ERRCHK &my_errorcheck_mutexattr
76#define MY_MUTEX_INIT_ERRCHK NULL
83 InitializeCriticalSection(mutex);
86 return pthread_mutex_init(mutex, attr);
92 EnterCriticalSection(mutex);
95 return pthread_mutex_lock(mutex);
101 if (TryEnterCriticalSection(mutex)) {
103 if (mutex->RecursionCount > 1) {
104 LeaveCriticalSection(mutex);
111 return pthread_mutex_trylock(mutex);
117 LeaveCriticalSection(mutex);
120 return pthread_mutex_unlock(mutex);
126 DeleteCriticalSection(mutex);
129 return pthread_mutex_destroy(mutex);
142void safe_mutex_global_init();
144 const char *
file, uint line);
145int safe_mutex_lock(safe_mutex_t *mp,
bool try_lock,
const char *
file,
147int safe_mutex_unlock(safe_mutex_t *mp,
const char *
file, uint line);
148int safe_mutex_destroy(safe_mutex_t *mp,
const char *
file, uint line);
150static inline void safe_mutex_assert_owner(safe_mutex_t *mp) {
151 assert(mp !=
nullptr);
157static inline void safe_mutex_assert_not_owner(safe_mutex_t *mp) {
158 assert(mp !=
nullptr);
168 const char *
file, uint line
172 assert(mp !=
nullptr);
183 const char *
file, uint line
187 assert(mp !=
nullptr);
188 assert(mp->m_u.m_safe_ptr !=
nullptr);
189 return safe_mutex_lock(mp->m_u.m_safe_ptr,
false,
file, line);
198 const char *
file, uint line
202 assert(mp !=
nullptr);
203 assert(mp->m_u.m_safe_ptr !=
nullptr);
204 return safe_mutex_lock(mp->m_u.m_safe_ptr,
true,
file, line);
213 const char *
file, uint line
217 assert(mp !=
nullptr);
218 assert(mp->m_u.m_safe_ptr !=
nullptr);
219 return safe_mutex_unlock(mp->m_u.m_safe_ptr,
file, line);
228 const char *
file, uint line
232 assert(mp !=
nullptr);
233 assert(mp->m_u.m_safe_ptr !=
nullptr);
234 int rc = safe_mutex_destroy(mp->m_u.m_safe_ptr,
file, line);
235 free(mp->m_u.m_safe_ptr);
236 mp->m_u.m_safe_ptr =
nullptr;
#define malloc(A)
Definition: lexyy.cc:914
#define free(A)
Definition: lexyy.cc:915
Some integer typedefs for easier portability.
Defines to make different thread packages compatible.
static my_thread_t my_thread_self()
Definition: my_thread.h:75
static int my_thread_equal(my_thread_t t1, my_thread_t t2)
Definition: my_thread.h:83
pthread_t my_thread_t
Definition: my_thread_bits.h:48
static int count
Definition: myisam_ftdump.cc:45
Definition: thr_mutex_bits.h:61
static int my_mutex_init(my_mutex_t *mp, const native_mutexattr_t *attr)
Definition: thr_mutex.h:165
static int native_mutex_unlock(native_mutex_t *mutex)
Definition: thr_mutex.h:115
static int native_mutex_destroy(native_mutex_t *mutex)
Definition: thr_mutex.h:124
static int my_mutex_destroy(my_mutex_t *mp)
Definition: thr_mutex.h:225
static int native_mutex_trylock(native_mutex_t *mutex)
Definition: thr_mutex.h:99
static int native_mutex_lock(native_mutex_t *mutex)
Definition: thr_mutex.h:90
static int native_mutex_init(native_mutex_t *mutex, const native_mutexattr_t *attr)
Definition: thr_mutex.h:79
static int my_mutex_lock(my_mutex_t *mp)
Definition: thr_mutex.h:180
static int my_mutex_trylock(my_mutex_t *mp)
Definition: thr_mutex.h:195
static int my_mutex_unlock(my_mutex_t *mp)
Definition: thr_mutex.h:210
pthread_mutex_t native_mutex_t
Definition: thr_mutex_bits.h:55
pthread_mutexattr_t native_mutexattr_t
Definition: thr_mutex_bits.h:56
native_mutex_t m_native
Definition: thr_mutex_bits.h:63
safe_mutex_t * m_safe_ptr
Definition: thr_mutex_bits.h:64