2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-10 23:32:28 +00:00

use C++11

This commit is contained in:
Oliver Kowalke
2014-12-27 19:07:42 +01:00
parent ddbdd91ced
commit 2f19be6d67
126 changed files with 19488 additions and 21505 deletions

View File

@@ -6,10 +6,12 @@
#include "boost/fiber/recursive_mutex.hpp"
#include <algorithm>
#include <algorithm> // std::find()
#include <mutex> // std::unique_lock
#include <boost/assert.hpp>
#include "boost/fiber/fiber_manager.hpp"
#include "boost/fiber/interruption.hpp"
#include "boost/fiber/operations.hpp"
@@ -21,18 +23,14 @@ namespace boost {
namespace fibers {
bool
recursive_mutex::lock_if_unlocked_()
{
if ( UNLOCKED == state_)
{
state_ = LOCKED;
recursive_mutex::lock_if_unlocked_() {
if ( mutex_status::unlocked == state_) {
state_ = mutex_status::locked;
BOOST_ASSERT( ! owner_);
owner_ = this_fiber::get_id();
++count_;
return true;
}
else if ( this_fiber::get_id() == owner_)
{
} else if ( this_fiber::get_id() == owner_) {
++count_;
return true;
}
@@ -42,28 +40,27 @@ recursive_mutex::lock_if_unlocked_()
recursive_mutex::recursive_mutex() :
splk_(),
state_( UNLOCKED),
state_( mutex_status::unlocked),
owner_(),
count_( 0),
waiting_()
{}
waiting_() {
}
recursive_mutex::~recursive_mutex()
{
recursive_mutex::~recursive_mutex() {
BOOST_ASSERT( ! owner_);
BOOST_ASSERT( 0 == count_);
BOOST_ASSERT( waiting_.empty() );
}
void
recursive_mutex::lock()
{
detail::fiber_base * f( fm_active() );
for (;;)
{
unique_lock< detail::spinlock > lk( splk_);
recursive_mutex::lock() {
detail::fiber_handle f( fm_active() );
for (;;) {
std::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(), f) );
@@ -75,11 +72,12 @@ recursive_mutex::lock()
}
bool
recursive_mutex::try_lock()
{
unique_lock< detail::spinlock > lk( splk_);
recursive_mutex::try_lock() {
std::unique_lock< detail::spinlock > lk( splk_);
if ( lock_if_unlocked_() ) return true;
if ( lock_if_unlocked_() ) {
return true;
}
lk.unlock();
// let other fiber release the lock
@@ -88,25 +86,23 @@ recursive_mutex::try_lock()
}
void
recursive_mutex::unlock()
{
BOOST_ASSERT( LOCKED == state_);
recursive_mutex::unlock() {
BOOST_ASSERT( mutex_status::locked == state_);
BOOST_ASSERT( this_fiber::get_id() == owner_);
unique_lock< detail::spinlock > lk( splk_);
detail::fiber_base * f( 0);
if ( 0 == --count_)
{
if ( ! waiting_.empty() )
{
std::unique_lock< detail::spinlock > lk( splk_);
detail::fiber_handle f;
if ( 0 == --count_) {
if ( ! waiting_.empty() ) {
f = waiting_.front();
waiting_.pop_front();
}
owner_ = detail::fiber_base::id();
state_ = UNLOCKED;
state_ = mutex_status::unlocked;
lk.unlock();
if ( f) f->set_ready();
if ( f) {
f->set_ready();
}
}
}