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.
This commit is contained in:
rdb 2019-02-06 23:00:12 +01:00
parent 36dd8889e7
commit c4f52bfdfe
2 changed files with 12 additions and 6 deletions

View File

@ -165,9 +165,9 @@ void ConditionVarDebug::
notify() { notify() {
_mutex._global_lock->lock(); _mutex._global_lock->lock();
Thread *current_thread = Thread::get_current_thread(); /*
if (!_mutex.do_debug_is_locked()) { if (!_mutex.do_debug_is_locked()) {
Thread *current_thread = Thread::get_current_thread();
ostringstream ostr; ostringstream ostr;
ostr << *current_thread << " attempted to notify " ostr << *current_thread << " attempted to notify "
<< *this << " without holding " << _mutex; << *this << " without holding " << _mutex;
@ -175,8 +175,10 @@ notify() {
_mutex._global_lock->unlock(); _mutex._global_lock->unlock();
return; return;
} }
*/
if (thread_cat->is_spam()) { if (thread_cat->is_spam()) {
Thread *current_thread = Thread::get_current_thread();
thread_cat.spam() thread_cat.spam()
<< *current_thread << " notifying " << *this << "\n"; << *current_thread << " notifying " << *this << "\n";
} }

View File

@ -165,9 +165,9 @@ void ConditionVarFullDebug::
notify() { notify() {
_mutex._global_lock->lock(); _mutex._global_lock->lock();
Thread *current_thread = Thread::get_current_thread(); /*
if (!_mutex.do_debug_is_locked()) { if (!_mutex.do_debug_is_locked()) {
Thread *current_thread = Thread::get_current_thread();
ostringstream ostr; ostringstream ostr;
ostr << *current_thread << " attempted to notify " ostr << *current_thread << " attempted to notify "
<< *this << " without holding " << _mutex; << *this << " without holding " << _mutex;
@ -175,8 +175,10 @@ notify() {
_mutex._global_lock->unlock(); _mutex._global_lock->unlock();
return; return;
} }
*/
if (thread_cat->is_spam()) { if (thread_cat->is_spam()) {
Thread *current_thread = Thread::get_current_thread();
thread_cat.spam() thread_cat.spam()
<< *current_thread << " notifying " << *this << "\n"; << *current_thread << " notifying " << *this << "\n";
} }
@ -198,9 +200,9 @@ void ConditionVarFullDebug::
notify_all() { notify_all() {
_mutex._global_lock->lock(); _mutex._global_lock->lock();
Thread *current_thread = Thread::get_current_thread(); /*
if (!_mutex.do_debug_is_locked()) { if (!_mutex.do_debug_is_locked()) {
Thread *current_thread = Thread::get_current_thread();
ostringstream ostr; ostringstream ostr;
ostr << *current_thread << " attempted to notify " ostr << *current_thread << " attempted to notify "
<< *this << " without holding " << _mutex; << *this << " without holding " << _mutex;
@ -208,8 +210,10 @@ notify_all() {
_mutex._global_lock->unlock(); _mutex._global_lock->unlock();
return; return;
} }
*/
if (thread_cat->is_spam()) { if (thread_cat->is_spam()) {
Thread *current_thread = Thread::get_current_thread();
thread_cat.spam() thread_cat.spam()
<< *current_thread << " notifying all " << *this << "\n"; << *current_thread << " notifying all " << *this << "\n";
} }