Rename thread mutex related debug flag name

It is used to detect multiple mutex lock, not just for pthread related
debugging.

Signed-off-by: OBATA Akio <obache@wizdas.com>
pull/21/head
OBATA Akio 3 months ago
parent cf0025c38a
commit 4f18860c33

@ -43,7 +43,7 @@
* define this if you want to protect mutexes against being locked twice by * define this if you want to protect mutexes against being locked twice by
* the same thread * the same thread
*/ */
#undef PTHREAD_DEBUG #undef PTHREAD_PREVENT_MULTI_LOCK
namespace Arts { namespace Arts {
@ -58,7 +58,7 @@ protected:
friend class ThreadCondition_impl; friend class ThreadCondition_impl;
pthread_mutex_t mutex; pthread_mutex_t mutex;
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
bool have_owner; bool have_owner;
pthread_t owner; pthread_t owner;
#endif #endif
@ -67,20 +67,20 @@ public:
Mutex_impl() Mutex_impl()
{ {
pthread_mutex_init(&mutex, 0); pthread_mutex_init(&mutex, 0);
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
have_owner = false; have_owner = false;
#endif #endif
} }
void lock() void lock()
{ {
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
pthread_t self = pthread_self(); pthread_t self = pthread_self();
arts_assert(!have_owner || !pthread_equal(owner, self)); arts_assert(!have_owner || !pthread_equal(owner, self));
#endif #endif
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
arts_assert(!have_owner); arts_assert(!have_owner);
have_owner = true; have_owner = true;
owner = self; owner = self;
@ -88,14 +88,14 @@ public:
} }
bool tryLock() bool tryLock()
{ {
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
pthread_t self = pthread_self(); pthread_t self = pthread_self();
arts_assert(!have_owner || !pthread_equal(owner, self)); arts_assert(!have_owner || !pthread_equal(owner, self));
#endif #endif
int result = pthread_mutex_trylock(&mutex); int result = pthread_mutex_trylock(&mutex);
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
if(result == 0) if(result == 0)
{ {
arts_assert(!have_owner); arts_assert(!have_owner);
@ -107,7 +107,7 @@ public:
} }
void unlock() void unlock()
{ {
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
arts_assert(have_owner && pthread_equal(owner, pthread_self())); arts_assert(have_owner && pthread_equal(owner, pthread_self()));
have_owner = false; have_owner = false;
#endif #endif
@ -137,7 +137,7 @@ public:
if(!have_owner || !pthread_equal(owner, self)) if(!have_owner || !pthread_equal(owner, self))
{ {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
arts_assert(count == 0); arts_assert(count == 0);
arts_assert(!have_owner); arts_assert(!have_owner);
#endif #endif
@ -155,7 +155,7 @@ public:
if(result != 0) if(result != 0)
return false; return false;
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
arts_assert(count == 0); arts_assert(count == 0);
arts_assert(!have_owner); arts_assert(!have_owner);
#endif #endif
@ -167,7 +167,7 @@ public:
} }
void unlock() void unlock()
{ {
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
arts_assert(have_owner && pthread_equal(owner, pthread_self())); arts_assert(have_owner && pthread_equal(owner, pthread_self()));
arts_assert(count > 0); arts_assert(count > 0);
#endif #endif
@ -234,7 +234,7 @@ public:
pthread_cond_broadcast(&cond); pthread_cond_broadcast(&cond);
} }
void wait(Arts::Mutex_impl *mutex) { void wait(Arts::Mutex_impl *mutex) {
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
pthread_t self = pthread_self(); pthread_t self = pthread_self();
arts_assert(((Mutex_impl *)mutex)->have_owner && pthread_equal(((Mutex_impl *)mutex)->owner, self)); arts_assert(((Mutex_impl *)mutex)->have_owner && pthread_equal(((Mutex_impl *)mutex)->owner, self));
((Mutex_impl *)mutex)->have_owner = false; ((Mutex_impl *)mutex)->have_owner = false;
@ -242,7 +242,7 @@ public:
pthread_cond_wait(&cond, &((Mutex_impl*)mutex)->mutex); pthread_cond_wait(&cond, &((Mutex_impl*)mutex)->mutex);
#ifdef PTHREAD_DEBUG #ifdef PTHREAD_PREVENT_MULTI_LOCK
arts_assert(!((Mutex_impl *)mutex)->have_owner); arts_assert(!((Mutex_impl *)mutex)->have_owner);
((Mutex_impl *)mutex)->have_owner = true; ((Mutex_impl *)mutex)->have_owner = true;
((Mutex_impl *)mutex)->owner = self; ((Mutex_impl *)mutex)->owner = self;

Loading…
Cancel
Save