10 #include <core/parallel/pthread_h.h> 11 #include <core/logging/assertions.hpp> 32 mutable pthread_mutex_t m_mut;
34 mutable volatile bool locked =
false;
38 int error = pthread_mutex_init(&m_mut, NULL);
39 ASSERT_MSG(!error,
"Mutex create error %d", error);
46 int error = pthread_mutex_init(&m_mut, NULL);
47 ASSERT_MSG(!error,
"Mutex create error %d", error);
51 int error = pthread_mutex_destroy(&m_mut);
54 std::cerr <<
"Mutex destroy error " << error << std::endl;
62 void operator=(
const mutex& m) {}
65 TURI_ATTRIBUTE_UNUSED_NDEBUG
int error = pthread_mutex_lock( &m_mut );
66 DASSERT_MSG(!error,
"Mutex lock error code: %d", error);
78 TURI_ATTRIBUTE_UNUSED_NDEBUG
int error = pthread_mutex_unlock(&m_mut);
79 DASSERT_MSG(!error,
"Mutex unlock error %d", error);
84 if (locked)
return false;
86 return pthread_mutex_trylock(&m_mut) == 0;
100 mutable pthread_mutex_t m_mut;
103 pthread_mutexattr_t attr;
104 int error = pthread_mutexattr_init(&attr);
106 error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
108 error = pthread_mutex_init(&m_mut, &attr);
110 pthread_mutexattr_destroy(&attr);
117 pthread_mutexattr_t attr;
118 int error = pthread_mutexattr_init(&attr);
120 error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
122 error = pthread_mutex_init(&m_mut, &attr);
124 pthread_mutexattr_destroy(&attr);
128 TURI_ATTRIBUTE_UNUSED_NDEBUG
int error = pthread_mutex_destroy(&m_mut);
137 TURI_ATTRIBUTE_UNUSED_NDEBUG
int error = pthread_mutex_lock(&m_mut);
143 TURI_ATTRIBUTE_UNUSED_NDEBUG
int error = pthread_mutex_unlock(&m_mut);
147 inline bool try_lock()
const {
return pthread_mutex_trylock(&m_mut) == 0; }
recursive_mutex()
constructs a mutex
bool try_lock() const
Non-blocking attempt to acquire a lock on the mutex.
recursive_mutex(const recursive_mutex &)
mutex()
constructs a mutex
void lock() const
Acquires a lock on the mutex.
void lock() const
Acquires a lock on the mutex.
void unlock() const
Releases a lock on the mutex.
void unlock() const
Releases a lock on the mutex.
#define ASSERT_TRUE(cond)
bool try_lock() const
Non-blocking attempt to acquire a lock on the mutex.
#define DASSERT_TRUE(cond)