|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58490 - in sandbox/fiber: . boost/fiber boost/fiber/detail boost/fiber/spin libs/fiber/doc libs/fiber/examples libs/fiber/src libs/fiber/src/spin
From: oliver.kowalke_at_[hidden]
Date: 2009-12-22 10:37:31
Author: olli
Date: 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
New Revision: 58490
URL: http://svn.boost.org/trac/boost/changeset/58490
Log:
- removed atomic ops. by boost.atomic
- usage of thread_mive_t removed by boost.move
- some code cleanup (remove atomic ops for scheduler-affine synchr. primitives)
- documentatiion modified
Removed:
sandbox/fiber/boost/fiber/detail/atomic.hpp
sandbox/fiber/boost/fiber/detail/atomic_aix.hpp
sandbox/fiber/boost/fiber/detail/atomic_gcc.hpp
sandbox/fiber/boost/fiber/detail/atomic_gcc_ppc.hpp
sandbox/fiber/boost/fiber/detail/atomic_gcc_x86.hpp
sandbox/fiber/boost/fiber/detail/atomic_hpux.hpp
sandbox/fiber/boost/fiber/detail/atomic_interlocked.hpp
sandbox/fiber/boost/fiber/detail/atomic_interprocess.hpp
sandbox/fiber/boost/fiber/detail/atomic_solaris.hpp
sandbox/fiber/boost/fiber/detail/atomic_sync.hpp
sandbox/fiber/boost/fiber/detail/has_sync.hpp
Text files modified:
sandbox/fiber/boost/fiber/auto_reset_event.hpp | 18 ++---
sandbox/fiber/boost/fiber/barrier.hpp | 14 ++--
sandbox/fiber/boost/fiber/bounded_fifo.hpp | 89 +++++++++++++++-------------
sandbox/fiber/boost/fiber/condition.hpp | 44 +++++--------
sandbox/fiber/boost/fiber/count_down_event.hpp | 17 ++--
sandbox/fiber/boost/fiber/detail/info_base_posix.hpp | 2
sandbox/fiber/boost/fiber/detail/info_base_windows.hpp | 2
sandbox/fiber/boost/fiber/fiber.hpp | 49 +++++++--------
sandbox/fiber/boost/fiber/manual_reset_event.hpp | 24 +++----
sandbox/fiber/boost/fiber/mutex.hpp | 16 +++-
sandbox/fiber/boost/fiber/round_robin.hpp | 6
sandbox/fiber/boost/fiber/scheduler.hpp | 10 +-
sandbox/fiber/boost/fiber/spin/auto_reset_event.hpp | 10 +-
sandbox/fiber/boost/fiber/spin/barrier.hpp | 15 ++--
sandbox/fiber/boost/fiber/spin/bounded_fifo.hpp | 123 ++++++++++++++++++++++-----------------
sandbox/fiber/boost/fiber/spin/condition.hpp | 41 ++++++-------
sandbox/fiber/boost/fiber/spin/count_down_event.hpp | 14 ++-
sandbox/fiber/boost/fiber/spin/manual_reset_event.hpp | 16 ++--
sandbox/fiber/boost/fiber/spin/mutex.hpp | 12 +++
sandbox/fiber/boost/fiber/spin/unbounded_fifo.hpp | 77 +++++++++++++++---------
sandbox/fiber/boost/fiber/strategy.hpp | 57 ++++++++++--------
sandbox/fiber/boost/fiber/unbounded_fifo.hpp | 53 +++++++++-------
sandbox/fiber/change.log | 1
sandbox/fiber/libs/fiber/doc/fiber.qbk | 5
sandbox/fiber/libs/fiber/doc/fiber_ref.qbk | 3
sandbox/fiber/libs/fiber/doc/overview.qbk | 3
sandbox/fiber/libs/fiber/doc/todo.qbk | 4
sandbox/fiber/libs/fiber/examples/ping_pong.cpp | 2
sandbox/fiber/libs/fiber/src/auto_reset_event.cpp | 23 ++----
sandbox/fiber/libs/fiber/src/condition.cpp | 18 +----
sandbox/fiber/libs/fiber/src/count_down_event.cpp | 23 ++-----
sandbox/fiber/libs/fiber/src/fiber.cpp | 60 +++++++++----------
sandbox/fiber/libs/fiber/src/fiber_posix.cpp | 10 +-
sandbox/fiber/libs/fiber/src/fiber_windows.cpp | 12 +-
sandbox/fiber/libs/fiber/src/manual_reset_event.cpp | 31 +++++----
sandbox/fiber/libs/fiber/src/mutex.cpp | 23 +++---
sandbox/fiber/libs/fiber/src/round_robin.cpp | 6
sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp | 22 ++----
sandbox/fiber/libs/fiber/src/spin/barrier.cpp | 2
sandbox/fiber/libs/fiber/src/spin/condition.cpp | 20 +++--
sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp | 19 ++---
sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp | 29 +++-----
sandbox/fiber/libs/fiber/src/spin/mutex.cpp | 13 +--
sandbox/fiber/libs/fiber/src/strategy.cpp | 52 ++++++++--------
44 files changed, 553 insertions(+), 537 deletions(-)
Modified: sandbox/fiber/boost/fiber/auto_reset_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/auto_reset_event.hpp (original)
+++ sandbox/fiber/boost/fiber/auto_reset_event.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,6 @@
#ifndef BOOST_FIBERS_AUTO_RESET_EVENT_H
#define BOOST_FIBERS_AUTO_RESET_EVENT_H
-#include <boost/cstdint.hpp>
#include <boost/utility.hpp>
#include <boost/fiber/object/id.hpp>
@@ -25,23 +24,20 @@
class auto_reset_event : private noncopyable
{
private:
- enum state_t
+ enum state
{
- RESET = 0,
- SET
+ SET = 0,
+ RESET
};
- volatile uint32_t state_;
- object::id id_;
- strategy::ptr_t strategy_;
+ state state_;
+ object::id id_;
+ strategy::ptr strategy_;
public:
template< typename Strategy >
auto_reset_event( scheduler< Strategy > & sched, bool isset = false) :
- state_(
- isset ?
- static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) ),
+ state_( isset ? SET : RESET),
id_( * this),
strategy_( sched.strategy_)
{ strategy_->register_object( id_); }
Modified: sandbox/fiber/boost/fiber/barrier.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/barrier.hpp (original)
+++ sandbox/fiber/boost/fiber/barrier.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,9 +7,9 @@
#ifndef BOOST_FIBERS_BARRIER_H
#define BOOST_FIBERS_BARRIER_H
+#include <cstddef>
#include <stdexcept>
-#include <boost/cstdint.hpp>
#include <boost/utility.hpp>
#include <boost/fiber/condition.hpp>
@@ -22,15 +22,15 @@
class barrier : private noncopyable
{
private:
- uint32_t initial_;
- uint32_t current_;
- bool cycle_;
- mutex mtx_;
- condition cond_;
+ std::size_t initial_;
+ std::size_t current_;
+ bool cycle_;
+ mutex mtx_;
+ condition cond_;
public:
template< typename Strategy >
- barrier( scheduler< Strategy > & sched, uint32_t initial) :
+ barrier( scheduler< Strategy > & sched, std::size_t initial) :
initial_( initial),
current_( initial_),
cycle_( true),
Modified: sandbox/fiber/boost/fiber/bounded_fifo.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/bounded_fifo.hpp (original)
+++ sandbox/fiber/boost/fiber/bounded_fifo.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -10,7 +10,6 @@
#include <cstddef>
#include <stdexcept>
-#include <boost/cstdint.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/utility.hpp>
@@ -36,11 +35,11 @@
private:
struct node
{
- typedef intrusive_ptr< node > ptr_t;
+ typedef intrusive_ptr< node > ptr;
- uint32_t use_count;
- value_type va;
- ptr_t next;
+ std::size_t use_count;
+ value_type va;
+ ptr next;
node() :
use_count( 0),
@@ -55,43 +54,49 @@
{ if ( --p->use_count == 0) delete p; }
};
- uint32_t state_;
- uint32_t count_;
- typename node::ptr_t head_;
- mutex head_mtx_;
- typename node::ptr_t tail_;
- mutex tail_mtx_;
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ state state_;
+ std::size_t count_;
+ typename node::ptr head_;
+ mutable mutex head_mtx_;
+ typename node::ptr tail_;
+ mutable mutex tail_mtx_;
condition not_empty_cond_;
condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
- uint32_t use_count_;
+ std::size_t hwm_;
+ std::size_t lwm_;
+ std::size_t use_count_;
bool active_() const
- { return 0 == state_; }
+ { return ACTIVE == state_; }
void deactivate_()
- { ++state_; }
+ { state_ = DEACTIVE; }
- uint32_t size_()
+ std::size_t size_() const
{ return count_; }
- bool empty_()
+ bool empty_() const
{ return head_ == get_tail_(); }
- bool full_()
+ bool full_() const
{ return size_() >= hwm_; }
- typename node::ptr_t get_tail_()
+ typename node::ptr get_tail_() const
{
mutex::scoped_lock lk( tail_mtx_);
- typename node::ptr_t tmp = tail_;
+ typename node::ptr tmp = tail_;
return tmp;
}
- typename node::ptr_t pop_head_()
+ typename node::ptr pop_head_()
{
- typename node::ptr_t old_head = head_;
+ typename node::ptr old_head = head_;
head_ = old_head->next;
--count_;
return old_head;
@@ -101,11 +106,11 @@
template< typename Strategy >
impl(
scheduler< Strategy > & sched,
- std::size_t const& hwm,
- std::size_t const& lwm) :
- state_( 0),
+ std::size_t hwm,
+ std::size_t lwm) :
+ state_( ACTIVE),
count_( 0),
- head_( new node),
+ head_( new node() ),
head_mtx_( sched),
tail_( head_),
tail_mtx_( sched),
@@ -122,10 +127,10 @@
template< typename Strategy >
impl(
scheduler< Strategy > & sched,
- std::size_t const& wm) :
- state_( 0),
+ std::size_t wm) :
+ state_( ACTIVE),
count_( 0),
- head_( new node),
+ head_( new node() ),
head_mtx_( sched),
tail_( head_),
tail_mtx_( sched),
@@ -140,30 +145,30 @@
{
if ( hwm < lwm_)
throw invalid_watermark();
- std::size_t tmp( hwm_);
+ unsigned int tmp( hwm_);
hwm_ = hwm;
if ( hwm_ > tmp) not_full_cond_.notify_one();
}
- std::size_t upper_bound()
+ std::size_t upper_bound() const
{ return hwm_; }
void lower_bound( std::size_t lwm)
{
if ( lwm > hwm_ )
throw invalid_watermark();
- std::size_t tmp( lwm_);
+ unsigned int tmp( lwm_);
lwm_ = lwm;
if ( lwm_ > tmp) not_full_cond_.notify_one();
}
- std::size_t lower_bound()
+ std::size_t lower_bound() const
{ return lwm_; }
void deactivate()
{ deactivate_(); }
- bool empty()
+ bool empty() const
{
mutex::scoped_lock lk( head_mtx_);
return empty_();
@@ -171,7 +176,7 @@
void put( T const& t)
{
- typename node::ptr_t new_node( new node);
+ typename node::ptr new_node( new node() );
{
mutex::scoped_lock lk( tail_mtx_);
@@ -256,34 +261,34 @@
template< typename Strategy >
bounded_fifo(
scheduler< Strategy > & sched,
- std::size_t const& hwm,
- std::size_t const& lwm) :
+ unsigned int hwm,
+ unsigned int lwm) :
impl_( new impl( sched, hwm, lwm) )
{}
template< typename Strategy >
bounded_fifo(
scheduler< Strategy > & sched,
- std::size_t const& wm) :
+ unsigned int wm) :
impl_( new impl( sched, wm) )
{}
void upper_bound( std::size_t hwm)
{ impl_->upper_bound( hwm); }
- std::size_t upper_bound()
+ std::size_t upper_bound() const
{ return impl_->upper_bound(); }
void lower_bound( std::size_t lwm)
{ impl_->lower_bound( lwm); }
- std::size_t lower_bound()
+ std::size_t lower_bound() const
{ return impl_->lower_bound(); }
void deactivate()
{ impl_->deactivate(); }
- bool empty()
+ bool empty() const
{ return impl_->empty(); }
void put( T const& t)
Modified: sandbox/fiber/boost/fiber/condition.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/condition.hpp (original)
+++ sandbox/fiber/boost/fiber/condition.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -9,12 +9,12 @@
#ifndef BOOST_FIBERS_CONDITION_H
#define BOOST_FIBERS_CONDITION_H
+#include <cstddef>
+
#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
#include <boost/utility.hpp>
#include <boost/thread/locks.hpp>
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/exceptions.hpp>
#include <boost/fiber/mutex.hpp>
#include <boost/fiber/object/id.hpp>
@@ -32,24 +32,24 @@
class condition : private noncopyable
{
private:
- enum command_t
+ enum command
{
SLEEPING = 0,
NOTIFY_ONE,
NOTIFY_ALL
};
- volatile uint32_t cmd_;
- volatile uint32_t waiters_;
- mutex enter_mtx_;
- mutex check_mtx_;
- object::id id_;
- strategy::ptr_t strategy_;
+ command cmd_;
+ std::size_t waiters_;
+ mutex enter_mtx_;
+ mutex check_mtx_;
+ object::id id_;
+ strategy::ptr strategy_;
public:
template< typename Strategy >
condition( scheduler< Strategy > & sched) :
- cmd_( static_cast< uint32_t >( SLEEPING) ),
+ cmd_( SLEEPING),
waiters_( 0),
enter_mtx_( sched),
check_mtx_( sched),
@@ -86,41 +86,33 @@
{
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
+ ++waiters_;
lt.unlock();
}
bool unlock_enter_mtx = false;
for (;;)
{
- while ( static_cast< uint32_t >( SLEEPING) == detail::atomic_load( & cmd_) )
+ while ( SLEEPING == cmd_)
strategy_->wait_for_object( id_);
mutex::scoped_lock lk( check_mtx_);
BOOST_ASSERT( lk);
- uint32_t expected = static_cast< uint32_t >( NOTIFY_ONE);
- detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- if ( static_cast< uint32_t >( SLEEPING) == expected)
+ if ( SLEEPING == cmd_)
continue;
- else if ( static_cast< uint32_t >( NOTIFY_ONE) == expected)
+ else if ( NOTIFY_ONE == cmd_)
{
+ cmd_ = SLEEPING;
unlock_enter_mtx = true;
- detail::atomic_fetch_sub( & waiters_, 1);
+ --waiters_;
break;
}
else
{
- unlock_enter_mtx = 1 == detail::atomic_fetch_sub( & waiters_, 1);
+ unlock_enter_mtx = 0 == --waiters_;
if ( unlock_enter_mtx)
- {
- expected = static_cast< uint32_t >( NOTIFY_ALL);
- detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- }
+ cmd_ = SLEEPING;
break;
}
}
Modified: sandbox/fiber/boost/fiber/count_down_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/count_down_event.hpp (original)
+++ sandbox/fiber/boost/fiber/count_down_event.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,8 @@
#ifndef BOOST_FIBERS_COUNT_DOWN_EVENT_H
#define BOOST_FIBERS_COUNT_DOWN_EVENT_H
-#include <boost/cstdint.hpp>
+#include <cstddef>
+
#include <boost/utility.hpp>
#include <boost/fiber/object/id.hpp>
@@ -26,14 +27,14 @@
class count_down_event : private noncopyable
{
private:
- uint32_t initial_;
- volatile uint32_t current_;
- object::id id_;
- strategy::ptr_t strategy_;
+ std::size_t initial_;
+ std::size_t current_;
+ object::id id_;
+ strategy::ptr strategy_;
public:
template< typename Strategy >
- count_down_event( scheduler< Strategy > & sched, uint32_t initial) :
+ count_down_event( scheduler< Strategy > & sched, std::size_t initial) :
initial_( initial),
current_( initial_),
id_( * this),
@@ -42,9 +43,9 @@
~count_down_event();
- uint32_t initial() const;
+ std::size_t initial() const;
- uint32_t current() const;
+ std::size_t current() const;
bool is_set() const;
Deleted: sandbox/fiber/boost/fiber/detail/atomic.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,48 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBER_DETAIL_ATOMIC_H
-#define BOOST_FIBER_DETAIL_ATOMIC_H
-
-// MS compatible compilers support #pragma once
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#include <boost/config.hpp>
-
-#include <boost/fiber/detail/has_sync.hpp>
-
-# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-#include <boost/fiber/detail/atomic_interlocked.hpp>
-
-# elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
-#include <boost/fiber/detail/atomic_gcc_x86.hpp>
-
-# elif defined( __GNUC__ ) && ( defined(__PPC__) || defined(__ppc__) )
-#include <boost/fiber/detail/atomic_gcc_ppc.hpp>
-
-# elif defined( BOOST_fiber_HAS_SYNC)
-#include <boost/fiber/detail/atomic_sync.hpp>
-
-# elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
-#include <boost/fiber/detail/atomic_gcc.hpp>
-
-# elif defined(__IBMCPP__) || defined(_AIX)
-#include <boost/fiber/detail/atomic_aix.hpp>
-
-# elif defined(__hpux)
-#include <boost/fiber/detail/atomic_hpux.hpp>
-
-# elif defined(sun) || defined(__sun)
-#include <boost/fiber/detail/atomic_solaris.hpp>
-
-# else
-#include <boost/fiber/detail/atomic_interprocess.hpp>
-
-# endif
-
-#endif // BOOST_FIBER_DETAIL_ATOMIC_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_aix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_aix.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,55 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_AIX_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_AIX_H
-
-extern "C"
-{
-#include <sys/atomic_ops.h>
-}
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{ return ::compare_and_swap( object, expected, desired); }
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::fetch_and_add( object, 1);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::fetch_and_add( object, -1);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_AIX_H
-
Deleted: sandbox/fiber/boost/fiber/detail/atomic_gcc.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_gcc.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,76 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_GCC_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_GCC_H
-
-// based on boost/smart_ptr/detail/atomic_count_gcc.hpp
-
-# if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
-#include <ext/atomicity.h>
-# else
-#include <bits/atomicity.h>
-# endif
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-#if defined(__GLIBCXX__) // g++ 3.4+
-
-using __gnu_cxx::__atomic_add;
-using __gnu_cxx::__exchange_and_add;
-
-#endif
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- // inline asm xchg for i386 || x86_64?
- * object = desired;
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = interprocess::detail::atomic_cas32( object, desired, * expected);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __exchange_and_add( ( _Atomic_word volatile *) object, 1) + 1;
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __exchange_and_add( ( _Atomic_word volatile *) object, -1) - 1;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_GCC_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_gcc_ppc.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_gcc_ppc.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,113 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_GCC_PPC_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_GCC_PPC_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- uint32_t r;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0, 0, %2 \n\t"
- "stwcx. %1, 0, %2 \n\t"
- "bne- 1b" :
- "=r" ( r) :
- "r" ( desired), "r" ( object)
- );
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = * expected;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0,0,%1\n\t"
- "cmpw %0,%3\n\t"
- "bne- 1f\n\t"
- "stwcx. %2,0,%1\n\t"
- "bne- 0b\n\t"
- "1:"
- : "=&r"( * expected)
- : "b" ( object), "r" ( desired), "r" ( * expected)
- : "memory", "cc"
- );
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- int object_ = static_cast< int >( object);
- int operand_ = static_cast< int >( operand);
- int r, t;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0,0,%2\n\t"
- "add %1,%0,%3\n\t"
- "stwcx. %1,0,%2\n\t"
- "bne- 0b"
- : "=&r" ( r), "=&r" ( t)
- : "b" ( object_), "r" ( operand_)
- : "memory", "cc"
- );
-
- return r;
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- int object_ = static_cast< int >( object);
- int operand_ = static_cast< int >( -1 * operand);
- int r;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0,0,%2\n\t"
- "add %1,%0,%3\n\t"
- "stwcx. %1,0,%2\n\t"
- "bne- 0b"
- : "=&r" ( r), "=&r" ( t)
- : "b" ( object_), "r" ( operand_)
- : "memory", "cc"
- );
-
- return r;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_GCC_PPC_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_gcc_x86.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_gcc_x86.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,90 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_GCC_X86_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_GCC_X86_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- __asm__ __volatile__
- (
- "xchg %0, %1" :
- "+r" ( desired), "+m" ( * object)
- );
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = * expected;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "cmpxchg %3, %1"
- : "=a" ( * expected), "=m" ( * object)
- : "a" ( prev), "r" ( desired)
- : "memory", "cc"
- );
-
- return prev == * expected;
-}
-
-inline
-long atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- int operand_ = static_cast< int >( operand);
- int r;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "xadd %1, %0" :
- "+m"( * object), "=r"( r):
- "1"( operand_):
- "memory", "cc"
- );
-
- return r;
-}
-
-inline
-long atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- int operand_ = static_cast< int >( -1 * operand);
- int r;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "xadd %1, %0":
- "+m"( * object), "=r"( r ):
- "1"( operand_):
- "memory", "cc"
- );
-
- return r;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_GCC_X86_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_hpux.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_hpux.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,61 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_HPUX_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_HPUX_H
-
-extern "C"
-{
-#include <atomic.h>
-}
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = ::atomic_cas_32( object, * expected, desired);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_inc( object);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_dec( object);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_HPUX_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_interlocked.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_interlocked.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,65 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_INTERLOCKED_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_INTERLOCKED_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/detail/interlocked.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- BOOST_INTERLOCKED_EXCHANGE(
- reinterpret_cast< long volatile * >( object),
- static_cast< long >( desired) );
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = BOOST_INTERLOCKED_COMPARE_EXCHANGE(
- reinterpret_cast< long volatile * >( object),
- static_cast< long >( desired),
- static_cast< long >( * expected) );
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return BOOST_INTERLOCKED_INCREMENT( reinterpret_cast< long volatile * >( object) ) - 1;
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return BOOST_INTERLOCKED_DECREMENT( reinterpret_cast< long volatile * >( object) ) + 1;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_INTERLOCKED_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_interprocess.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_interprocess.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,58 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_INTERPROCESS_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_INTERPROCESS_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ interprocess::detail::atomic_write32( object, desired); }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = interprocess::detail::atomic_cas32( object, desired, * expected);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-unsigned int atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return interprocess::detail::atomic_inc32( object);
-}
-
-inline
-unsigned int atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return interprocess::detail::atomic_dec32( object);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_INTERPROCESS_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_solaris.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_solaris.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,62 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_SOLARIS_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_SOLARIS_H
-
-extern "C"
-{
-#include <atomic.h>
-}
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = ::atomic_cas_32( object, * expected, desired);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_inc_32( object);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_dec_32( object);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_SOLARIS_H
Deleted: sandbox/fiber/boost/fiber/detail/atomic_sync.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/atomic_sync.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,66 +0,0 @@
-
-// 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)
-
-#ifndef BOOST_FIBERS_DETAIL_ATOMIC_SYNC_H
-#define BOOST_FIBERS_DETAIL_ATOMIC_SYNC_H
-
-// based on boost/smart_ptr/detail/atomic_count_gc.hpp
-
-# if defined( __ia64__ ) && defined( __INTEL_COMPILER )
-extern "C"
-{
-#include<ia64intrin.h>
-}
-# endif
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = __sync_val_compare_and_swap( object, * expected, desired);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __sync_fetch_and_add( object, 1);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __sync_fetch_and_add( object, -1);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_ATOMIC_SYNC_H
Deleted: sandbox/fiber/boost/fiber/detail/has_sync.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/has_sync.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
+++ (empty file)
@@ -1,49 +0,0 @@
-#ifndef BOOST_FIBERS_DETAIL_HAS_SYNC_H
-#define BOOST_FIBERS_DETAIL_HAS_SYNC_H
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-//
-// based on boost/smart_ptr/detail/sp_has_sync.hpp
-//
-// Copyright (c) 2008, 2009 Peter Dimov
-//
-// 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)
-//
-// Defines the BOOST_SP_HAS_SYNC macro if the __sync_* intrinsics
-// are available.
-//
-
-#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
-
-#define BOOST_FIBER_HAS_SYNC
-
-#if defined( __arm__ ) || defined( __armel__ )
-#undef BOOST_FIBER_HAS_SYNC
-#endif
-
-#if defined( __hppa ) || defined( __hppa__ )
-#undef BOOST_FIBER_HAS_SYNC
-#endif
-
-#if defined( __m68k__ )
-#undef BOOST_FIBER_HAS_SYNC
-#endif
-
-#if defined( __sparc__ )
-#undef BOOST_FIBER_HAS_SYNC
-#endif
-
-#if defined( __INTEL_COMPILER ) && !defined( __ia64__ )
-#undef BOOST_FIBER_HAS_SYNC
-#endif
-
-#endif // __GNUC__ * 100 + __GNUC_MINOR__ >= 401
-
-#endif // BOOST_FIBERS_DETAIL_HAS_SYNC_H
Modified: sandbox/fiber/boost/fiber/detail/info_base_posix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/info_base_posix.hpp (original)
+++ sandbox/fiber/boost/fiber/detail/info_base_posix.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -36,7 +36,7 @@
struct BOOST_FIBER_DECL info_base
{
- typedef intrusive_ptr< info_base > ptr_t;
+ typedef intrusive_ptr< info_base > ptr;
typedef function< void() > callable_t;
typedef std::stack< callable_t > callable_stack_t;
Modified: sandbox/fiber/boost/fiber/detail/info_base_windows.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/info_base_windows.hpp (original)
+++ sandbox/fiber/boost/fiber/detail/info_base_windows.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -40,7 +40,7 @@
struct BOOST_FIBER_DECL info_base
{
- typedef intrusive_ptr< info_base > ptr_t;
+ typedef intrusive_ptr< info_base > ptr;
typedef function< void() > callable_t;
typedef std::stack< callable_t > callable_stack_t;
Modified: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/fiber.hpp (original)
+++ sandbox/fiber/boost/fiber/fiber.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,6 @@
#ifndef BOOST_FIBERS_FIBER_H
#define BOOST_FIBERS_FIBER_H
-#include <cstddef>
#include <iostream>
#include <boost/bind.hpp>
@@ -45,33 +44,31 @@
static void convert_thread_to_fiber();
static void convert_fiber_to_thread();
- static std::size_t default_stacksize;
+ static unsigned int default_stacksize;
BOOST_COPYABLE_AND_MOVABLE( fiber);
- detail::info_base::ptr_t info_base_;
+ detail::info_base::ptr info_;
- explicit fiber( detail::info_base::ptr_t);
+ explicit fiber( detail::info_base::ptr);
void init_();
- detail::info_base::ptr_t info_() const;
-
void switch_to_( fiber &);
template< typename Fn >
- static detail::info_base::ptr_t make_info_(
- std::size_t stack_size, Fn fn)
+ static detail::info_base::ptr make_info_(
+ unsigned int stack_size, Fn fn)
{
- return detail::info_base::ptr_t(
+ return detail::info_base::ptr(
new detail::info< Fn >( fn, stack_size) );
}
template< typename Fn >
- static detail::info_base::ptr_t make_info_(
- std::size_t stack_size, BOOST_RV_REF( Fn) fn)
+ static detail::info_base::ptr make_info_(
+ unsigned int stack_size, BOOST_RV_REF( Fn) fn)
{
- return detail::info_base::ptr_t(
+ return detail::info_base::ptr(
new detail::info< Fn >( fn, stack_size) );
}
@@ -82,12 +79,12 @@
template< typename Fn >
explicit fiber( Fn fn) :
- info_base_( make_info_( default_stacksize, fn) )
+ info_( make_info_( default_stacksize, fn) )
{ init_(); }
template< typename Fn >
- explicit fiber( std::size_t stack_size, Fn fn) :
- info_base_( make_info_( stack_size, fn) )
+ explicit fiber( unsigned int stack_size, Fn fn) :
+ info_( make_info_( stack_size, fn) )
{ init_(); }
#define BOOST_FIBER_ARG(z, n, unused) \
@@ -97,15 +94,15 @@
#define BOOST_FIBER_FIBER_CTOR(z, n, unused) \
template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
fiber( Fn fn, BOOST_ENUM_FIBER_ARGS(n)) : \
- info_base_( \
+ info_( \
make_info_( \
default_stacksize, \
boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a)) ) ) \
{ init_(); } \
\
template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
- fiber( std::size_t stack_size, Fn fn, BOOST_ENUM_FIBER_ARGS(n)) : \
- info_base_( \
+ fiber( unsigned int stack_size, Fn fn, BOOST_ENUM_FIBER_ARGS(n)) : \
+ info_( \
make_info_( \
stack_size, \
boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a)) ) ) \
@@ -121,12 +118,12 @@
template< typename Fn >
explicit fiber( BOOST_RV_REF( Fn) fn) :
- info_base_( make_info_( default_stacksize, fn) )
+ info_( make_info_( default_stacksize, fn) )
{ init_(); }
template< typename Fn >
- explicit fiber( std::size_t stack_size, BOOST_RV_REF( Fn) fn) :
- info_base_( make_info_( stack_size, fn) )
+ explicit fiber( unsigned int stack_size, BOOST_RV_REF( Fn) fn) :
+ info_( make_info_( stack_size, fn) )
{ init_(); }
fiber( fiber const& other);
@@ -137,7 +134,7 @@
fiber & operator=( BOOST_RV_REF( fiber) other);
- typedef detail::info_base::ptr_t::unspecified_bool_type unspecified_bool_type;
+ typedef detail::info_base::ptr::unspecified_bool_type unspecified_bool_type;
operator unspecified_bool_type() const;
@@ -170,9 +167,9 @@
private:
friend class fiber;
- detail::info_base::ptr_t info_;
+ detail::info_base::ptr info_;
- explicit id( detail::info_base::ptr_t info) :
+ explicit id( detail::info_base::ptr info) :
info_( info)
{}
@@ -215,7 +212,7 @@
{ return fiber( fn); }
template< typename Fn >
-fiber make_fiber( std::size_t stack_size, Fn fn)
+fiber make_fiber( unsigned int stack_size, Fn fn)
{ return fiber( stack_size, fn); }
#define BOOST_FIBER_MAKE_FIBER_FUNCTION(z, n, unused) \
@@ -224,7 +221,7 @@
{ return fiber( fn, BOOST_PP_ENUM_PARAMS(n, a) ); } \
\
template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
-fiber make_fiber( std::size_t stack_size, Fn fn, BOOST_ENUM_FIBER_ARGS(n)) \
+fiber make_fiber( unsigned int stack_size, Fn fn, BOOST_ENUM_FIBER_ARGS(n)) \
{ return fiber( stack_size, fn, BOOST_PP_ENUM_PARAMS(n, a) ); }
BOOST_PP_REPEAT_FROM_TO( 1, BOOST_FIBER_MAX_ARITY, BOOST_FIBER_MAKE_FIBER_FUNCTION, ~)
Modified: sandbox/fiber/boost/fiber/manual_reset_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/manual_reset_event.hpp (original)
+++ sandbox/fiber/boost/fiber/manual_reset_event.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,8 @@
#ifndef BOOST_FIBERS_MANUAL_RESET_EVENT_H
#define BOOST_FIBERS_MANUAL_RESET_EVENT_H
-#include <boost/cstdint.hpp>
+#include <cstddef>
+
#include <boost/utility.hpp>
#include <boost/fiber/object/id.hpp>
@@ -26,25 +27,22 @@
class manual_reset_event : private noncopyable
{
private:
- enum state_t
+ enum state
{
- RESET = 0,
- SET
+ SET = 0,
+ RESET
};
- volatile uint32_t state_;
- volatile uint32_t waiters_;
- mutex enter_mtx_;
- object::id id_;
- strategy::ptr_t strategy_;
+ state state_;
+ std::size_t waiters_;
+ mutex enter_mtx_;
+ object::id id_;
+ strategy::ptr strategy_;
public:
template< typename Strategy >
manual_reset_event( scheduler< Strategy > & sched, bool isset = false) :
- state_(
- isset ?
- static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) ),
+ state_( isset ? SET : RESET),
waiters_( 0),
enter_mtx_( sched),
id_( * this),
Modified: sandbox/fiber/boost/fiber/mutex.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/mutex.hpp (original)
+++ sandbox/fiber/boost/fiber/mutex.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -9,10 +9,10 @@
#ifndef BOOST_FIBERS_MUTEX_H
#define BOOST_FIBERS_MUTEX_H
-#include <boost/cstdint.hpp>
#include <boost/thread/locks.hpp>
#include <boost/utility.hpp>
+#include <boost/fiber/fiber.hpp>
#include <boost/fiber/object/id.hpp>
#include <boost/fiber/scheduler.hpp>
#include <boost/fiber/strategy.hpp>
@@ -28,16 +28,22 @@
class mutex : private noncopyable
{
private:
- volatile uint32_t state_;
- object::id id_;
- strategy::ptr_t strategy_;
+ enum state
+ {
+ LOCKED = 0,
+ UNLOCKED
+ };
+
+ state state_;
+ object::id id_;
+ strategy::ptr strategy_;
public:
typedef unique_lock< mutex > scoped_lock;
template< typename Strategy >
mutex( scheduler< Strategy > & sched) :
- state_( 0),
+ state_( UNLOCKED),
id_( * this),
strategy_( sched.strategy_)
{ strategy_->register_object( id_); }
Modified: sandbox/fiber/boost/fiber/round_robin.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/round_robin.hpp (original)
+++ sandbox/fiber/boost/fiber/round_robin.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -97,11 +97,11 @@
bool run();
- bool empty();
+ bool empty() const;
- std::size_t size();
+ std::size_t size() const;
- std::size_t ready();
+ std::size_t ready() const;
};
}}
Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -62,13 +62,13 @@
bool run()
{ return strategy_->run(); }
- bool empty()
+ bool empty() const
{ return strategy_->empty(); }
- std::size_t size()
+ std::size_t size() const
{ return strategy_->size(); }
- std::size_t ready()
+ std::size_t ready() const
{ return strategy_->ready(); }
void submit_fiber( fiber f)
@@ -94,9 +94,9 @@
{
if ( ! f) throw fiber_moved();
- strategy * st( f.info_()->st);
+ strategy * st( f.info_->st);
if ( ! st) throw fiber_error("fiber not attached");
- strategy_->migrate( f.info_()->st->release( f.get_id() ) );
+ strategy_->migrate( f.info_->st->release( f.get_id() ) );
}
template< typename OtherStrategy >
Modified: sandbox/fiber/boost/fiber/spin/auto_reset_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/auto_reset_event.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/auto_reset_event.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,7 @@
#ifndef BOOST_FIBERS_SPIN_AUTO_RESET_EVENT_H
#define BOOST_FIBERS_SPIN_AUTO_RESET_EVENT_H
-#include <boost/cstdint.hpp>
+#include <boost/atomic.hpp>
#include <boost/utility.hpp>
namespace boost {
@@ -17,13 +17,13 @@
class auto_reset_event : private noncopyable
{
private:
- enum state_t
+ enum state
{
- RESET = 0,
- SET
+ SET = 0,
+ RESET
};
- volatile uint32_t state_;
+ atomic< state > state_;
public:
explicit auto_reset_event( bool = false);
Modified: sandbox/fiber/boost/fiber/spin/barrier.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/barrier.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/barrier.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,8 @@
#ifndef BOOST_FIBERS_SPIN_BARRIER_H
#define BOOST_FIBERS_SPIN_BARRIER_H
-#include <boost/cstdint.hpp>
+#include <cstddef>
+
#include <boost/utility.hpp>
#include <boost/fiber/spin/condition.hpp>
@@ -20,14 +21,14 @@
class barrier : private noncopyable
{
private:
- uint32_t initial_;
- uint32_t current_;
- bool cycle_;
- mutex mtx_;
- condition cond_;
+ std::size_t initial_;
+ std::size_t current_;
+ bool cycle_;
+ mutex mtx_;
+ condition cond_;
public:
- barrier( uint32_t);
+ barrier( std::size_t);
bool wait();
};
Modified: sandbox/fiber/boost/fiber/spin/bounded_fifo.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/bounded_fifo.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/bounded_fifo.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -10,12 +10,11 @@
#include <cstddef>
#include <stdexcept>
-#include <boost/cstdint.hpp>
+#include <boost/atomic.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/utility.hpp>
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/exceptions.hpp>
#include <boost/fiber/spin/condition.hpp>
#include <boost/fiber/spin/mutex.hpp>
@@ -38,11 +37,11 @@
private:
struct node
{
- typedef intrusive_ptr< node > ptr_t;
+ typedef intrusive_ptr< node > ptr;
- uint32_t use_count;
- value_type va;
- ptr_t next;
+ atomic< std::size_t > use_count;
+ value_type va;
+ ptr next;
node() :
use_count( 0),
@@ -51,61 +50,73 @@
{}
inline friend void intrusive_ptr_add_ref( node * p)
- { ++p->use_count; }
+ { p->use_count.fetch_add( 1, memory_order_relaxed); }
inline friend void intrusive_ptr_release( node * p)
- { if ( --p->use_count == 0) delete p; }
+ {
+ if ( p->use_count.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
+ };
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
};
- volatile uint32_t state_;
- volatile uint32_t count_;
- typename node::ptr_t head_;
- mutex head_mtx_;
- typename node::ptr_t tail_;
- mutex tail_mtx_;
+ atomic< state > state_;
+ atomic< std::size_t > count_;
+ typename node::ptr head_;
+ mutable mutex head_mtx_;
+ typename node::ptr tail_;
+ mutable mutex tail_mtx_;
condition not_empty_cond_;
condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
- volatile uint32_t use_count_;
+ unsigned int hwm_;
+ unsigned int lwm_;
+ atomic< std::size_t > use_count_;
bool active_() const
- { return 0 == state_; }
+ { return ACTIVE == state_.load(); }
void deactivate_()
- { fibers::detail::atomic_fetch_add( & state_, 1); }
+ { state_.store( DEACTIVE); }
- uint32_t size_()
- { return count_; }
+ std::size_t size_() const
+ { return count_.load(); }
- bool empty_()
+ bool empty_() const
{ return head_ == get_tail_(); }
- bool full_()
+ bool full_() const
{ return size_() >= hwm_; }
- typename node::ptr_t get_tail_()
+ typename node::ptr get_tail_() const
{
mutex::scoped_lock lk( tail_mtx_);
- typename node::ptr_t tmp = tail_;
+ typename node::ptr tmp = tail_;
return tmp;
}
- typename node::ptr_t pop_head_()
+ typename node::ptr pop_head_()
{
- typename node::ptr_t old_head = head_;
+ typename node::ptr old_head = head_;
head_ = old_head->next;
- fibers::detail::atomic_fetch_sub( & count_, 1);
+ count_.fetch_sub( 1);
return old_head;
}
public:
impl(
- std::size_t const& hwm,
- std::size_t const& lwm) :
- state_( 0),
+ std::size_t hwm,
+ std::size_t lwm) :
+ state_( ACTIVE),
count_( 0),
- head_( new node),
+ head_( new node() ),
head_mtx_(),
tail_( head_),
tail_mtx_(),
@@ -119,10 +130,10 @@
throw invalid_watermark();
}
- impl( std::size_t const& wm) :
- state_( 0),
+ impl( std::size_t wm) :
+ state_( ACTIVE),
count_( 0),
- head_( new node),
+ head_( new node() ),
head_mtx_(),
tail_( head_),
tail_mtx_(),
@@ -137,30 +148,30 @@
{
if ( hwm < lwm_)
throw invalid_watermark();
- std::size_t tmp( hwm_);
+ unsigned int tmp( hwm_);
hwm_ = hwm;
if ( hwm_ > tmp) not_full_cond_.notify_one();
}
- std::size_t upper_bound()
+ std::size_t upper_bound() const
{ return hwm_; }
void lower_bound_( std::size_t lwm)
{
if ( lwm > hwm_ )
throw invalid_watermark();
- std::size_t tmp( lwm_);
+ unsigned int tmp( lwm_);
lwm_ = lwm;
if ( lwm_ > tmp) not_full_cond_.notify_one();
}
- std::size_t lower_bound()
+ std::size_t lower_bound() const
{ return lwm_; }
void deactivate()
{ deactivate_(); }
- bool empty()
+ bool empty() const
{
mutex::scoped_lock lk( head_mtx_);
return empty_();
@@ -168,7 +179,7 @@
void put( T const& t)
{
- typename node::ptr_t new_node( new node);
+ typename node::ptr new_node( new node() );
{
mutex::scoped_lock lk( tail_mtx_);
@@ -183,7 +194,7 @@
tail_->va = t;
tail_->next = new_node;
tail_ = new_node;
- fibers::detail::atomic_fetch_add( & count_, 1);
+ count_.fetch_add( 1);
}
not_empty_cond_.notify_one();
}
@@ -240,42 +251,48 @@
return valid;
}
- friend void intrusive_ptr_add_ref( impl * p)
- { fibers::detail::atomic_fetch_add( & p->use_count_, 1); }
-
- friend void intrusive_ptr_release( impl * p)
- { if ( fibers::detail::atomic_fetch_sub( & p->use_count_, 1) == 1) delete p; }
+ inline friend void intrusive_ptr_add_ref( impl * p)
+ { p->use_count_.fetch_add( 1, memory_order_relaxed); }
+
+ inline friend void intrusive_ptr_release( impl * p)
+ {
+ if ( p->use_count_.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
};
intrusive_ptr< impl > impl_;
public:
bounded_fifo(
- std::size_t const& hwm,
- std::size_t const& lwm) :
+ std::size_t hwm,
+ std::size_t lwm) :
impl_( new impl( hwm, lwm) )
{}
- bounded_fifo( std::size_t const& wm) :
+ bounded_fifo( std::size_t wm) :
impl_( new impl( wm) )
{}
void upper_bound( std::size_t hwm)
{ impl_->upper_bound( hwm); }
- std::size_t upper_bound()
+ std::size_t upper_bound() const
{ return impl_->upper_bound(); }
void lower_bound( std::size_t lwm)
{ impl_->lower_bound( lwm); }
- std::size_t lower_bound()
+ std::size_t lower_bound() const
{ return impl_->lower_bound(); }
void deactivate()
{ impl_->deactivate(); }
- bool empty()
+ bool empty() const
{ return impl_->empty(); }
void put( T const& t)
Modified: sandbox/fiber/boost/fiber/spin/condition.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/condition.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/condition.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -9,12 +9,13 @@
#ifndef BOOST_FIBERS_SPIN_CONDITION_H
#define BOOST_FIBERS_SPIN_CONDITION_H
+#include <cstddef>
+
#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
+#include <boost/atomic.hpp>
#include <boost/thread/locks.hpp>
#include <boost/utility.hpp>
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/exceptions.hpp>
#include <boost/fiber/spin/mutex.hpp>
#include <boost/fiber/utility.hpp>
@@ -26,19 +27,19 @@
class condition : private noncopyable
{
private:
- enum command_t
+ enum command
{
SLEEPING = 0,
NOTIFY_ONE,
NOTIFY_ALL
};
- volatile uint32_t cmd_;
- volatile uint32_t waiters_;
- mutex enter_mtx_;
- mutex check_mtx_;
+ atomic< command > cmd_;
+ atomic< std::size_t > waiters_;
+ mutex enter_mtx_;
+ mutex check_mtx_;
- void notify_( uint32_t);
+ void notify_( command);
public:
condition();
@@ -70,40 +71,36 @@
{
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- fibers::detail::atomic_fetch_add( & waiters_, 1);
+ waiters_.fetch_add( 1);
lt.unlock();
}
bool unlock_enter_mtx = false;
for (;;)
{
- while ( static_cast< uint32_t >( SLEEPING) == fibers::detail::atomic_load( & cmd_) )
+ while ( SLEEPING == cmd_.load() )
this_fiber::yield();
mutex::scoped_lock lk( check_mtx_);
BOOST_ASSERT( lk);
- uint32_t expected = static_cast< uint32_t >( NOTIFY_ONE);
- fibers::detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- if ( static_cast< uint32_t >( SLEEPING) == expected)
+ command expected = NOTIFY_ONE;
+ cmd_.compare_exchange_strong( expected, SLEEPING);
+ if ( SLEEPING == expected)
continue;
- else if ( static_cast< uint32_t >( NOTIFY_ONE) == expected)
+ else if ( NOTIFY_ONE == expected)
{
unlock_enter_mtx = true;
- fibers::detail::atomic_fetch_sub( & waiters_, 1);
+ waiters_.fetch_sub( 1);
break;
}
else
{
- unlock_enter_mtx = 1 == fibers::detail::atomic_fetch_sub( & waiters_, 1);
+ unlock_enter_mtx = 1 == waiters_.fetch_sub( 1);
if ( unlock_enter_mtx)
{
- expected = static_cast< uint32_t >( NOTIFY_ALL);
- fibers::detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
+ expected = NOTIFY_ALL;
+ cmd_.compare_exchange_strong( expected, SLEEPING);
}
break;
}
Modified: sandbox/fiber/boost/fiber/spin/count_down_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/count_down_event.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/count_down_event.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,9 @@
#ifndef BOOST_FIBERS_SPIN_COUNT_DOWN_EVENT_H
#define BOOST_FIBERS_SPIN_COUNT_DOWN_EVENT_H
-#include <boost/cstdint.hpp>
+#include <cstddef>
+
+#include <boost/atomic.hpp>
#include <boost/utility.hpp>
namespace boost {
@@ -17,15 +19,15 @@
class count_down_event : private noncopyable
{
private:
- uint32_t initial_;
- volatile uint32_t current_;
+ std::size_t initial_;
+ atomic< std::size_t > current_;
public:
- explicit count_down_event( uint32_t);
+ explicit count_down_event( std::size_t);
- uint32_t initial() const;
+ std::size_t initial() const;
- uint32_t current() const;
+ std::size_t current() const;
bool is_set() const;
Modified: sandbox/fiber/boost/fiber/spin/manual_reset_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/manual_reset_event.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/manual_reset_event.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,7 +7,9 @@
#ifndef BOOST_FIBERS_SPIN_MANUAL_RESET_EVENT_H
#define BOOST_FIBERS_SPIN_MANUAL_RESET_EVENT_H
-#include <boost/cstdint.hpp>
+#include <cstddef>
+
+#include <boost/atomic.hpp>
#include <boost/utility.hpp>
#include <boost/fiber/spin/mutex.hpp>
@@ -19,15 +21,15 @@
class manual_reset_event : private noncopyable
{
private:
- enum state_t
+ enum state
{
- RESET = 0,
- SET
+ SET = 0,
+ RESET
};
- volatile uint32_t state_;
- volatile uint32_t waiters_;
- mutex enter_mtx_;
+ atomic< state > state_;
+ atomic< std::size_t > waiters_;
+ mutex enter_mtx_;
public:
explicit manual_reset_event( bool = false);
Modified: sandbox/fiber/boost/fiber/spin/mutex.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/mutex.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/mutex.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -9,10 +9,12 @@
#ifndef BOOST_FIBERS_SPIN_MUTEX_H
#define BOOST_FIBERS_SPIN_MUTEX_H
-#include <boost/cstdint.hpp>
+#include <boost/atomic.hpp>
#include <boost/thread/locks.hpp>
#include <boost/utility.hpp>
+#include <boost/fiber/fiber.hpp>
+
namespace boost {
namespace fibers {
namespace spin {
@@ -20,7 +22,13 @@
class mutex : private noncopyable
{
private:
- volatile uint32_t state_;
+ enum state
+ {
+ LOCKED = 0,
+ UNLOCKED
+ };
+
+ atomic< state > state_;
public:
typedef unique_lock< mutex > scoped_lock;
Modified: sandbox/fiber/boost/fiber/spin/unbounded_fifo.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/spin/unbounded_fifo.hpp (original)
+++ sandbox/fiber/boost/fiber/spin/unbounded_fifo.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -9,14 +9,13 @@
#include <cstddef>
+#include <boost/atomic.hpp>
#include <boost/config.hpp>
-#include <boost/cstdint.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/utility.hpp>
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/exceptions.hpp>
#include <boost/fiber/spin/condition.hpp>
#include <boost/fiber/spin/mutex.hpp>
@@ -39,11 +38,11 @@
private:
struct node
{
- typedef intrusive_ptr< node > ptr_t;
+ typedef intrusive_ptr< node > ptr;
- uint32_t use_count;
- value_type va;
- ptr_t next;
+ atomic< std::size_t > use_count;
+ value_type va;
+ ptr next;
node() :
use_count( 0),
@@ -52,47 +51,59 @@
{}
inline friend void intrusive_ptr_add_ref( node * p)
- { ++p->use_count; }
+ { p->use_count.fetch_add( 1, memory_order_relaxed); }
inline friend void intrusive_ptr_release( node * p)
- { if ( --p->use_count == 0) delete p; }
+ {
+ if ( p->use_count.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
+ };
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
};
- volatile uint32_t state_;
- typename node::ptr_t head_;
- mutex head_mtx_;
- typename node::ptr_t tail_;
- mutex tail_mtx_;
+ atomic< state > state_;
+ typename node::ptr head_;
+ mutable mutex head_mtx_;
+ typename node::ptr tail_;
+ mutable mutex tail_mtx_;
condition not_empty_cond_;
- uint32_t use_count_;
+ atomic< std::size_t > use_count_;
bool active_() const
- { return 0 == state_; }
+ { return ACTIVE == state_.load(); }
void deactivate_()
- { fibers::detail::atomic_fetch_add( & state_, 1); }
+ { state_.store( DEACTIVE); }
- bool empty_()
+ bool empty_() const
{ return head_ == get_tail_(); }
- typename node::ptr_t get_tail_()
+ typename node::ptr get_tail_() const
{
mutex::scoped_lock lk( tail_mtx_);
- typename node::ptr_t tmp = tail_;
+ typename node::ptr tmp = tail_;
return tmp;
}
- typename node::ptr_t pop_head_()
+ typename node::ptr pop_head_()
{
- typename node::ptr_t old_head = head_;
+ typename node::ptr old_head = head_;
head_ = old_head->next;
return old_head;
}
public:
impl() :
- state_( 0),
- head_( new node),
+ state_( ACTIVE),
+ head_( new node() ),
head_mtx_(),
tail_( head_),
tail_mtx_(),
@@ -103,7 +114,7 @@
void deactivate()
{ deactivate_(); }
- bool empty()
+ bool empty() const
{
mutex::scoped_lock lk( head_mtx_);
return empty_();
@@ -111,7 +122,7 @@
void put( T const& t)
{
- typename node::ptr_t new_node( new node);
+ typename node::ptr new_node( new node() );
{
mutex::scoped_lock lk( tail_mtx_);
@@ -155,11 +166,17 @@
return va;
}
- friend void intrusive_ptr_add_ref( impl * p)
- { fibers::detail::atomic_fetch_add( & p->use_count_, 1); }
-
- friend void intrusive_ptr_release( impl * p)
- { if ( fibers::detail::atomic_fetch_sub( & p->use_count_, 1) == 1) delete p; }
+ inline friend void intrusive_ptr_add_ref( impl * p)
+ { p->use_count_.fetch_add( 1, memory_order_relaxed); }
+
+ inline friend void intrusive_ptr_release( impl * p)
+ {
+ if ( p->use_count_.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
};
intrusive_ptr< impl > impl_;
Modified: sandbox/fiber/boost/fiber/strategy.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/strategy.hpp (original)
+++ sandbox/fiber/boost/fiber/strategy.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -9,6 +9,7 @@
#include <cstddef>
+#include <boost/atomic.hpp>
#include <boost/function.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/thread/tss.hpp>
@@ -103,51 +104,51 @@
static void cancel_();
- uint32_t use_count_;
+ atomic< std::size_t > use_count_;
protected:
- typedef thread_specific_ptr< fiber > fiber_t;
+ typedef thread_specific_ptr< fiber > fiber_tss;
- static fiber_t active_fiber;
+ static fiber_tss active_fiber;
- fiber master_fiber;
+ fiber master_fiber;
void attach( fiber &);
- void detach( fiber &);
+ static void detach( fiber &);
- void switch_between( fiber &, fiber &);
+ static void switch_between( fiber &, fiber &);
- void enable_interruption( fiber &);
+ static void enable_interruption( fiber &);
- bool interruption_enabled( fiber const&);
+ static bool interruption_enabled( fiber const&);
bool is_master( fiber const&);
- bool in_state_not_started( fiber const&);
+ static bool in_state_not_started( fiber const&);
- bool in_state_ready( fiber const&);
+ static bool in_state_ready( fiber const&);
- bool in_state_running( fiber const&);
+ static bool in_state_running( fiber const&);
- bool in_state_wait_for_fiber( fiber const&);
+ static bool in_state_wait_for_fiber( fiber const&);
- bool in_state_wait_for_object( fiber const&);
+ static bool in_state_wait_for_object( fiber const&);
- bool in_state_terminated( fiber const&);
+ static bool in_state_terminated( fiber const&);
- void set_state_ready( fiber &);
+ static void set_state_ready( fiber &);
- void set_state_running( fiber &);
+ static void set_state_running( fiber &);
- void set_state_wait_for_fiber( fiber &);
+ static void set_state_wait_for_fiber( fiber &);
- void set_state_wait_for_object( fiber &);
+ static void set_state_wait_for_object( fiber &);
- void set_state_terminated( fiber &);
+ static void set_state_terminated( fiber &);
public:
- typedef intrusive_ptr< strategy > ptr_t;
+ typedef intrusive_ptr< strategy > ptr;
strategy();
@@ -183,17 +184,23 @@
virtual bool run() = 0;
- virtual bool empty() = 0;
+ virtual bool empty() const = 0;
- virtual std::size_t size() = 0;
+ virtual std::size_t size() const = 0;
- virtual std::size_t ready() = 0;
+ virtual std::size_t ready() const = 0;
inline friend void intrusive_ptr_add_ref( strategy * p)
- { ++p->use_count_; }
+ { p->use_count_.fetch_add( 1, memory_order_relaxed); }
inline friend void intrusive_ptr_release( strategy * p)
- { if ( --p->use_count_ == 0) delete p; }
+ {
+ if ( p->use_count_.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
};
}}
Modified: sandbox/fiber/boost/fiber/unbounded_fifo.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/unbounded_fifo.hpp (original)
+++ sandbox/fiber/boost/fiber/unbounded_fifo.hpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -10,7 +10,6 @@
#include <cstddef>
#include <boost/config.hpp>
-#include <boost/cstdint.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/utility.hpp>
@@ -37,11 +36,11 @@
private:
struct node
{
- typedef intrusive_ptr< node > ptr_t;
+ typedef intrusive_ptr< node > ptr;
- uint32_t use_count;
- value_type va;
- ptr_t next;
+ std::size_t use_count;
+ value_type va;
+ ptr next;
node() :
use_count( 0),
@@ -56,33 +55,39 @@
{ if ( --p->use_count == 0) delete p; }
};
- uint32_t state_;
- typename node::ptr_t head_;
- mutex head_mtx_;
- typename node::ptr_t tail_;
- mutex tail_mtx_;
- condition not_empty_cond_;
- uint32_t use_count_;
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ state state_;
+ typename node::ptr head_;
+ mutable mutex head_mtx_;
+ typename node::ptr tail_;
+ mutable mutex tail_mtx_;
+ condition not_empty_cond_;
+ std::size_t use_count_;
bool active_() const
- { return 0 == state_; }
+ { return ACTIVE == state_; }
void deactivate_()
- { ++state_; }
+ { state_ = DEACTIVE; }
- bool empty_()
+ bool empty_() const
{ return head_ == get_tail_(); }
- typename node::ptr_t get_tail_()
+ typename node::ptr get_tail_() const
{
mutex::scoped_lock lk( tail_mtx_);
- typename node::ptr_t tmp = tail_;
+ typename node::ptr tmp = tail_;
return tmp;
}
- typename node::ptr_t pop_head_()
+ typename node::ptr pop_head_()
{
- typename node::ptr_t old_head = head_;
+ typename node::ptr old_head = head_;
head_ = old_head->next;
return old_head;
}
@@ -90,8 +95,8 @@
public:
template< typename Strategy >
impl( scheduler< Strategy > & sched) :
- state_( 0),
- head_( new node),
+ state_( ACTIVE),
+ head_( new node() ),
head_mtx_( sched),
tail_( head_),
tail_mtx_( sched),
@@ -102,7 +107,7 @@
void deactivate()
{ deactivate_(); }
- bool empty()
+ bool empty() const
{
mutex::scoped_lock lk( head_mtx_);
return empty_();
@@ -110,7 +115,7 @@
void put( T const& t)
{
- typename node::ptr_t new_node( new node);
+ typename node::ptr new_node( new node() );
{
mutex::scoped_lock lk( tail_mtx_);
@@ -172,7 +177,7 @@
void deactivate()
{ impl_->deactivate(); }
- bool empty()
+ bool empty() const
{ return impl_->empty(); }
void put( T const& t)
Modified: sandbox/fiber/change.log
==============================================================================
--- sandbox/fiber/change.log (original)
+++ sandbox/fiber/change.log 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -2,6 +2,7 @@
------
- default stacksize = 64kB because of seg fault if value is too small
- using boost.move library for move support
+- using boost.atomic for atomic ops.
0.3.1:
------
Modified: sandbox/fiber/libs/fiber/doc/fiber.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/fiber.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/fiber.qbk 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -19,9 +19,10 @@
]
+[def __boost_atomic__ [@http://www.chaoticmind.net/~hcb/projects/boost.atomic/doc/index.html [*Boost.Atomic]]]
[def __boost_fiber__ [*Boost.Fiber]]
-[def __boost_task__ [*Boost.Task]]
-[def __boost_thread__ [*Boost.Thread]]
+[def __boost_move__ [@http://svn.boost.org/svn/boost/sandbox/move/libs/move/doc/html/index.html [*Boost.Move]]]
+[def __boost_thread__ [@http://www.boost.org/libs/thread [*Boost.Thread]]]
[template barrier_link[link_text] [link fiber.synchronization.barriers [link_text]]]
[template condition_link[link_text] [link fiber.synchronization.conditions [link_text]]]
Modified: sandbox/fiber/libs/fiber/doc/fiber_ref.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/fiber_ref.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/fiber_ref.qbk 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -71,6 +71,9 @@
boost::fibers::scheduler<> sched;
sched.make_fiber( new_fn, arg1, arg2, arg3);
+[caution If you encounter segmentation faults or bus errors it may be possible that the stacksize for the fibers is
+too small.]
+
[heading Exceptions]
Modified: sandbox/fiber/libs/fiber/doc/overview.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/overview.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/overview.qbk 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -38,7 +38,8 @@
[warning This library is ['not] an official Boost library]
-__boost_fiber__ uses some code from __boost_thread__ (especially a specialisation of future)!
+__boost_fiber__ depends uppon __boost_atomic__, __boost_move__ and uses some code from __boost_thread__
+(especially a specialisation of future).
[heading Tested Platforms]
Modified: sandbox/fiber/libs/fiber/doc/todo.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/todo.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/todo.qbk 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -7,12 +7,12 @@
[section:todo Todo]
+* optimize memory ordering in atomic ops.
+
* replace system calls related to fiber switching (like swapcontext()) by assembler
* replace thread_specific_ptr by an specialiced implementation for fiber (interusive_ptr)
-* replace implementation of atomic-ops by boost.atomic
-
* provide an scheduler which deals with priorities
[endsect]
Modified: sandbox/fiber/libs/fiber/examples/ping_pong.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/examples/ping_pong.cpp (original)
+++ sandbox/fiber/libs/fiber/examples/ping_pong.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -11,7 +11,7 @@
#include <boost/fiber.hpp>
typedef boost::fibers::unbounded_fifo< std::string > fifo_t;
-typedef boost::intrusive_ptr< fifo_t > fifo_ptr_t;
+typedef boost::intrusive_ptr< fifo_t > fifo_ptr;
inline
void ping(
Modified: sandbox/fiber/libs/fiber/src/auto_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/auto_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/auto_reset_event.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -6,8 +6,6 @@
#include "boost/fiber/auto_reset_event.hpp"
-#include <boost/fiber/detail/atomic.hpp>
-
namespace boost {
namespace fibers {
@@ -17,30 +15,27 @@
void
auto_reset_event::set()
{
- detail::atomic_exchange( & state_, static_cast< uint32_t >( SET) );
+ state_ = SET;
strategy_->object_notify_one( id_);
}
void
auto_reset_event::wait()
{
- uint32_t expected = static_cast< uint32_t >( SET);
- while ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) ) )
- {
+ while ( RESET == state_)
strategy_->wait_for_object( id_);
- expected = static_cast< uint32_t >( SET);
- }
+ state_ = RESET;
}
bool
auto_reset_event::try_wait()
{
- uint32_t expected = static_cast< uint32_t >( SET);
- return detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) );
+ if ( SET == state_)
+ {
+ state_ = RESET;
+ return true;
+ }
+ return false;
}
}}
Modified: sandbox/fiber/libs/fiber/src/condition.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/condition.cpp (original)
+++ sandbox/fiber/libs/fiber/src/condition.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -19,18 +19,14 @@
{
enter_mtx_.lock();
- if ( 0 == detail::atomic_load( & waiters_) )
+ if ( 0 == waiters_)
{
enter_mtx_.unlock();
return;
}
- uint32_t cmd = static_cast< uint32_t >( NOTIFY_ONE);
- uint32_t expected = static_cast< uint32_t >( SLEEPING);
- while ( ! detail::atomic_compare_exchange_strong(
- & cmd_, & expected, cmd) )
- this_fiber::yield();
-
+ cmd_ = NOTIFY_ONE;
+
strategy_->object_notify_one( id_);
}
@@ -39,17 +35,13 @@
{
enter_mtx_.lock();
- if ( 0 == detail::atomic_load( & waiters_) )
+ if ( 0 == waiters_)
{
enter_mtx_.unlock();
return;
}
- uint32_t cmd = static_cast< uint32_t >( NOTIFY_ALL);
- uint32_t expected = static_cast< uint32_t >( SLEEPING);
- while ( ! detail::atomic_compare_exchange_strong(
- & cmd_, & expected, cmd) )
- this_fiber::yield();
+ cmd_ = NOTIFY_ALL;
strategy_->object_notify_all( id_);
}
Modified: sandbox/fiber/libs/fiber/src/count_down_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/count_down_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/count_down_event.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -6,45 +6,36 @@
#include "boost/fiber/count_down_event.hpp"
-#include <boost/fiber/detail/atomic.hpp>
-
namespace boost {
namespace fibers {
count_down_event::~count_down_event()
{ strategy_->unregister_object( id_); }
-uint32_t
+std::size_t
count_down_event::initial() const
{ return initial_; }
-uint32_t
+std::size_t
count_down_event::current() const
-{ return detail::atomic_load( & current_); }
+{ return current_; }
bool
count_down_event::is_set() const
-{ return 0 == detail::atomic_load( & current_); }
+{ return 0 == current_; }
void
count_down_event::set()
{
- for (;;)
- {
- if ( 0 == detail::atomic_load( & current_) )
- return;
- uint32_t expected = current_;
- if ( detail::atomic_compare_exchange_strong( & current_, & expected, expected - 1) )
- break;
- }
- if ( 0 == detail::atomic_load( & current_) )
+ if ( 0 == current_) return;
+ if ( 0 == --current_)
strategy_->object_notify_all( id_);
}
void
count_down_event::wait()
{
- while ( 0 != detail::atomic_load( & current_) )
+ while ( 0 != current_)
strategy_->wait_for_object( id_);
}
Modified: sandbox/fiber/libs/fiber/src/fiber.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -18,33 +18,33 @@
namespace boost {
namespace fibers {
-std::size_t
-fiber::default_stacksize = 64000;
+unsigned int
+fiber::default_stacksize = 65536;
fiber::fiber() :
- info_base_()
+ info_()
{}
-fiber::fiber( detail::info_base::ptr_t info_base) :
- info_base_( info_base)
+fiber::fiber( detail::info_base::ptr info_base) :
+ info_( info_base)
{}
fiber::fiber( fiber const& other) :
- info_base_( other.info_base_)
+ info_( other.info_)
{}
fiber &
fiber::operator=( BOOST_COPY_ASSIGN_REF( fiber) other)
{
if ( this == & other) return * this;
- info_base_ = other.info_base_;
+ info_ = other.info_;
return * this;
}
fiber::fiber( BOOST_RV_REF( fiber) other)
{
- info_base_ = other.info_base_;
- other.info_base_.reset();
+ info_ = other.info_;
+ other.info_.reset();
}
fiber &
@@ -55,16 +55,12 @@
return * this;
}
-detail::info_base::ptr_t
-fiber::info_() const
-{ return info_base_; }
-
fiber::operator unspecified_bool_type() const
-{ return info_base_; }
+{ return info_; }
bool
fiber::operator!() const
-{ return ! info_base_; }
+{ return ! info_; }
bool
fiber::operator==( fiber const& other) const
@@ -76,61 +72,61 @@
void
fiber::swap( fiber & other)
-{ info_base_.swap( other.info_base_); }
+{ info_.swap( other.info_); }
fiber::id
fiber::get_id() const
-{ return fiber::id( info_base_); }
+{ return fiber::id( info_); }
bool
fiber::is_alive() const
{
- if ( ! info_base_) throw fiber_moved();
- return ( info_base_->state & IS_ALIVE_BIT_MASK) != 0;
+ if ( ! info_) throw fiber_moved();
+ return ( info_->state & IS_ALIVE_BIT_MASK) != 0;
}
int
fiber::priority() const
{
- if ( ! info_base_) throw fiber_moved();
- return info_base_->priority;
+ if ( ! info_) throw fiber_moved();
+ return info_->priority;
}
void
fiber::priority( int prio)
{
- if ( ! info_base_) throw fiber_moved();
- info_base_->priority = prio;
+ if ( ! info_) throw fiber_moved();
+ info_->priority = prio;
if ( is_alive() )
- info_base_->st->reschedule( get_id() );
+ info_->st->reschedule( get_id() );
}
void
fiber::interrupt()
{
- if ( ! info_base_) throw fiber_moved();
- info_base_->st->interrupt( get_id() );
+ if ( ! info_) throw fiber_moved();
+ info_->st->interrupt( get_id() );
}
bool
fiber::interruption_requested() const
{
- if ( ! info_base_) throw fiber_moved();
- return ( info_base_->interrupt & detail::INTERRUPTION_ENABLED) != 0;
+ if ( ! info_) throw fiber_moved();
+ return ( info_->interrupt & detail::INTERRUPTION_ENABLED) != 0;
}
void
fiber::cancel()
{
- if ( ! info_base_) throw fiber_moved();
- info_base_->st->cancel( get_id() );
+ if ( ! info_) throw fiber_moved();
+ info_->st->cancel( get_id() );
}
void
fiber::join()
{
- if ( ! info_base_) throw fiber_moved();
- info_base_->st->join( get_id() );
+ if ( ! info_) throw fiber_moved();
+ info_->st->join( get_id() );
}
}}
Modified: sandbox/fiber/libs/fiber/src/fiber_posix.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_posix.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_posix.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -48,21 +48,21 @@
typedef void ( * st_fn)();
fn_type * fn_ptr( trampoline);
- if ( ! info_base_) throw fiber_moved();
+ if ( ! info_) throw fiber_moved();
::makecontext(
- & info_base_->uctx,
+ & info_->uctx,
( st_fn)( fn_ptr),
1,
- info_base_.get() );
+ info_.get() );
}
void
fiber::switch_to_( fiber & to)
{
- if ( ! info_base_ || ! to.info_base_) throw fiber_moved();
+ if ( ! info_ || ! to.info_) throw fiber_moved();
- if ( ::swapcontext( & info_base_->uctx, & to.info_base_->uctx) != 0)
+ if ( ::swapcontext( & info_->uctx, & to.info_->uctx) != 0)
throw system::system_error(
system::error_code(
errno,
Modified: sandbox/fiber/libs/fiber/src/fiber_windows.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_windows.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_windows.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -60,20 +60,20 @@
void
fiber::init_()
{
- if ( ! info_base_) throw fiber_moved();
+ if ( ! info_) throw fiber_moved();
- info_base_->uctx = ::CreateFiber(
- info_base_->stack_size,
+ info_->uctx = ::CreateFiber(
+ info_->stack_size,
static_cast< LPFIBER_START_ROUTINE >( & trampoline),
- static_cast< LPVOID >( info_base_.get() ) );
+ static_cast< LPVOID >( info_.get() ) );
}
void
fiber::switch_to_( fiber & to)
{
- if ( ! info_base_ || ! to.info_base_) throw fiber_moved();
+ if ( ! info_ || ! to.info_) throw fiber_moved();
- ::SwitchToFiber( to.info_base_->uctx);
+ ::SwitchToFiber( to.info_->uctx);
}
void
Modified: sandbox/fiber/libs/fiber/src/manual_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/manual_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/manual_reset_event.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -8,8 +8,6 @@
#include <boost/assert.hpp>
-#include <boost/fiber/detail/atomic.hpp>
-
namespace boost {
namespace fibers {
@@ -21,11 +19,15 @@
{
enter_mtx_.lock();
- uint32_t expected = static_cast< uint32_t >( RESET);
- if ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( SET) ) ||
- ! detail::atomic_load( & waiters_ ) )
+ if ( SET == state_)
+ {
+ enter_mtx_.unlock();
+ return;
+ }
+
+ state_ = SET;
+
+ if ( 0 == waiters_)
enter_mtx_.unlock();
else
strategy_->object_notify_all( id_);
@@ -37,8 +39,7 @@
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_exchange( & state_,
- static_cast< uint32_t >( RESET) );
+ state_ = RESET;
}
void
@@ -47,13 +48,13 @@
{
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
+ ++waiters_;
}
- while ( static_cast< uint32_t >( RESET) == detail::atomic_load( & state_) )
+ while ( RESET == state_)
strategy_->wait_for_object( id_);
- if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
+ if ( 0 == --waiters_)
enter_mtx_.unlock();
}
@@ -63,12 +64,12 @@
{
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
+ ++waiters_;
}
- bool result = static_cast< uint32_t >( SET) == detail::atomic_load( & state_);
+ bool result = SET == state_;
- if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
+ if ( 0 == --waiters_)
enter_mtx_.unlock();
return result;
Modified: sandbox/fiber/libs/fiber/src/mutex.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/mutex.cpp (original)
+++ sandbox/fiber/libs/fiber/src/mutex.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -6,7 +6,7 @@
#include <boost/fiber/mutex.hpp>
-#include <boost/fiber/detail/atomic.hpp>
+#include <boost/fiber/utility.hpp>
namespace boost {
namespace fibers {
@@ -17,27 +17,26 @@
void
mutex::lock()
{
- for (;;)
- {
- uint32_t expected = 0;
- if ( detail::atomic_compare_exchange_strong( & state_, & expected, 1) )
- break;
- else
- strategy_->wait_for_object( id_);
- }
+ while ( LOCKED == state_)
+ strategy_->wait_for_object( id_);
+ state_ = LOCKED;
}
bool
mutex::try_lock()
{
- uint32_t expected = 0;
- return detail::atomic_compare_exchange_strong( & state_, & expected, 1);
+ if ( UNLOCKED == state_)
+ {
+ state_ = LOCKED;
+ return true;
+ }
+ return false;
}
void
mutex::unlock()
{
- detail::atomic_exchange( & state_, 0);
+ state_ = UNLOCKED;
strategy_->object_notify_one( id_);
}
Modified: sandbox/fiber/libs/fiber/src/round_robin.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/round_robin.cpp (original)
+++ sandbox/fiber/libs/fiber/src/round_robin.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -435,15 +435,15 @@
}
bool
-round_robin::empty()
+round_robin::empty() const
{ return fibers_.empty(); }
std::size_t
-round_robin::size()
+round_robin::size() const
{ return fibers_.size(); }
std::size_t
-round_robin::ready()
+round_robin::ready() const
{ return runnable_fibers_.size(); }
}}
Modified: sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -6,7 +6,6 @@
#include "boost/fiber/spin/auto_reset_event.hpp"
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/utility.hpp>
namespace boost {
@@ -14,36 +13,29 @@
namespace spin {
auto_reset_event::auto_reset_event( bool isset) :
- state_(
- isset ?
- static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) )
+ state_( isset ? SET : RESET)
{}
void
auto_reset_event::set()
-{ detail::atomic_exchange( & state_, static_cast< uint32_t >( SET) ); }
+{ state_.exchange( SET); }
void
auto_reset_event::wait()
{
- uint32_t expected = static_cast< uint32_t >( SET);
- while ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) ) )
+ state expected = SET;
+ while ( ! state_.compare_exchange_strong( expected, RESET) )
{
this_fiber::yield();
- expected = static_cast< uint32_t >( SET);
+ expected = SET;
}
}
bool
auto_reset_event::try_wait()
{
- uint32_t expected = static_cast< uint32_t >( SET);
- return detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) );
+ state expected = SET;
+ return state_.compare_exchange_strong( expected, RESET);
}
}}}
Modified: sandbox/fiber/libs/fiber/src/spin/barrier.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/barrier.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/barrier.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -12,7 +12,7 @@
namespace fibers {
namespace spin {
-barrier::barrier( uint32_t initial) :
+barrier::barrier( std::size_t initial) :
initial_( initial),
current_( initial_),
cycle_( true),
Modified: sandbox/fiber/libs/fiber/src/spin/condition.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/condition.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/condition.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -11,24 +11,26 @@
namespace spin {
void
-condition::notify_( uint32_t cmd)
+condition::notify_( command cmd)
{
enter_mtx_.lock();
- if ( 0 == detail::atomic_load( & waiters_) )
+ if ( 0 == waiters_.load() )
{
enter_mtx_.unlock();
return;
}
- uint32_t expected = static_cast< uint32_t >( SLEEPING);
- while ( ! detail::atomic_compare_exchange_strong(
- & cmd_, & expected, cmd) )
- this_fiber::yield();
+ command expected = SLEEPING;
+ while ( ! cmd_.compare_exchange_strong( expected, cmd) )
+ {
+ this_fiber::yield();
+ expected = SLEEPING;
+ }
}
condition::condition() :
- cmd_( static_cast< uint32_t >( SLEEPING) ),
+ cmd_( SLEEPING),
waiters_( 0),
enter_mtx_(),
check_mtx_()
@@ -36,10 +38,10 @@
void
condition::notify_one()
-{ notify_( static_cast< uint32_t >( NOTIFY_ONE) ); }
+{ notify_( NOTIFY_ONE); }
void
condition::notify_all()
-{ notify_( static_cast< uint32_t >( NOTIFY_ALL) ); }
+{ notify_( NOTIFY_ALL); }
}}}
Modified: sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -6,7 +6,6 @@
#include "boost/fiber/spin/count_down_event.hpp"
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/spin/mutex.hpp>
#include <boost/fiber/utility.hpp>
@@ -14,32 +13,32 @@
namespace fibers {
namespace spin {
-count_down_event::count_down_event( uint32_t initial) :
+count_down_event::count_down_event( std::size_t initial) :
initial_( initial),
current_( initial_)
{}
-uint32_t
+std::size_t
count_down_event::initial() const
{ return initial_; }
-uint32_t
+std::size_t
count_down_event::current() const
-{ return detail::atomic_load( & current_); }
+{ return current_.load(); }
bool
count_down_event::is_set() const
-{ return 0 == detail::atomic_load( & current_); }
+{ return 0 == current_.load(); }
void
count_down_event::set()
{
for (;;)
{
- if ( 0 == detail::atomic_load( & current_) )
+ if ( 0 == current_.load() )
return;
- uint32_t expected = current_;
- if ( detail::atomic_compare_exchange_strong( & current_, & expected, expected - 1) )
+ std::size_t expected = current_.load();
+ if ( current_.compare_exchange_strong( expected, expected - 1) )
return;
}
}
@@ -47,7 +46,7 @@
void
count_down_event::wait()
{
- while ( 0 != detail::atomic_load( & current_) )
+ while ( 0 != current_.load() )
this_fiber::yield();
}
Modified: sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -8,7 +8,6 @@
#include <boost/assert.hpp>
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/utility.hpp>
namespace boost {
@@ -16,10 +15,7 @@
namespace spin {
manual_reset_event::manual_reset_event( bool isset) :
- state_(
- isset ?
- static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) ),
+ state_( isset ? SET : RESET),
waiters_( 0),
enter_mtx_()
{}
@@ -29,11 +25,9 @@
{
enter_mtx_.lock();
- uint32_t expected = static_cast< uint32_t >( RESET);
- if ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( SET) ) ||
- ! detail::atomic_load( & waiters_ ) )
+ state expected = RESET;
+ if ( ! state_.compare_exchange_strong( expected, SET) ||
+ 0 == waiters_.load() )
enter_mtx_.unlock();
}
@@ -43,8 +37,7 @@
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_exchange( & state_,
- static_cast< uint32_t >( RESET) );
+ state_.exchange( RESET);
}
void
@@ -53,13 +46,13 @@
{
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
+ waiters_.fetch_add( 1);
}
- while ( static_cast< uint32_t >( RESET) == detail::atomic_load( & state_) )
+ while ( RESET == state_.load() )
this_fiber::yield();
- if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
+ if ( 1 == waiters_.fetch_sub( 1) )
enter_mtx_.unlock();
}
@@ -69,12 +62,12 @@
{
mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
+ waiters_.fetch_add( 1);
}
- bool result = static_cast< uint32_t >( SET) == detail::atomic_load( & state_);
+ bool result = SET == state_.load();
- if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
+ if ( 1 == waiters_.fetch_sub( 1) )
enter_mtx_.unlock();
return result;
Modified: sandbox/fiber/libs/fiber/src/spin/mutex.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/mutex.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/mutex.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -6,7 +6,6 @@
#include <boost/fiber/spin/mutex.hpp>
-#include <boost/fiber/detail/atomic.hpp>
#include <boost/fiber/utility.hpp>
namespace boost {
@@ -14,7 +13,7 @@
namespace spin {
mutex::mutex() :
- state_( 0)
+ state_( UNLOCKED)
{}
void
@@ -22,8 +21,8 @@
{
for (;;)
{
- uint32_t expected = 0;
- if ( detail::atomic_compare_exchange_strong( & state_, & expected, 1) )
+ state expected = UNLOCKED;
+ if ( state_.compare_exchange_strong( expected, LOCKED) )
break;
else
this_fiber::yield();
@@ -33,12 +32,12 @@
bool
mutex::try_lock()
{
- uint32_t expected = 0;
- return detail::atomic_compare_exchange_strong( & state_, & expected, 1);
+ state expected = UNLOCKED;
+ return state_.compare_exchange_strong( expected, LOCKED);
}
void
mutex::unlock()
-{ detail::atomic_exchange( & state_, 0); }
+{ state_.exchange( UNLOCKED); }
}}}
Modified: sandbox/fiber/libs/fiber/src/strategy.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/strategy.cpp (original)
+++ sandbox/fiber/libs/fiber/src/strategy.cpp 2009-12-22 10:37:26 EST (Tue, 22 Dec 2009)
@@ -12,7 +12,7 @@
namespace boost {
namespace fibers {
-strategy::fiber_t strategy::active_fiber;
+strategy::fiber_tss strategy::active_fiber;
bool
strategy::runs_as_fiber_()
@@ -31,7 +31,7 @@
{
fiber * active( active_fiber.get() );
if ( ! active) throw fiber_error("not a fiber");
- if ( detail::INTERRUPTION_ENABLED == active->info_()->interrupt)
+ if ( detail::INTERRUPTION_ENABLED == active->info_->interrupt)
throw fiber_interrupted();
}
@@ -48,7 +48,7 @@
{
fiber * active( active_fiber.get() );
if ( ! active) throw fiber_error("not a fiber");
- return active->info_()->interrupt;
+ return active->info_->interrupt;
}
bool
@@ -56,7 +56,7 @@
{
fiber * active( active_fiber.get() );
if ( ! active) throw fiber_error("not a fiber");
- return ( active->info_()->interrupt & detail::INTERRUPTION_ENABLED) != 0;
+ return ( active->info_->interrupt & detail::INTERRUPTION_ENABLED) != 0;
}
int
@@ -80,7 +80,7 @@
{
fiber * active( active_fiber.get() );
if ( ! active) throw fiber_error("not a fiber");
- active->info_()->at_exit.push( ca);
+ active->info_->at_exit.push( ca);
}
void
@@ -88,8 +88,8 @@
{
fiber * active( active_fiber.get() );
if ( ! active) throw fiber_error("not a fiber");
- if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
- active->info_()->st->yield();
+ if ( ! active->info_->st) throw scheduler_error("no valid scheduler");
+ active->info_->st->yield();
}
void
@@ -97,8 +97,8 @@
{
fiber * active( active_fiber.get() );
if ( ! active) throw fiber_error("not a fiber");
- if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
- active->info_()->st->cancel( active_fiber->get_id() );
+ if ( ! active->info_->st) throw scheduler_error("no valid scheduler");
+ active->info_->st->cancel( active_fiber->get_id() );
}
strategy::strategy() :
@@ -107,7 +107,7 @@
{
fiber::convert_thread_to_fiber();
master_fiber = fiber(
- detail::info_base::ptr_t(
+ detail::info_base::ptr(
new detail::info_default() ) );
attach( master_fiber);
}
@@ -117,11 +117,11 @@
void
strategy::attach( fiber & f)
-{ f.info_()->st = this; }
+{ f.info_->st = this; }
void
strategy::detach( fiber & f)
-{ f.info_()->st = 0; }
+{ f.info_->st = 0; }
void
strategy::switch_between( fiber & from, fiber & to)
@@ -131,15 +131,15 @@
strategy::enable_interruption( fiber & f)
{
// remove disabled flag
- f.info_()->interrupt &= ~detail::INTERRUPTION_DISABLED;
+ f.info_->interrupt &= ~detail::INTERRUPTION_DISABLED;
// set enabled flag
- f.info_()->interrupt |= detail::INTERRUPTION_ENABLED;
+ f.info_->interrupt |= detail::INTERRUPTION_ENABLED;
}
bool
strategy::interruption_enabled( fiber const& f)
-{ return detail::INTERRUPTION_ENABLED == f.info_()->interrupt; }
+{ return detail::INTERRUPTION_ENABLED == f.info_->interrupt; }
bool
strategy::is_master( fiber const& f)
@@ -147,46 +147,46 @@
bool
strategy::in_state_not_started( fiber const& f)
-{ return detail::STATE_NOT_STARTED == f.info_()->state; }
+{ return detail::STATE_NOT_STARTED == f.info_->state; }
bool
strategy::in_state_ready( fiber const& f)
-{ return detail::STATE_READY == f.info_()->state; }
+{ return detail::STATE_READY == f.info_->state; }
bool
strategy::in_state_running( fiber const& f)
-{ return detail::STATE_RUNNING == f.info_()->state; }
+{ return detail::STATE_RUNNING == f.info_->state; }
bool
strategy::in_state_wait_for_fiber( fiber const& f)
-{ return detail::STATE_WAIT_FOR_FIBER == f.info_()->state; }
+{ return detail::STATE_WAIT_FOR_FIBER == f.info_->state; }
bool
strategy::in_state_wait_for_object( fiber const& f)
-{ return detail::STATE_WAIT_FOR_OBJECT == f.info_()->state; }
+{ return detail::STATE_WAIT_FOR_OBJECT == f.info_->state; }
bool
strategy::in_state_terminated( fiber const& f)
-{ return detail::STATE_TERMINATED == f.info_()->state; }
+{ return detail::STATE_TERMINATED == f.info_->state; }
void
strategy::set_state_ready( fiber & f)
-{ f.info_()->state = detail::STATE_READY; }
+{ f.info_->state = detail::STATE_READY; }
void
strategy::set_state_running( fiber & f)
-{ f.info_()->state = detail::STATE_RUNNING; }
+{ f.info_->state = detail::STATE_RUNNING; }
void
strategy::set_state_wait_for_fiber( fiber & f)
-{ f.info_()->state = detail::STATE_WAIT_FOR_FIBER; }
+{ f.info_->state = detail::STATE_WAIT_FOR_FIBER; }
void
strategy::set_state_wait_for_object( fiber & f)
-{ f.info_()->state = detail::STATE_WAIT_FOR_OBJECT; }
+{ f.info_->state = detail::STATE_WAIT_FOR_OBJECT; }
void
strategy::set_state_terminated( fiber & f)
-{ f.info_()->state = detail::STATE_TERMINATED; }
+{ f.info_->state = detail::STATE_TERMINATED; }
}}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk