34 #ifdef MUTEX_ERROR_CHECKS
35 #define MFM_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK
37 #define MFM_MUTEX_TYPE PTHREAD_MUTEX_NORMAL
48 pthread_mutex_t m_lock;
50 pthread_mutexattr_t m_attr;
57 pthread_cond_t m_virtualCond;
68 void CondWait(pthread_cond_t & condvar)
70 pthread_cond_wait(&condvar, &m_lock);
78 m_threadId = pthread_self();
103 pthread_cond_t m_condvar;
104 pthread_t m_threadIdOfWaiter;
106 virtual bool EvaluatePredicate() = 0;
110 pthread_cond_init(&m_condvar, NULL);
113 void WaitForCondition()
116 m_threadIdOfWaiter = m_mutex.m_threadId;
118 while (!EvaluatePredicate())
120 m_mutex.CondWait(m_condvar);
124 void SignalCondition()
127 pthread_cond_signal(&m_condvar);
142 if (pthread_mutexattr_init(&m_attr))
147 if (pthread_mutexattr_settype(&m_attr, MFM_MUTEX_TYPE))
152 if (pthread_mutex_init(&m_lock, &m_attr))
172 if (pthread_mutex_destroy(&m_lock))
177 if (pthread_mutexattr_destroy(&m_attr))
192 if (m_locked && pthread_equal(m_threadId, pthread_self()))
197 bool ret = !pthread_mutex_trylock(&m_lock);
201 m_threadId = pthread_self();
214 if (m_locked && pthread_equal(m_threadId, pthread_self()))
219 if (pthread_mutex_lock(&m_lock))
227 m_threadId = pthread_self();
245 if (!pthread_equal(m_threadId, pthread_self()))
264 pthread_mutex_unlock(&m_lock);
284 if (pthread_equal(m_threadId, pthread_self()))
292 void ReportMutexStatus(
int level) ;
301 bool IHoldThisLock()
const
303 return m_locked && pthread_equal(m_threadId, pthread_self());
bool TryLock()
Definition: Mutex.h:190
~Mutex()
Definition: Mutex.h:165
void AssertIHoldTheLock()
Definition: Mutex.h:238
bool IsLockedByAnother()
Definition: Mutex.h:277
void Lock()
Definition: Mutex.h:212
Mutex()
Definition: Mutex.h:137
void Unlock()
Definition: Mutex.h:258