From c4f52bfdfea15b9f36a5af00b0a82b25310268bb Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 6 Feb 2019 23:00:12 +0100 Subject: [PATCH] pipeline: don't require holding lock for ConditionVar.notify() As far as I know, none of the implementations strictly require this, and this may cause the waiting thread to wake up only for it to immediately have to wait for the lock again. This change brings our implementation closer to C++11 std::condition_variable semantics. --- panda/src/pipeline/conditionVarDebug.cxx | 6 ++++-- panda/src/pipeline/conditionVarFullDebug.cxx | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/panda/src/pipeline/conditionVarDebug.cxx b/panda/src/pipeline/conditionVarDebug.cxx index bbf9ce0d22..30a12695ad 100644 --- a/panda/src/pipeline/conditionVarDebug.cxx +++ b/panda/src/pipeline/conditionVarDebug.cxx @@ -165,9 +165,9 @@ void ConditionVarDebug:: notify() { _mutex._global_lock->lock(); - Thread *current_thread = Thread::get_current_thread(); - + /* if (!_mutex.do_debug_is_locked()) { + Thread *current_thread = Thread::get_current_thread(); ostringstream ostr; ostr << *current_thread << " attempted to notify " << *this << " without holding " << _mutex; @@ -175,8 +175,10 @@ notify() { _mutex._global_lock->unlock(); return; } + */ if (thread_cat->is_spam()) { + Thread *current_thread = Thread::get_current_thread(); thread_cat.spam() << *current_thread << " notifying " << *this << "\n"; } diff --git a/panda/src/pipeline/conditionVarFullDebug.cxx b/panda/src/pipeline/conditionVarFullDebug.cxx index 746991e79c..6b8b7feaa7 100644 --- a/panda/src/pipeline/conditionVarFullDebug.cxx +++ b/panda/src/pipeline/conditionVarFullDebug.cxx @@ -165,9 +165,9 @@ void ConditionVarFullDebug:: notify() { _mutex._global_lock->lock(); - Thread *current_thread = Thread::get_current_thread(); - + /* if (!_mutex.do_debug_is_locked()) { + Thread *current_thread = Thread::get_current_thread(); ostringstream ostr; ostr << *current_thread << " attempted to notify " << *this << " without holding " << _mutex; @@ -175,8 +175,10 @@ notify() { _mutex._global_lock->unlock(); return; } + */ if (thread_cat->is_spam()) { + Thread *current_thread = Thread::get_current_thread(); thread_cat.spam() << *current_thread << " notifying " << *this << "\n"; } @@ -198,9 +200,9 @@ void ConditionVarFullDebug:: notify_all() { _mutex._global_lock->lock(); - Thread *current_thread = Thread::get_current_thread(); - + /* if (!_mutex.do_debug_is_locked()) { + Thread *current_thread = Thread::get_current_thread(); ostringstream ostr; ostr << *current_thread << " attempted to notify " << *this << " without holding " << _mutex; @@ -208,8 +210,10 @@ notify_all() { _mutex._global_lock->unlock(); return; } + */ if (thread_cat->is_spam()) { + Thread *current_thread = Thread::get_current_thread(); thread_cat.spam() << *current_thread << " notifying all " << *this << "\n"; }