pipeline: revert change causing shutdown crash with DEBUG_THREADS

We actually need to leak this lock, because we need to call this at static destruction time, and we can't guarantee static destruction order.

This reverts commit afed80e83a5c033f03497bcf38353794e662eedf.
This commit is contained in:
rdb 2019-02-14 21:42:14 +01:00
parent 95f3e30d37
commit ff2fbe60ef
4 changed files with 52 additions and 36 deletions

View File

@ -29,7 +29,7 @@ using std::ostringstream;
ConditionVarDebug::
ConditionVarDebug(MutexDebug &mutex) :
_mutex(mutex),
_impl(mutex._global_lock)
_impl(*mutex.get_global_lock())
{
nassertv(!_mutex._allow_recursion);
}
@ -60,7 +60,7 @@ ConditionVarDebug::
*/
void ConditionVarDebug::
wait() {
_mutex._global_lock.lock();
_mutex._global_lock->lock();
Thread *current_thread = Thread::get_current_thread();
@ -69,7 +69,7 @@ wait() {
ostr << *current_thread << " attempted to wait on "
<< *this << " without holding " << _mutex;
nassert_raise(ostr.str());
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
return;
}
@ -95,7 +95,7 @@ wait() {
<< *current_thread << " awake on " << *this << "\n";
}
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
}
/**
@ -108,7 +108,7 @@ wait() {
*/
void ConditionVarDebug::
wait(double timeout) {
_mutex._global_lock.lock();
_mutex._global_lock->lock();
Thread *current_thread = Thread::get_current_thread();
@ -117,7 +117,7 @@ wait(double timeout) {
ostr << *current_thread << " attempted to wait on "
<< *this << " without holding " << _mutex;
nassert_raise(ostr.str());
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
return;
}
@ -144,7 +144,7 @@ wait(double timeout) {
<< *current_thread << " awake on " << *this << "\n";
}
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
}
/**
@ -158,7 +158,7 @@ wait(double timeout) {
*/
void ConditionVarDebug::
notify() {
_mutex._global_lock.lock();
_mutex._global_lock->lock();
/*
if (!_mutex.do_debug_is_locked()) {
@ -167,7 +167,7 @@ notify() {
ostr << *current_thread << " attempted to notify "
<< *this << " without holding " << _mutex;
nassert_raise(ostr.str());
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
return;
}
*/
@ -179,7 +179,7 @@ notify() {
}
_impl.notify();
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
}
/**
@ -190,7 +190,7 @@ notify() {
*/
void ConditionVarDebug::
notify_all() {
_mutex._global_lock.lock();
_mutex._global_lock->lock();
/*
if (!_mutex.do_debug_is_locked()) {
@ -199,7 +199,7 @@ notify_all() {
ostr << *current_thread << " attempted to notify "
<< *this << " without holding " << _mutex;
nassert_raise(ostr.str());
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
return;
}
*/
@ -211,7 +211,7 @@ notify_all() {
}
_impl.notify_all();
_mutex._global_lock.unlock();
_mutex._global_lock->unlock();
}
/**

View File

@ -18,9 +18,9 @@
INLINE void MutexDebug::
lock() {
TAU_PROFILE("void MutexDebug::acquire()", " ", TAU_USER);
_global_lock.lock();
_global_lock->lock();
((MutexDebug *)this)->do_lock(Thread::get_current_thread());
_global_lock.unlock();
_global_lock->unlock();
}
/**
@ -30,9 +30,9 @@ lock() {
INLINE bool MutexDebug::
try_lock() {
TAU_PROFILE("void MutexDebug::try_lock()", " ", TAU_USER);
_global_lock.lock();
_global_lock->lock();
bool acquired = ((MutexDebug *)this)->do_try_lock(Thread::get_current_thread());
_global_lock.unlock();
_global_lock->unlock();
return acquired;
}
@ -43,9 +43,9 @@ try_lock() {
INLINE void MutexDebug::
unlock() {
TAU_PROFILE("void MutexDebug::unlock()", " ", TAU_USER);
_global_lock.lock();
_global_lock->lock();
((MutexDebug *)this)->do_unlock();
_global_lock.unlock();
_global_lock->unlock();
}
/**
@ -62,9 +62,9 @@ INLINE void MutexDebug::
acquire(Thread *current_thread) const {
TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER);
nassertv(current_thread == Thread::get_current_thread());
_global_lock.lock();
_global_lock->lock();
((MutexDebug *)this)->do_lock(current_thread);
_global_lock.unlock();
_global_lock->unlock();
}
/**
@ -75,9 +75,9 @@ INLINE bool MutexDebug::
try_acquire(Thread *current_thread) const {
TAU_PROFILE("void MutexDebug::try_acquire(Thread *)", " ", TAU_USER);
nassertr(current_thread == Thread::get_current_thread(), false);
_global_lock.lock();
_global_lock->lock();
bool acquired = ((MutexDebug *)this)->do_try_lock(current_thread);
_global_lock.unlock();
_global_lock->unlock();
return acquired;
}
@ -114,9 +114,9 @@ elevate_lock() const {
INLINE void MutexDebug::
release() const {
TAU_PROFILE("void MutexDebug::release()", " ", TAU_USER);
_global_lock.lock();
_global_lock->lock();
((MutexDebug *)this)->do_unlock();
_global_lock.unlock();
_global_lock->unlock();
}
/**
@ -128,8 +128,22 @@ release() const {
INLINE bool MutexDebug::
debug_is_locked() const {
TAU_PROFILE("bool MutexDebug::debug_is_locked()", " ", TAU_USER);
_global_lock.lock();
_global_lock->lock();
bool is_locked = do_debug_is_locked();
_global_lock.unlock();
_global_lock->unlock();
return is_locked;
}
/**
* Ensures the global MutexImpl pointer has been created, and returns its
* pointer. Since this method is called by the MutexDebug constructor, any
* other (non-static) methods of MutexDebug may simply assume that the pointer
* has already been created.
*/
INLINE MutexTrueImpl *MutexDebug::
get_global_lock() {
if (_global_lock == nullptr) {
_global_lock = new MutexTrueImpl;
}
return _global_lock;
}

