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

changed directory structure as required by modularized-boost

This commit is contained in:
Oliver Kowalke
2012-12-09 15:22:59 +01:00
parent de1188faa2
commit 81e62e8962
77 changed files with 0 additions and 0 deletions

96
src/mutex.cpp Normal file
View File

@@ -0,0 +1,96 @@
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_FIBERS_SOURCE
#include <boost/fiber/mutex.hpp>
#include <boost/assert.hpp>
#include <boost/fiber/detail/scheduler.hpp>
#include <boost/fiber/operations.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace fibers {
mutex::mutex( bool checked) :
state_( UNLOCKED),
owner_(),
waiting_(),
checked_( checked)
{}
void
mutex::lock()
{
while ( UNLOCKED != state_)
{
if ( this_fiber::is_fiberized() )
{
waiting_.push_back(
detail::scheduler::instance().active() );
detail::scheduler::instance().wait();
}
else
detail::scheduler::instance().run();
}
state_ = LOCKED;
if ( this_fiber::is_fiberized() )
owner_ = detail::scheduler::instance().active()->get_id();
else
owner_ = detail::fiber_base::id();
}
bool
mutex::try_lock()
{
if ( LOCKED == state_) return false;
state_ = LOCKED;
if ( this_fiber::is_fiberized() )
owner_ = detail::scheduler::instance().active()->get_id();
else
owner_ = detail::fiber_base::id();
return true;
}
void
mutex::unlock()
{
if ( checked_)
{
if ( this_fiber::is_fiberized() )
{
if ( detail::scheduler::instance().active()->get_id() != owner_)
std::abort();
}
else if ( detail::fiber_base::id() != owner_)
std::abort();
}
if ( ! waiting_.empty() )
{
detail::fiber_base::ptr_t f;
do
{
f.swap( waiting_.front() );
waiting_.pop_front();
} while ( f->is_complete() );
if ( f)
detail::scheduler::instance().notify( f);
}
state_ = UNLOCKED;
owner_ = detail::fiber_base::id();
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif