2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-01 20:42:08 +00:00

some fixes

This commit is contained in:
Oliver Kowalke
2014-09-24 19:18:44 +02:00
parent 244c539a2e
commit 7fb469cd10
39 changed files with 728 additions and 1139 deletions

View File

@@ -47,45 +47,19 @@ mutex::~mutex()
void
mutex::lock()
{
detail::fiber_base * n( fm_active() );
if ( 0 != n)
detail::fiber_base * f( fm_active() );
for (;;)
{
for (;;)
{
unique_lock< detail::spinlock > lk( splk_);
unique_lock< detail::spinlock > lk( splk_);
if ( lock_if_unlocked_() ) return;
if ( lock_if_unlocked_() ) return;
// store this fiber in order to be notified later
BOOST_ASSERT( waiting_.end() == std::find( waiting_.begin(), waiting_.end(), n) );
waiting_.push_back( n);
// store this fiber in order to be notified later
BOOST_ASSERT( waiting_.end() == std::find( waiting_.begin(), waiting_.end(), f) );
waiting_.push_back( f);
// suspend this fiber
fm_wait( lk);
}
}
else
{
// notification for main-fiber
detail::main_fiber mf;
n = & mf;
for (;;)
{
unique_lock< detail::spinlock > lk( splk_);
if ( lock_if_unlocked_() ) return;
// store this fiber in order to be notified later
BOOST_ASSERT( waiting_.end() == std::find( waiting_.begin(), waiting_.end(), n) );
waiting_.push_back( n);
lk.unlock();
// wait until main-fiber gets notified
while ( ! n->is_ready() )
// run scheduler
fm_run();
}
// suspend this fiber
fm_wait( lk);
}
}
@@ -109,16 +83,16 @@ mutex::unlock()
BOOST_ASSERT( this_fiber::get_id() == owner_);
unique_lock< detail::spinlock > lk( splk_);
detail::fiber_base * n = 0;
detail::fiber_base * f( 0);
if ( ! waiting_.empty() )
{
n = waiting_.front();
f = waiting_.front();
waiting_.pop_front();
}
owner_ = detail::worker_fiber::id();
owner_ = detail::fiber_base::id();
state_ = UNLOCKED;
lk.unlock();
if ( n) n->set_ready();
if ( f) f->set_ready();
}
}}