View File

@ -21,7 +21,7 @@ using std::ostream;
using std::ostringstream;
int MutexDebug::_pstats_count = 0;
MutexTrueImpl MutexDebug::_global_lock;
MutexTrueImpl *MutexDebug::_global_lock;
/**
*
@ -34,7 +34,7 @@ MutexDebug(const std::string &name, bool allow_recursion, bool lightweight) :
_locking_thread(nullptr),
_lock_count(0),
_deleted_name(nullptr),
_cvar_impl(_global_lock)
_cvar_impl(*get_global_lock())
{
#ifndef SIMPLE_THREADS
// If we're using real threads, there's no such thing as a lightweight
@ -87,12 +87,12 @@ output(ostream &out) const {
*/
void MutexDebug::
output_with_holder(ostream &out) const {
_global_lock.lock();
_global_lock->lock();
output(out);
if (_locking_thread != nullptr) {
out << " (held by " << *_locking_thread << ")\n";
}
_global_lock.unlock();
_global_lock->unlock();
}
/**
@ -102,9 +102,9 @@ output_with_holder(ostream &out) const {
*/
void MutexDebug::
increment_pstats() {
_global_lock.lock();
_global_lock->lock();
++_pstats_count;
_global_lock.unlock();
_global_lock->unlock();
}
/**
@ -113,9 +113,9 @@ increment_pstats() {
*/
void MutexDebug::
decrement_pstats() {
_global_lock.lock();
_global_lock->lock();
--_pstats_count;
_global_lock.unlock();
_global_lock->unlock();
}
/**

View File

@ -65,6 +65,8 @@ private:
void report_deadlock(Thread *current_thread);
private:
INLINE static MutexTrueImpl *get_global_lock();
bool _allow_recursion;
bool _lightweight;
Thread *_locking_thread;
@ -78,7 +80,7 @@ private:
ConditionVarImpl _cvar_impl;
static int _pstats_count;
static MutexTrueImpl _global_lock;
static MutexTrueImpl *_global_lock;
friend class ConditionVarDebug;
};