22 #include <ndb_global.h>
29 #include <my_pthread.h>
33 #ifndef NDB_MUTEX_STAT
34 typedef pthread_mutex_t NdbMutex;
37 pthread_mutex_t mutex;
39 unsigned cnt_lock_contention;
40 unsigned cnt_trylock_ok;
41 unsigned cnt_trylock_nok;
42 unsigned long long min_lock_wait_time_ns;
43 unsigned long long sum_lock_wait_time_ns;
44 unsigned long long max_lock_wait_time_ns;
45 unsigned long long min_hold_time_ns;
46 unsigned long long sum_hold_time_ns;
47 unsigned long long max_hold_time_ns;
48 unsigned long long lock_start_time_ns;
60 NdbMutex* NdbMutex_Create(
void);
61 NdbMutex* NdbMutex_CreateWithName(
const char *
name);
69 int NdbMutex_Init(NdbMutex* p_mutex);
70 int NdbMutex_InitWithName(NdbMutex* p_mutex,
const char *
name);
78 int NdbMutex_Destroy(NdbMutex* p_mutex);
86 int NdbMutex_Lock(NdbMutex* p_mutex);
94 int NdbMutex_Unlock(NdbMutex* p_mutex);
102 int NdbMutex_Trylock(NdbMutex* p_mutex);
116 void lock() { NdbMutex_Lock(m_mutex); }
117 void unlock(){ NdbMutex_Unlock(m_mutex);}
118 bool tryLock(){
return NdbMutex_Trylock(m_mutex) == 0;}
120 NdbMutex* getMutex() {
return m_mutex;};
128 Guard(NdbMutex *mtx) : m_mtx(mtx) { NdbMutex_Lock(m_mtx); };
129 Guard(
NdbLockable & l) : m_mtx(l.m_mutex) { NdbMutex_Lock(m_mtx); };
130 ~Guard() { NdbMutex_Unlock(m_mtx); };
138 Guard2(NdbMutex *mtx) : m_mtx(mtx) {
if (m_mtx) NdbMutex_Lock(m_mtx);};
139 Guard2(
NdbLockable & l) : m_mtx(l.m_mutex) {
if(m_mtx)NdbMutex_Lock(m_mtx);};
140 ~Guard2() {
if (m_mtx) NdbMutex_Unlock(m_mtx); };