From dcfb7be88d8c72d2bc619317bd28dbda653b99a2 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 13 Mar 2013 19:29:55 +0100 Subject: [PATCH] release lock in unlock() earlier --- src/mutex.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mutex.cpp b/src/mutex.cpp index 17e9ee71..44fd464a 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -55,11 +55,13 @@ mutex::lock() { // notifier for main-fiber n = detail::scheduler::instance().notifier(); + // store this fiber in order to be notified later unique_lock< detail::spinlock > lk( splk_); waiting_.push_back( n); - lk.unlock(); + + // wait until main-fiber gets notified while ( ! n->is_ready() ) { // run scheduler @@ -92,6 +94,7 @@ mutex::unlock() n.swap( waiting_.front() ); waiting_.pop_front(); } + lk.unlock(); state_ = UNLOCKED;