diff --git a/build/Jamfile.v2 b/build/Jamfile.v2
index 7f055765..cf90355c 100644
--- a/build/Jamfile.v2
+++ b/build/Jamfile.v2
@@ -27,21 +27,9 @@ project boost/fiber
;
lib boost_fiber
- : algorithm.cpp
- barrier.cpp
- condition.cpp
- context.cpp
- detail/spinlock.cpp
+ : context.cpp
fiber.cpp
- future.cpp
- interruption.cpp
- mutex.cpp
- properties.cpp
- recursive_mutex.cpp
- recursive_timed_mutex.cpp
- round_robin.cpp
scheduler.cpp
- timed_mutex.cpp
: shared:../../context/build//boost_context
;
diff --git a/include/boost/fiber/algorithm.hpp b/include/boost/fiber/algorithm.hpp
deleted file mode 100644
index 871219d0..00000000
--- a/include/boost/fiber/algorithm.hpp
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright Oliver Kowalke 2013.
-// 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_ALGORITHM_H
-#define BOOST_FIBERS_ALGORITHM_H
-
-#include
-
-#include
-#include
-
-#include
-#include
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_PREFIX
-#endif
-
-namespace boost {
-namespace fibers {
-
-class context;
-
-struct BOOST_FIBERS_DECL sched_algorithm {
- virtual ~sched_algorithm() {}
-
- virtual void awakened( context *) = 0;
-
- virtual context * pick_next() = 0;
-
- virtual std::size_t ready_fibers() const noexcept = 0;
-};
-
-class BOOST_FIBERS_DECL sched_algorithm_with_properties_base : public sched_algorithm {
-public:
- // called by fiber_properties::notify() -- don't directly call
- virtual void property_change_( context * f, fiber_properties * props) = 0;
-
-protected:
- static fiber_properties* get_properties( context * f) noexcept;
- static void set_properties( context * f, fiber_properties * p) noexcept;
-};
-
-template< typename PROPS >
-struct sched_algorithm_with_properties : public sched_algorithm_with_properties_base {
- typedef sched_algorithm_with_properties_base super;
-
- // Mark this override 'final': sched_algorithm_with_properties subclasses
- // must override awakened() with properties parameter instead. Otherwise
- // you'd have to remember to start every subclass awakened() override
- // with: sched_algorithm_with_properties::awakened(fb);
- virtual void awakened( context * f) final {
- fiber_properties * props = super::get_properties( f);
- if ( ! props) {
- // TODO: would be great if PROPS could be allocated on the new
- // fiber's stack somehow
- props = new_properties( f);
- // It is not good for new_properties() to return 0.
- BOOST_ASSERT_MSG(props, "new_properties() must return non-NULL");
- // new_properties() must return instance of (a subclass of) PROPS
- BOOST_ASSERT_MSG(dynamic_cast(props),
- "new_properties() must return properties class");
- super::set_properties( f, props);
- }
- // Set sched_algo_ again every time this fiber becomes READY. That
- // handles the case of a fiber migrating to a new thread with a new
- // sched_algorithm subclass instance.
- props->set_sched_algorithm( this);
-
- // Okay, now forward the call to subclass override.
- awakened( f, properties(f) );
- }
-
- // subclasses override this method instead of the original awakened()
- virtual void awakened( context *, PROPS& ) = 0;
-
- // used for all internal calls
- PROPS& properties( context * f) {
- return static_cast< PROPS & >( * super::get_properties( f) );
- }
-
- // override this to be notified by PROPS::notify()
- virtual void property_change( context * f, PROPS & props) {
- }
-
- // implementation for sched_algorithm_with_properties_base method
- void property_change_( context * f, fiber_properties * props ) final {
- property_change( f, * static_cast< PROPS * >( props) );
- }
-
- // Override this to customize instantiation of PROPS, e.g. use a different
- // allocator. Each PROPS instance is associated with a particular
- // context.
- virtual fiber_properties * new_properties( context * f) {
- return new PROPS( f);
- }
-};
-
-}}
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_SUFFIX
-#endif
-
-#endif // BOOST_FIBERS_ALGORITHM_H
diff --git a/include/boost/fiber/all.hpp b/include/boost/fiber/all.hpp
index 6dd47455..59bbcb0e 100644
--- a/include/boost/fiber/all.hpp
+++ b/include/boost/fiber/all.hpp
@@ -7,24 +7,9 @@
#ifndef BOOST_FIBERS_H
#define BOOST_FIBERS_H
-#include
-#include
-#include
-#include
-#include
#include
#include
-#include
-#include
-#include
-#include
-#include
#include
-#include
-#include
-#include
#include
-#include
-#include
#endif // BOOST_FIBERS_H
diff --git a/include/boost/fiber/barrier.hpp b/include/boost/fiber/barrier.hpp
deleted file mode 100644
index a2a3044d..00000000
--- a/include/boost/fiber/barrier.hpp
+++ /dev/null
@@ -1,48 +0,0 @@
-
-// Copyright Oliver Kowalke 2013.
-// 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_BARRIER_H
-#define BOOST_FIBERS_BARRIER_H
-
-#include
-
-#include
-
-#include
-#include
-#include
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_PREFIX
-#endif
-
-namespace boost {
-namespace fibers {
-
-class BOOST_FIBERS_DECL barrier {
-private:
- std::size_t initial_;
- std::size_t current_;
- bool cycle_;
- mutex mtx_;
- condition cond_;
-
-public:
- barrier( std::size_t);
-
- barrier( barrier const&) = delete;
- barrier & operator=( barrier const&) = delete;
-
- bool wait();
-};
-
-}}
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_SUFFIX
-#endif
-
-#endif // BOOST_FIBERS_BARRIER_H
diff --git a/include/boost/fiber/bounded_channel.hpp b/include/boost/fiber/bounded_channel.hpp
deleted file mode 100644
index 2199f750..00000000
--- a/include/boost/fiber/bounded_channel.hpp
+++ /dev/null
@@ -1,417 +0,0 @@
-
-// Copyright Oliver Kowalke 2013.
-// 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_BOUNDED_CHANNEL_H
-#define BOOST_FIBERS_BOUNDED_CHANNEL_H
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_PREFIX
-#endif
-
-namespace boost {
-namespace fibers {
-
-template< typename T, typename Allocator = std::allocator< T > >
-class bounded_channel {
-public:
- typedef T value_type;
-
-private:
- struct node {
- typedef intrusive_ptr< node > ptr;
- typedef typename std::allocator_traits< Allocator >::template rebind_alloc< node > allocator_type;
-
- std::size_t use_count;
- allocator_type & alloc;
- T va;
- ptr nxt;
-
- explicit node( T const& t, allocator_type & alloc_) :
- use_count( 0),
- alloc( alloc_),
- va( t),
- nxt() {
- }
-
- explicit node( T && t, allocator_type & alloc_) :
- use_count( 0),
- alloc( alloc_),
- va( std::forward< T >( t) ),
- nxt() {
- }
-
- friend
- void intrusive_ptr_add_ref( node * p) {
- ++p->use_count;
- }
-
- friend
- void intrusive_ptr_release( node * p) {
- if ( 0 == --p->use_count) {
- allocator_type & alloc( p->alloc);
- std::allocator_traits< allocator_type >::destroy( alloc, p);
- std::allocator_traits< allocator_type >::deallocate( alloc, p, 1);
- }
- }
- };
-
- typedef typename std::allocator_traits< Allocator >::template rebind_alloc< node > allocator_type;
-
- enum class queue_status {
- open = 0,
- closed
- };
-
- allocator_type alloc_;
- queue_status state_;
- std::size_t count_;
- typename node::ptr head_;
- typename node::ptr * tail_;
- mutable mutex mtx_;
- condition not_empty_cond_;
- condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
-
- bool is_closed_() const noexcept {
- return queue_status::closed == state_;
- }
-
- void close_( std::unique_lock< boost::fibers::mutex > & lk) {
- state_ = queue_status::closed;
- lk.unlock();
- not_empty_cond_.notify_all();
- not_full_cond_.notify_all();
- }
-
- std::size_t size_() const noexcept {
- return count_;
- }
-
- bool is_empty_() const noexcept {
- return ! head_;
- }
-
- bool is_full_() const noexcept {
- return count_ >= hwm_;
- }
-
- channel_op_status push_( typename node::ptr const& new_node,
- std::unique_lock< boost::fibers::mutex > & lk) {
- if ( is_closed_() ) {
- return channel_op_status::closed;
- }
-
- while ( is_full_() ) {
- not_full_cond_.wait( lk);
- }
-
- return push_and_notify_( new_node, lk);
- }
-
- channel_op_status try_push_( typename node::ptr const& new_node,
- std::unique_lock< boost::fibers::mutex > & lk) {
- if ( is_closed_() ) {
- return channel_op_status::closed;
- }
-
- if ( is_full_() ) {
- return channel_op_status::full;
- }
-
- return push_and_notify_( new_node, lk);
- }
-
- template< typename Clock, typename Duration >
- channel_op_status push_wait_until_( typename node::ptr const& new_node,
- std::chrono::time_point< Clock, Duration > const& timeout_time,
- std::unique_lock< boost::fibers::mutex > & lk) {
- if ( is_closed_() ) {
- return channel_op_status::closed;
- }
-
- while ( is_full_() ) {
- if ( cv_status::timeout == not_full_cond_.wait_until( lk, timeout_time) ) {
- return channel_op_status::timeout;
- }
- }
-
- return push_and_notify_( new_node, lk);
- }
-
- channel_op_status push_and_notify_( typename node::ptr const& new_node,
- std::unique_lock< boost::fibers::mutex > & lk) {
- try {
- push_tail_( new_node);
- lk.unlock();
- not_empty_cond_.notify_one();
-
- return channel_op_status::success;
- } catch (...) {
- close_( lk);
- throw;
- }
- }
-
- void push_tail_( typename node::ptr new_node) {
- * tail_ = new_node;
- tail_ = & new_node->nxt;
- ++count_;
- }
-
- value_type value_pop_( std::unique_lock< boost::fibers::mutex > & lk) {
- BOOST_ASSERT( ! is_empty_() );
-
- try {
- typename node::ptr old_head = pop_head_();
- if ( size_() <= lwm_) {
- if ( lwm_ == hwm_) {
- lk.unlock();
- not_full_cond_.notify_one();
- } else {
- lk.unlock();
- // more than one producer could be waiting
- // to push a value
- not_full_cond_.notify_all();
- }
- }
- return std::move( old_head->va);
- } catch (...) {
- close_( lk);
- throw;
- }
- }
-
- typename node::ptr pop_head_() {
- typename node::ptr old_head = head_;
- head_ = old_head->nxt;
- if ( ! head_) {
- tail_ = & head_;
- }
- old_head->nxt.reset();
- --count_;
- return old_head;
- }
-
-public:
- bounded_channel( std::size_t hwm,
- std::size_t lwm,
- Allocator const& alloc = Allocator() ) :
- alloc_( alloc),
- state_( queue_status::open),
- count_( 0),
- head_(),
- tail_( & head_),
- mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- hwm_( hwm),
- lwm_( lwm) {
- if ( hwm_ <= lwm_) {
- throw invalid_argument( static_cast< int >( std::errc::invalid_argument),
- "boost fiber: high-watermark is less than or equal to low-watermark for bounded_channel");
- }
- if ( 0 == hwm) {
- throw invalid_argument( static_cast< int >( std::errc::invalid_argument),
- "boost fiber: high-watermark is zero");
- }
- }
-
- bounded_channel( std::size_t wm,
- Allocator const& alloc = Allocator() ) :
- alloc_( alloc),
- state_( queue_status::open),
- count_( 0),
- head_(),
- tail_( & head_),
- mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- hwm_( wm),
- lwm_() {
- if ( 0 == wm) {
- throw invalid_argument( static_cast< int >( std::errc::invalid_argument),
- "boost fiber: watermark is zero");
- }
- lwm_ = hwm_ - 1;
- }
-
- bounded_channel( bounded_channel const&) = delete;
- bounded_channel & operator=( bounded_channel const&) = delete;
-
- std::size_t upper_bound() const {
- return hwm_;
- }
-
- std::size_t lower_bound() const {
- return lwm_;
- }
-
- void close() {
- std::unique_lock< mutex > lk( mtx_);
- close_( lk);
- }
-
- channel_op_status push( value_type const& va) {
- typename node::ptr new_node(
- new ( alloc_.allocate( 1) ) node( va, alloc_) );
- std::unique_lock< mutex > lk( mtx_);
- return push_( new_node, lk);
- }
-
- channel_op_status push( value_type && va) {
- typename node::ptr new_node(
- new ( alloc_.allocate( 1) ) node( std::forward< value_type >( va), alloc_) );
- std::unique_lock< mutex > lk( mtx_);
- return push_( new_node, lk);
- }
-
- template< typename Rep, typename Period >
- channel_op_status push_wait_for( value_type const& va,
- std::chrono::duration< Rep, Period > const& timeout_duration) {
- return push_wait_until( va,
- std::chrono::steady_clock::now() + timeout_duration);
- }
-
- template< typename Rep, typename Period >
- channel_op_status push_wait_for( value_type && va,
- std::chrono::duration< Rep, Period > const& timeout_duration) {
- return push_wait_until( std::forward< value_type >( va),
- std::chrono::steady_clock::now() + timeout_duration);
- }
-
- template< typename Clock, typename Duration >
- channel_op_status push_wait_until( value_type const& va,
- std::chrono::time_point< Clock, Duration > const& timeout_time) {
- typename node::ptr new_node(
- new ( alloc_.allocate( 1) ) node( va, alloc_) );
- std::unique_lock< mutex > lk( mtx_);
- return push_wait_until_( new_node, timeout_time, lk);
- }
-
- template< typename Clock, typename Duration >
- channel_op_status push_wait_until( value_type && va,
- std::chrono::time_point< Clock, Duration > const& timeout_time) {
- typename node::ptr new_node(
- new ( alloc_.allocate( 1) ) node( std::forward< value_type >( va), alloc_) );
- std::unique_lock< mutex > lk( mtx_);
- return push_wait_until_( new_node, timeout_time, lk);
- }
-
- channel_op_status try_push( value_type const& va) {
- typename node::ptr new_node(
- new ( alloc_.allocate( 1) ) node( va, alloc_) );
- std::unique_lock< mutex > lk( mtx_);
- return try_push_( new_node, lk);
- }
-
- channel_op_status try_push( value_type && va) {
- typename node::ptr new_node(
- new ( alloc_.allocate( 1) ) node( std::forward< value_type >( va), alloc_) );
- std::unique_lock< mutex > lk( mtx_);
- return try_push_( new_node, lk);
- }
-
- channel_op_status pop( value_type & va) {
- std::unique_lock< mutex > lk( mtx_);
-
- while ( ! is_closed_() && is_empty_() ) {
- not_empty_cond_.wait( lk);
- }
-
- if ( is_closed_() && is_empty_() ) {
- return channel_op_status::closed;
- }
-
- va = value_pop_( lk);
- return channel_op_status::success;
- }
-
- value_type value_pop() {
- std::unique_lock< mutex > lk( mtx_);
-
- while ( ! is_closed_() && is_empty_() ) {
- not_empty_cond_.wait( lk);
- }
-
- if ( is_closed_() && is_empty_() ) {
- throw logic_error("boost fiber: queue is closed");
- }
-
- return value_pop_( lk);
- }
-
- channel_op_status try_pop( value_type & va) {
- std::unique_lock< mutex > lk( mtx_);
-
- if ( is_closed_() && is_empty_() ) {
- // let other fibers run
- lk.unlock();
- this_fiber::yield();
- return channel_op_status::closed;
- }
-
- if ( is_empty_() ) {
- // let other fibers run
- lk.unlock();
- this_fiber::yield();
- return channel_op_status::empty;
- }
-
- va = value_pop_( lk);
- return channel_op_status::success;
- }
-
- template< typename Rep, typename Period >
- channel_op_status pop_wait_for( value_type & va,
- std::chrono::duration< Rep, Period > const& timeout_duration) {
- return pop_wait_until( va,
- std::chrono::steady_clock::now() + timeout_duration);
- }
-
- template< typename Clock, typename Duration >
- channel_op_status pop_wait_until( value_type & va,
- std::chrono::time_point< Clock, Duration > const& timeout_time) {
- std::unique_lock< mutex > lk( mtx_);
-
- while ( ! is_closed_() && is_empty_() ) {
- if ( cv_status::timeout == not_empty_cond_.wait_until( lk, timeout_time) ) {
- return channel_op_status::timeout;
- }
- }
-
- if ( is_closed_() && is_empty_() ) {
- return channel_op_status::closed;
- }
-
- va = value_pop_( lk);
- return channel_op_status::success;
- }
-};
-
-}}
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_SUFFIX
-#endif
-
-#endif // BOOST_FIBERS_BOUNDED_CHANNEL_H
diff --git a/include/boost/fiber/channel_op_status.hpp b/include/boost/fiber/channel_op_status.hpp
deleted file mode 100644
index 78fd9bd6..00000000
--- a/include/boost/fiber/channel_op_status.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright Oliver Kowalke 2013.
-// 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_QUEUE_OP_STATUS_H
-#define BOOST_FIBERS_QUEUE_OP_STATUS_H
-
-#include
-
-#include
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_PREFIX
-#endif
-
-namespace boost {
-namespace fibers {
-
-enum class channel_op_status {
- success = 0,
- empty,
- full,
- closed,
- timeout
-};
-
-}}
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_SUFFIX
-#endif
-
-#endif // BOOST_FIBERS_QUEUE_OP_STATUS_H
diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp
deleted file mode 100644
index 929499c4..00000000
--- a/include/boost/fiber/condition.hpp
+++ /dev/null
@@ -1,172 +0,0 @@
-
-// Copyright Oliver Kowalke 2013.
-// 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_CONDITION_H
-#define BOOST_FIBERS_CONDITION_H
-
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_PREFIX
-#endif
-
-namespace boost {
-namespace fibers {
-
-class context;
-
-enum class cv_status {
- no_timeout = 1,
- timeout
-};
-
-class BOOST_FIBERS_DECL condition {
-private:
- typedef detail::wait_queue< context > wait_queue_t;
-
- detail::spinlock splk_;
- wait_queue_t wait_queue_;
-
-public:
- condition();
-
- ~condition();
-
- condition( condition const&) = delete;
- condition & operator=( condition const&) = delete;
-
- void notify_one();
-
- void notify_all();
-
- template< typename LockType, typename Pred >
- void wait( LockType & lt, Pred pred) {
- while ( ! pred() ) {
- wait( lt);
- }
- }
-
- template< typename LockType >
- void wait( LockType & lt) {
- context * f( context::active() );
- try {
- // lock spinlock
- detail::spinlock_lock lk( splk_);
-
- // store this fiber in waiting-queue
- // in order notify (resume) this fiber later
- BOOST_ASSERT( ! f->wait_is_linked() );
- wait_queue_.push_back( * f);
- lk.unlock();
-
- // unlock external
- lt.unlock();
-
- // check if fiber was interrupted
- this_fiber::interruption_point();
- // suspend this fiber
- f->do_schedule();
-
- // lock external again before returning
- lt.lock();
- } catch (...) {
- detail::spinlock_lock lk( splk_);
- f->wait_unlink();
- throw;
- }
- }
-
- template< typename LockType, typename Clock, typename Duration >
- cv_status wait_until( LockType & lt, std::chrono::time_point< Clock, Duration > const& timeout_time_) {
- cv_status status = cv_status::no_timeout;
- std::chrono::steady_clock::time_point timeout_time(
- detail::clock_cast( timeout_time_) );
- context * f( context::active() );
- try {
- // lock spinlock
- detail::spinlock_lock lk( splk_);
-
- // store this fiber in waiting-queue
- // in order notify (resume) this fiber later
- BOOST_ASSERT( ! f->wait_is_linked() );
- wait_queue_.push_back( * f);
- lk.unlock();
-
- // unlock external
- lt.unlock();
-
- // check if fiber was interrupted
- this_fiber::interruption_point();
- // suspend this fiber
- if ( ! f->do_wait_until( timeout_time) ) {
- // this fiber was not notified before timeout
- // lock spinlock again
- detail::spinlock_lock lk( splk_);
- f->wait_unlink();
-
- status = cv_status::timeout;
- }
-
- // lock external again before returning
- lt.lock();
- } catch (...) {
- detail::spinlock_lock lk( splk_);
- f->wait_unlink();
- throw;
- }
-
- return status;
- }
-
- template< typename LockType, typename Clock, typename Duration, typename Pred >
- bool wait_until( LockType & lt,
- std::chrono::time_point< Clock, Duration > const& timeout_time, Pred pred) {
- while ( ! pred() ) {
- if ( cv_status::timeout == wait_until( lt, timeout_time) ) {
- return pred();
- }
- }
- return true;
- }
-
- template< typename LockType, typename Rep, typename Period >
- cv_status wait_for( LockType & lt, std::chrono::duration< Rep, Period > const& timeout_duration) {
- return wait_until( lt,
- std::chrono::steady_clock::now() + timeout_duration);
- }
-
- template< typename LockType, typename Rep, typename Period, typename Pred >
- bool wait_for( LockType & lt, std::chrono::duration< Rep, Period > const& timeout_duration, Pred pred) {
- return wait_until( lt,
- std::chrono::steady_clock::now() + timeout_duration,
- pred);
- }
-};
-
-typedef condition condition_variable;
-typedef condition condition_variable_any;
-
-}}
-
-#ifdef BOOST_HAS_ABI_HEADERS
-# include BOOST_ABI_SUFFIX
-#endif
-
-#endif // BOOST_FIBERS_CONDITION_H
diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp
index a5df3796..82b43ce1 100644
--- a/include/boost/fiber/context.hpp
+++ b/include/boost/fiber/context.hpp
@@ -7,29 +7,17 @@
#ifndef BOOST_FIBERS_CONTEXT_H
#define BOOST_FIBERS_CONTEXT_H
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include