Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57788 - in sandbox/fiber: boost/fiber boost/fiber/detail libs/fiber/build libs/fiber/src
From: oliver.kowalke_at_[hidden]
Date: 2009-11-19 13:36:50


Author: olli
Date: 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
New Revision: 57788
URL: http://svn.boost.org/trac/boost/changeset/57788

Log:
- refactoring -> strategy

Added:
   sandbox/fiber/boost/fiber/detail/strategy.hpp (contents, props changed)
   sandbox/fiber/libs/fiber/src/strategy.cpp (contents, props changed)
Removed:
   sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp
   sandbox/fiber/libs/fiber/src/scheduler_impl.cpp
Text files modified:
   sandbox/fiber/boost/fiber/fiber.hpp | 33 ++++++++++-------------
   sandbox/fiber/boost/fiber/scheduler.hpp | 6 ++--
   sandbox/fiber/libs/fiber/build/Jamfile.v2 | 4 +-
   sandbox/fiber/libs/fiber/src/fiber.cpp | 55 +++++++++++++++++++++------------------
   sandbox/fiber/libs/fiber/src/fiber_posix.cpp | 10 +++---
   sandbox/fiber/libs/fiber/src/fiber_windows.cpp | 10 +++---
   sandbox/fiber/libs/fiber/src/scheduler.cpp | 40 ++++++++++++++--------------
   7 files changed, 80 insertions(+), 78 deletions(-)

Deleted: sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
+++ (empty file)
@@ -1,119 +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_SCHEDULER_IMPL_H
-#define BOOST_FIBERS_DETAIL_SCHEDULER_IMPL_H
-
-#include <cstddef>
-#include <list>
-#include <map>
-#include <queue>
-
-#include <boost/function.hpp>
-#include <boost/optional.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
-#include <boost/fiber/fiber.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-# if defined(BOOST_MSVC)
-# pragma warning(push)
-# pragma warning(disable:4251 4275)
-# endif
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-class BOOST_FIBER_DECL scheduler_impl : private noncopyable
-{
-private:
- struct schedulable
- {
- fiber f;
- std::list< fiber::id > joining_fibers;
- optional< fiber::id > waiting_on;
-
- schedulable() :
- f(), joining_fibers(), waiting_on()
- {}
-
- schedulable( fiber f_) :
- f( f_), joining_fibers(), waiting_on()
- {}
- };
-
- typedef std::map< fiber::id, schedulable > container;
- typedef std::list< fiber::id > runnable_queue;
- typedef std::queue< fiber::id > terminated_queue;
- typedef function< void() > callable_t;
-
- fiber master_;
- fiber active_;
- container fibers_;
- runnable_queue runnable_fibers_;
- terminated_queue terminated_fibers_;
-
-public:
- scheduler_impl();
-
- ~scheduler_impl();
-
- void add( fiber);
-
- fiber::id get_id() const;
-
- void yield();
-
- void cancel();
-
- void suspend();
-
- void interrupt();
-
- bool interruption_requested();
-
- bool interruption_enabled();
-
- fiber_interrupt_t & interrupt_flags();
-
- int priority();
-
- void priority( int);
-
- void at_exit( callable_t);
-
- void interrupt( fiber::id const&);
-
- void cancel( fiber::id const&);
-
- void suspend( fiber::id const&);
-
- void resume( fiber::id const&);
-
- void join( fiber::id const&);
-
- void reschedule( fiber::id const&);
-
- bool run();
-
- bool empty();
-
- std::size_t size();
-};
-
-}}}
-
-# if defined(BOOST_MSVC)
-# pragma warning(pop)
-# endif
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_SCHEDULER_IMPL_H

Added: sandbox/fiber/boost/fiber/detail/strategy.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/strategy.hpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -0,0 +1,119 @@
+
+// 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_STRATEGY_H
+#define BOOST_FIBERS_DETAIL_STRATEGY_H
+
+#include <cstddef>
+#include <list>
+#include <map>
+#include <queue>
+
+#include <boost/function.hpp>
+#include <boost/optional.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/detail/fiber_state.hpp>
+#include <boost/fiber/fiber.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+# if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable:4251 4275)
+# endif
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+class BOOST_FIBER_DECL strategy : private noncopyable
+{
+private:
+ struct schedulable
+ {
+ fiber f;
+ std::list< fiber::id > joining_fibers;
+ optional< fiber::id > waiting_on;
+
+ schedulable() :
+ f(), joining_fibers(), waiting_on()
+ {}
+
+ schedulable( fiber f_) :
+ f( f_), joining_fibers(), waiting_on()
+ {}
+ };
+
+ typedef std::map< fiber::id, schedulable > container;
+ typedef std::list< fiber::id > runnable_queue;
+ typedef std::queue< fiber::id > terminated_queue;
+ typedef function< void() > callable_t;
+
+ fiber master_;
+ fiber active_;
+ container fibers_;
+ runnable_queue runnable_fibers_;
+ terminated_queue terminated_fibers_;
+
+public:
+ strategy();
+
+ ~strategy();
+
+ void add( fiber);
+
+ fiber::id get_id() const;
+
+ void yield();
+
+ void cancel();
+
+ void suspend();
+
+ void interrupt();
+
+ bool interruption_requested();
+
+ bool interruption_enabled();
+
+ fiber_interrupt_t & interrupt_flags();
+
+ int priority();
+
+ void priority( int);
+
+ void at_exit( callable_t);
+
+ void interrupt( fiber::id const&);
+
+ void cancel( fiber::id const&);
+
+ void suspend( fiber::id const&);
+
+ void resume( fiber::id const&);
+
+ void join( fiber::id const&);
+
+ void reschedule( fiber::id const&);
+
+ bool run();
+
+ bool empty();
+
+ std::size_t size();
+};
+
+}}}
+
+# if defined(BOOST_MSVC)
+# pragma warning(pop)
+# endif
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBERS_DETAIL_STRATEGY_H

Modified: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/fiber.hpp (original)
+++ sandbox/fiber/boost/fiber/fiber.hpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -32,30 +32,27 @@
 namespace fibers {
 namespace detail {
 
-class scheduler_impl;
+class strategy;
 
 }
 
-class disable_interruption;
-class restore_interruption;
-
 #define BOOST_FIBER_DEFAULT_STACKSIZE 64000
 
 class BOOST_FIBER_DECL fiber
 {
 private:
- friend class detail::scheduler_impl;
- friend class disable_interruption;
- friend class restore_interruption;
+ friend class detail::strategy;
 
         struct dummy;
 
- detail::fiber_info_base::ptr_t info_;
+ detail::fiber_info_base::ptr_t info_base_;
 
         explicit fiber( detail::fiber_info_base::ptr_t);
 
         void init_();
 
+ detail::fiber_info_base::ptr_t info_() const;
+
         void switch_to_( fiber &);
 
 #ifdef BOOST_HAS_RVALUE_REFS
@@ -99,11 +96,11 @@
 #ifdef BOOST_HAS_RVALUE_REFS
         template< typename Fn >
         fiber( Fn && fn) :
- info_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, static_cast< Fn && >( fn) ) )
+ info_base_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, static_cast< Fn && >( fn) ) )
         { init_(); }
 
         fiber( std::size_t stack_size, Fn && fn) :
- info_( make_info_( stack_size, static_cast< Fn && >( fn) ) )
+ info_base_( make_info_( stack_size, static_cast< Fn && >( fn) ) )
         { init_(); }
 
         fiber( fiber &&);
@@ -115,36 +112,36 @@
 #ifdef BOOST_NO_SFINAE
         template< typename Fn >
         explicit fiber( Fn fn) :
- info_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, fn) )
+ info_base_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, fn) )
         { init_(); }
 
         template< typename Fn >
         explicit fiber( std::size_t stack_size, Fn fn) :
- info_( make_info_( stack_size, fn) )
+ info_base_( make_info_( stack_size, fn) )
         { init_(); }
 #else
         template< typename Fn >
         explicit fiber(
                         Fn fn,
                         typename disable_if< boost::is_convertible< Fn &, boost::detail::fiber_move_t< Fn > >, dummy * >::type = 0) :
- info_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, fn) )
+ info_base_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, fn) )
         { init_(); }
 
         template< typename Fn >
         explicit fiber(
                         std::size_t stack_size, Fn fn,
                         typename disable_if< boost::is_convertible< Fn &, boost::detail::fiber_move_t< Fn > >, dummy * >::type = 0) :
- info_( make_info_( stack_size, fn) )
+ info_base_( make_info_( stack_size, fn) )
         { init_(); }
 #endif
         template< typename Fn >
         explicit fiber( boost::detail::fiber_move_t< Fn > fn) :
- info_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, fn) )
+ info_base_( make_info_( BOOST_FIBER_DEFAULT_STACKSIZE, fn) )
         { init_(); }
 
         template< typename Fn >
         explicit fiber( std::size_t stack_size, boost::detail::fiber_move_t< Fn > fn) :
- info_( make_info_( stack_size, fn) )
+ info_base_( make_info_( stack_size, fn) )
         { init_(); }
 
         fiber( boost::detail::fiber_move_t< fiber >);
@@ -163,14 +160,14 @@
 #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_( \
+ info_base_( \
                         make_info_( \
                                 BOOST_FIBER_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_( \
+ info_base_( \
                         make_info_( \
                                 stack_size, \
                                 boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a)) ) ) \

Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -17,7 +17,7 @@
 
 #include <boost/fiber/detail/config.hpp>
 #include <boost/fiber/detail/fiber_state.hpp>
-#include <boost/fiber/detail/scheduler_impl.hpp>
+#include <boost/fiber/detail/strategy.hpp>
 #include <boost/fiber/fiber.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -74,7 +74,7 @@
         friend class disable_interruption;
         friend class restore_interruption;
 
- typedef thread_specific_ptr< detail::scheduler_impl > impl_t;
+ typedef thread_specific_ptr< detail::strategy > impl_t;
         typedef function< void() > callable_t;
 
         static impl_t impl_;
@@ -117,7 +117,7 @@
 
         static void reschedule( fiber::id const&);
 
- detail::scheduler_impl * access_();
+ detail::strategy * access_();
 
 public:
         ~scheduler();

Modified: sandbox/fiber/libs/fiber/build/Jamfile.v2
==============================================================================
--- sandbox/fiber/libs/fiber/build/Jamfile.v2 (original)
+++ sandbox/fiber/libs/fiber/build/Jamfile.v2 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -50,7 +50,7 @@
         manual_reset_event.cpp
         mutex.cpp
         scheduler.cpp
- scheduler_impl.cpp
+ strategy.cpp
     : ## requirements ##
       <fiberapi>win32
     ;
@@ -66,7 +66,7 @@
         manual_reset_event.cpp
         mutex.cpp
         scheduler.cpp
- scheduler_impl.cpp
+ strategy.cpp
     : ## requirements ##
       <fiberapi>posix
     ;

Modified: sandbox/fiber/libs/fiber/src/fiber.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber.cpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -27,22 +27,22 @@
 #endif
 
 fiber::fiber() :
- info_()
+ info_base_()
 {}
 
-fiber::fiber( detail::fiber_info_base::ptr_t info) :
- info_( info)
+fiber::fiber( detail::fiber_info_base::ptr_t info_base) :
+ info_base_( info_base)
 {}
 
 #ifdef BOOST_HAS_RVALUE_REFS
 fiber::fiber( fiber && other)
-{ info_.swap( other.info_); }
+{ info_base_.swap( other.info_base_); }
 
 fiber &
 fiber::operator=( fiber && other)
 {
- info_ = other.info_;
- other.info_.reset();
+ info_base_ = other.info_base_;
+ other.info_base_.reset();
         return * this;
 }
 
@@ -52,8 +52,8 @@
 #else
 fiber::fiber( boost::detail::fiber_move_t< fiber > f)
 {
- info_ = f->info_;
- f->info_.reset();
+ info_base_ = f->info_base_;
+ f->info_base_.reset();
 }
 
 fiber &
@@ -74,12 +74,17 @@
         return f;
 }
 #endif
+
+detail::fiber_info_base::ptr_t
+fiber::info_() const
+{ return info_base_; }
+
 fiber::operator unspecified_bool_type() const
-{ return info_; }
+{ return info_base_; }
 
 bool
 fiber::operator!() const
-{ return ! info_; }
+{ return ! info_base_; }
 
 bool
 fiber::operator==( fiber const& other) const
@@ -91,73 +96,73 @@
 
 void
 fiber::swap( fiber & other)
-{ info_.swap( other.info_); }
+{ info_base_.swap( other.info_base_); }
 
 fiber::id
 fiber::get_id() const
-{ return fiber::id( info_); }
+{ return fiber::id( info_base_); }
 
 bool
 fiber::is_alive() const
 {
- if ( ! info_) throw fiber_moved();
- return ( info_->state & IS_ALIVE_BIT_MASK) != 0;
+ if ( ! info_base_) throw fiber_moved();
+ return ( info_base_->state & IS_ALIVE_BIT_MASK) != 0;
 }
 
 int
 fiber::priority() const
 {
- if ( ! info_) throw fiber_moved();
- return info_->priority;
+ if ( ! info_base_) throw fiber_moved();
+ return info_base_->priority;
 }
 
 void
 fiber::priority( int prio)
 {
- if ( ! info_) throw fiber_moved();
- info_->priority = prio;
+ if ( ! info_base_) throw fiber_moved();
+ info_base_->priority = prio;
         if ( is_alive() ) scheduler::reschedule( get_id() );
 }
 
 void
 fiber::interrupt()
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
         scheduler::interrupt( get_id() );
 }
 
 bool
 fiber::interruption_requested() const
 {
- if ( ! info_) throw fiber_moved();
- return ( info_->interrupt & detail::INTERRUPTION_ENABLED) != 0;
+ if ( ! info_base_) throw fiber_moved();
+ return ( info_base_->interrupt & detail::INTERRUPTION_ENABLED) != 0;
 }
 
 void
 fiber::cancel()
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
         scheduler::cancel( get_id() );
 }
 
 void
 fiber::suspend()
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
         scheduler::suspend( get_id() );
 }
 
 void
 fiber::resume()
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
         scheduler::resume( get_id() );
 }
 
 void
 fiber::join()
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
         scheduler::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-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -48,21 +48,21 @@
         typedef void ( * st_fn)();
         fn_type * fn_ptr( trampoline);
 
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
 
         ::makecontext(
- & info_->uctx,
+ & info_base_->uctx,
                 ( st_fn)( fn_ptr),
                 1,
- info_.get() );
+ info_base_.get() );
 }
 
 void
 fiber::switch_to_( fiber & to)
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
 
- if ( ::swapcontext( & info_->uctx, & to.info_->uctx) != 0)
+ if ( ::swapcontext( & info_base_->uctx, & to.info_base_->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-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -46,20 +46,20 @@
 void
 fiber::init_()
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
 
- info_->uctx = ::CreateFiber(
+ info_base_->uctx = ::CreateFiber(
                 info_->stack_size,
                 static_cast< LPFIBER_START_ROUTINE >( & trampoline),
- static_cast< LPVOID >( info_.get() ) );
+ static_cast< LPVOID >( info_base_.get() ) );
 }
 
 void
 fiber::switch_to_( fiber & to)
 {
- if ( ! info_) throw fiber_moved();
+ if ( ! info_base_) throw fiber_moved();
 
- ::SwitchToFiber( to.info_->uctx);
+ ::SwitchToFiber( to.info_base_->uctx);
 }
 
 void

Modified: sandbox/fiber/libs/fiber/src/scheduler.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/scheduler.cpp (original)
+++ sandbox/fiber/libs/fiber/src/scheduler.cpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -7,7 +7,7 @@
 #include <boost/fiber/scheduler.hpp>
 
 #include <boost/fiber/detail/move.hpp>
-#include <boost/fiber/detail/scheduler_impl.hpp>
+#include <boost/fiber/detail/strategy.hpp>
 #include <boost/fiber/exceptions.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -24,7 +24,7 @@
 fiber::id
 scheduler::get_id()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         return impl->get_id();
 }
@@ -32,7 +32,7 @@
 void
 scheduler::yield()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->yield();
 }
@@ -40,7 +40,7 @@
 void
 scheduler::cancel()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->cancel();
 }
@@ -48,7 +48,7 @@
 void
 scheduler::suspend()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->suspend();
 }
@@ -56,7 +56,7 @@
 void
 scheduler::interrupt()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->interrupt();
 }
@@ -64,7 +64,7 @@
 bool
 scheduler::interruption_requested()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         return impl->interruption_requested();
 }
@@ -72,7 +72,7 @@
 bool
 scheduler::interruption_enabled()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         return impl->interruption_enabled();
 }
@@ -80,7 +80,7 @@
 detail::fiber_interrupt_t &
 scheduler::interrupt_flags()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         return impl->interrupt_flags();
 }
@@ -88,7 +88,7 @@
 int
 scheduler::priority()
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         return impl->priority();
 }
@@ -96,7 +96,7 @@
 void
 scheduler::priority( int prio)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->priority( prio);
 }
@@ -104,7 +104,7 @@
 void
 scheduler::at_exit( callable_t ca)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->at_exit( ca);
 }
@@ -112,7 +112,7 @@
 void
 scheduler::interrupt( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->interrupt( id);
 }
@@ -120,7 +120,7 @@
 void
 scheduler::cancel( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->cancel( id);
 }
@@ -128,7 +128,7 @@
 void
 scheduler::suspend( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->suspend( id);
 }
@@ -136,7 +136,7 @@
 void
 scheduler::resume( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->resume( id);
 }
@@ -144,7 +144,7 @@
 void
 scheduler::join( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->join( id);
 }
@@ -152,16 +152,16 @@
 void
 scheduler::reschedule( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
+ detail::strategy * impl( impl_.get() );
         if ( ! impl) throw fiber_error("not a fiber");
         impl->reschedule( id);
 }
 
-detail::scheduler_impl *
+detail::strategy *
 scheduler::access_()
 {
         if ( ! impl_.get() )
- impl_.reset( new detail::scheduler_impl() );
+ impl_.reset( new detail::strategy() );
         return impl_.get();
 }
 

Deleted: sandbox/fiber/libs/fiber/src/scheduler_impl.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/scheduler_impl.cpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
+++ (empty file)
@@ -1,517 +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)
-
-#include <boost/fiber/detail/scheduler_impl.hpp>
-
-#include <utility>
-
-#include <boost/assert.hpp>
-#include <boost/foreach.hpp>
-
-#include <boost/fiber/detail/fiber_info.hpp>
-#include <boost/fiber/detail/move.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
-#include <boost/fiber/exceptions.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-#define HAS_STATE_MASTER( state) \
- ( state & STATE_MASTER) != 0
-
-#define HAS_STATE_NOT_STARTED( state) \
- ( state & STATE_NOT_STARTED) != 0
-
-#define HAS_STATE_READY( state) \
- ( state & STATE_READY) != 0
-
-#define HAS_STATE_RUNNING( state) \
- ( state & STATE_RUNNING) != 0
-
-#define HAS_STATE_SUSPENDED( state) \
- ( state & STATE_SUSPENDED) != 0
-
-#define HAS_STATE_WAIT_FOR_JOIN( state) \
- ( state & STATE_WAIT_FOR_JOIN) != 0
-
-#define HAS_STATE_TERMINATED( state) \
- ( state & STATE_TERMINATED) != 0
-
-scheduler_impl::scheduler_impl() :
- master_(),
- active_(),
- fibers_(),
- runnable_fibers_(),
- terminated_fibers_()
-{
- fiber::convert_thread_to_fiber();
- master_ = fiber(
- fiber_info_base::ptr_t(
- new fiber_info_default() ) );
-}
-
-scheduler_impl::~scheduler_impl()
-{ fiber::convert_fiber_to_thread(); }
-
-void
-scheduler_impl::add( fiber f)
-{
- if ( ! f) throw fiber_moved();
-
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( STATE_NOT_STARTED == f.info_->state);
-
- // set state to ready
- f.info_->state = STATE_READY;
-
- // insert fiber to fiber-list
- std::pair< std::map< fiber::id, schedulable >::iterator, bool > result(
- fibers_.insert(
- std::make_pair(
- f.get_id(),
- schedulable( f) ) ) );
-
- // check result
- if ( ! result.second) throw scheduler_error("inserting fiber failed");
-
- // put fiber to runnable-queue
- runnable_fibers_.push_back( result.first->first);
-}
-
-fiber::id
-scheduler_impl::get_id() const
-{ return active_.get_id(); }
-
-void
-scheduler_impl::yield()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- // set state ready
- active_.info_->state = STATE_READY;
-
- // put fiber to runnable-queue
- runnable_fibers_.push_back( active_.get_id() );
-
- // switch to master-fiber
- active_.switch_to_( master_);
-}
-
-void
-scheduler_impl::cancel()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- schedulable s( fibers_[active_.get_id()]);
-
- // invoke each fiber waiting on this fiber
- BOOST_FOREACH( fiber::id id__, s.joining_fibers)
- {
- schedulable s__( fibers_[id__]);
- fiber f__( s__.f);
- BOOST_ASSERT( s__.waiting_on);
- BOOST_ASSERT( active_.get_id() == * s__.waiting_on);
- BOOST_ASSERT( HAS_STATE_WAIT_FOR_JOIN( f__.info_->state) );
-
- // clear waiting-on
- fibers_[id__].waiting_on.reset();
-
- // remove wait-for-join state
- f__.info_->state &= ~STATE_WAIT_FOR_JOIN;
-
- // if fiber is in state ready or running and not suspended
- // put it on runnable-queue
- if ( ( HAS_STATE_READY( f__.info_->state) || HAS_STATE_RUNNING( f__.info_->state) )
- && ! HAS_STATE_SUSPENDED( f__.info_->state) )
- {
- f__.info_->state = STATE_READY;
- runnable_fibers_.push_back( id__);
- }
- }
- // clear waiting-queue
- fibers_[active_.get_id()].joining_fibers.clear();
-
- // set state to terminated
- active_.info_->state = STATE_TERMINATED;
-
- // put fiber to terminated-queue
- terminated_fibers_.push( active_.get_id() );
-
- // switch to master-fiber
- active_.switch_to_( master_);
-}
-
-void
-scheduler_impl::suspend()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- // set state suspended
- active_.info_->state |= STATE_SUSPENDED;
-
- // switch to master-fiber
- active_.switch_to_( master_);
-}
-
-void
-scheduler_impl::interrupt()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- // gets invoked by interruption-points
- // if interruption flag is set throw fiber_interrupted
- // exceptions
- if ( INTERRUPTION_ENABLED == active_.info_->interrupt)
- throw fiber_interrupted();
-}
-
-bool
-scheduler_impl::interruption_requested()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- return active_.interruption_requested();
-}
-
-bool
-scheduler_impl::interruption_enabled()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- return active_.info_->interrupt == detail::INTERRUPTION_ENABLED;
-}
-
-fiber_interrupt_t &
-scheduler_impl::interrupt_flags()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- return active_.info_->interrupt;
-}
-
-int
-scheduler_impl::priority()
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- return active_.priority();
-}
-
-void
-scheduler_impl::priority( int prio)
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- // set priority
- active_.priority( prio);
-}
-
-void
-scheduler_impl::at_exit( callable_t ca)
-{
- BOOST_ASSERT( STATE_RUNNING == active_.info_->state);
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- // push a exit-callback on fibers stack
- active_.info_->at_exit.push( ca);
-}
-
-void
-scheduler_impl::interrupt( fiber::id const& id)
-{
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- schedulable s( i->second);
- fiber f( s.f);
- BOOST_ASSERT( f);
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_->state) );
-
- // nothing to do for al terminated fiber
- if ( HAS_STATE_TERMINATED( f.info_->state) ) return;
-
- // remove disabled flag
- f.info_->interrupt &= ~detail::INTERRUPTION_DISABLED;
-
- // set enabled flag
- f.info_->interrupt |= detail::INTERRUPTION_ENABLED;
-
- // if fiber is waiting
- if ( HAS_STATE_WAIT_FOR_JOIN( f.info_->state) )
- {
- // fiber is waiting (joining) on another fiber
- // remove it from the waiting-queue, reset waiting-on
- // and reset the waiting state
- BOOST_ASSERT( s.waiting_on);
- fibers_[* s.waiting_on].joining_fibers.remove( id);
- fibers_[id].waiting_on.reset();
- f.info_->interrupt &= ~STATE_WAIT_FOR_JOIN;
-
- // if fiber is not suspended put it to runnable-queue
- if ( ! HAS_STATE_SUSPENDED( f.info_->state) )
- {
- BOOST_ASSERT(
- HAS_STATE_READY( f.info_->state) ||
- HAS_STATE_RUNNING( f.info_->state) );
- f.info_->state = STATE_READY;
- runnable_fibers_.push_back( id);
- }
- }
-}
-
-void
-scheduler_impl::cancel( fiber::id const& id)
-{
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- schedulable s( i->second);
- fiber f( s.f);
- BOOST_ASSERT( f);
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_->state) );
-
- // nothing to do for al terminated fiber
- if ( HAS_STATE_TERMINATED( f.info_->state) ) return;
-
- // invoke each fiber waiting on this fiber
- BOOST_FOREACH( fiber::id id__, s.joining_fibers)
- {
- schedulable s__( fibers_[id__]);
- fiber f__( s__.f);
- BOOST_ASSERT( s__.waiting_on);
- BOOST_ASSERT( HAS_STATE_WAIT_FOR_JOIN( f__.info_->state) );
-
- // clear waiting-on
- fibers_[id__].waiting_on.reset();
-
- // remove wait-for-join state
- f__.info_->state &= ~STATE_WAIT_FOR_JOIN;
-
- // if fiber is in state ready or running and not suspended
- // put it on runnable-queue
- if ( ( HAS_STATE_READY( f__.info_->state) || HAS_STATE_RUNNING( f__.info_->state) )
- && ! HAS_STATE_SUSPENDED( f__.info_->state) )
- {
- f__.info_->state = STATE_READY;
- runnable_fibers_.push_back( id__);
- }
- }
- // clear waiting-queue
- fibers_[id].joining_fibers.clear();
-
- // if fiber is ready remove it from the runnable-queue
- // and put it to terminated-queue
- if ( HAS_STATE_READY( f.info_->state) )
- {
- f.info_->state = STATE_TERMINATED;
- runnable_fibers_.remove( id);
- terminated_fibers_.push( id);
- }
- // if fiber is running (== active fiber)
- // put it to terminated-queue and switch
- // to master fiber
- else if ( HAS_STATE_RUNNING( f.info_->state) )
- {
- BOOST_ASSERT( active_.get_id() == id);
- f.info_->state = STATE_TERMINATED;
- terminated_fibers_.push( id);
- f.switch_to_( master_);
- }
- // if fiber is waiting then remove it from the
- // waiting-queue and put it to terminated-queue
- else if ( HAS_STATE_WAIT_FOR_JOIN( f.info_->state) )
- {
- BOOST_ASSERT( s.waiting_on);
- f.info_->state = STATE_TERMINATED;
- fibers_[* s.waiting_on].joining_fibers.remove( id);
- terminated_fibers_.push( id);
- }
- // suspended state is only used with one of the
- // other states
- else
- BOOST_ASSERT( ! "should never reached");
-}
-
-void
-scheduler_impl::suspend( fiber::id const& id)
-{
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- fiber f( i->second.f);
- BOOST_ASSERT( f);
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_->state) );
-
- // nothing to do for a terminated fiber
- if ( HAS_STATE_TERMINATED( f.info_->state) ) return;
-
- // if fiber is ready remove it from the
- // runnable-queue
- if ( HAS_STATE_READY( f.info_->state) )
- {
- f.info_->state |= STATE_SUSPENDED;
- runnable_fibers_.remove( id);
- }
- // if fiber is running (== active fiber)
- // switch to master-fiber
- else if ( HAS_STATE_RUNNING( f.info_->state) )
- {
- BOOST_ASSERT( active_.get_id() == id);
- f.info_->state |= STATE_SUSPENDED;
- f.switch_to_( master_);
- }
- // if fiber is in waiting state mark it only
- // as suspended
- else if ( HAS_STATE_WAIT_FOR_JOIN( f.info_->state) )
- f.info_->state |= STATE_SUSPENDED;
- else
- BOOST_ASSERT( ! "should never reached");
-}
-
-void
-scheduler_impl::resume( fiber::id const& id)
-{
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- fiber f( i->second.f);
- BOOST_ASSERT( f);
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_->state) );
-
- BOOST_ASSERT( active_.get_id() != id);
-
- // nothing to do for already terminated fiber
- if ( HAS_STATE_TERMINATED( f.info_->state) ) return;
-
- // remove suspended state an requeue fiber
- if ( HAS_STATE_SUSPENDED( f.info_->state) )
- {
- f.info_->state &= ~STATE_SUSPENDED;
- // if suspended fiber was ready or running and not waiting
- // put it to the runnable-queue
- if ( ( HAS_STATE_READY( f.info_->state) || HAS_STATE_RUNNING( f.info_->state) )
- && ! HAS_STATE_WAIT_FOR_JOIN( f.info_->state) )
- {
- f.info_->state = STATE_READY;
- runnable_fibers_.push_back( id);
- }
- }
-}
-
-void
-scheduler_impl::join( fiber::id const& id)
-{
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- schedulable s( i->second);
- fiber f( s.f);
- BOOST_ASSERT( f);
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_->state) );
-
- // nothing to do for a terminated fiber
- if ( HAS_STATE_TERMINATED( f.info_->state) ) return;
-
- // prevent self-join
- if ( active_.get_id() == id) throw scheduler_error("self-join denied");
-
- // register on fiber to be joined
- fibers_[id].joining_fibers.push_back( active_.get_id() );
-
- // set state waiting
- active_.info_->state |= STATE_WAIT_FOR_JOIN;
-
- // set fiber-id waiting-on
- fibers_[active_.get_id()].waiting_on = id;
-
- // switch to master-fiber
- active_.switch_to_( master_);
-
- // fiber was invoked
- BOOST_ASSERT( ! HAS_STATE_WAIT_FOR_JOIN( active_.info_->state) );
- BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
-
- // check if interruption was requested
- interrupt();
-}
-
-void
-scheduler_impl::reschedule( fiber::id const& id)
-{
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- fiber f( i->second.f);
- BOOST_ASSERT( f);
- BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_->state) );
- BOOST_ASSERT( ! HAS_STATE_TERMINATED( f.info_->state) );
-
- // TODO: re-schedule fiber == remove from
- // runnable_fibers + re-insert
-}
-
-bool
-scheduler_impl::run()
-{
- bool result( false);
- if ( ! runnable_fibers_.empty() )
- {
- schedulable s = fibers_[runnable_fibers_.front()];
- active_ = s.f;
- BOOST_ASSERT( ! s.waiting_on);
- BOOST_ASSERT( active_.info_->state == STATE_READY);
- active_.info_->state = STATE_RUNNING;
- master_.switch_to_( active_);
- runnable_fibers_.pop_front();
- result = true;
- }
- else
- active_.move();
-
- while ( ! terminated_fibers_.empty() )
- {
- schedulable s = fibers_[terminated_fibers_.front()];
- fiber f( s.f);
- terminated_fibers_.pop();
- BOOST_ASSERT( s.joining_fibers.empty() );
- BOOST_ASSERT( STATE_TERMINATED == f.info_->state);
- fibers_.erase( f.get_id() );
- result = true;
- }
- return result;
-}
-
-bool
-scheduler_impl::empty()
-{ return fibers_.empty(); }
-
-std::size_t
-scheduler_impl::size()
-{ return fibers_.size(); }
-
-#undef HAS_STATE_MASTER
-#undef HAS_STATE_NOT_STARTED
-#undef HAS_STATE_READY
-#undef HAS_STATE_RUNNING
-#undef HAS_STATE_SUSPENDED
-#undef HAS_STATE_WAIT_FOR_JOIN
-#undef HAS_STATE_TERMINATED
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>

Added: sandbox/fiber/libs/fiber/src/strategy.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/strategy.cpp 2009-11-19 13:36:48 EST (Thu, 19 Nov 2009)
@@ -0,0 +1,517 @@
+
+// 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)
+
+#include <boost/fiber/detail/strategy.hpp>
+
+#include <utility>
+
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp>
+
+#include <boost/fiber/detail/fiber_info.hpp>
+#include <boost/fiber/detail/move.hpp>
+#include <boost/fiber/detail/fiber_state.hpp>
+#include <boost/fiber/exceptions.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+#define HAS_STATE_MASTER( state) \
+ ( state & STATE_MASTER) != 0
+
+#define HAS_STATE_NOT_STARTED( state) \
+ ( state & STATE_NOT_STARTED) != 0
+
+#define HAS_STATE_READY( state) \
+ ( state & STATE_READY) != 0
+
+#define HAS_STATE_RUNNING( state) \
+ ( state & STATE_RUNNING) != 0
+
+#define HAS_STATE_SUSPENDED( state) \
+ ( state & STATE_SUSPENDED) != 0
+
+#define HAS_STATE_WAIT_FOR_JOIN( state) \
+ ( state & STATE_WAIT_FOR_JOIN) != 0
+
+#define HAS_STATE_TERMINATED( state) \
+ ( state & STATE_TERMINATED) != 0
+
+strategy::strategy() :
+ master_(),
+ active_(),
+ fibers_(),
+ runnable_fibers_(),
+ terminated_fibers_()
+{
+ fiber::convert_thread_to_fiber();
+ master_ = fiber(
+ fiber_info_base::ptr_t(
+ new fiber_info_default() ) );
+}
+
+strategy::~strategy()
+{ fiber::convert_fiber_to_thread(); }
+
+void
+strategy::add( fiber f)
+{
+ if ( ! f) throw fiber_moved();
+
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( STATE_NOT_STARTED == f.info_()->state);
+
+ // set state to ready
+ f.info_()->state = STATE_READY;
+
+ // insert fiber to fiber-list
+ std::pair< std::map< fiber::id, schedulable >::iterator, bool > result(
+ fibers_.insert(
+ std::make_pair(
+ f.get_id(),
+ schedulable( f) ) ) );
+
+ // check result
+ if ( ! result.second) throw scheduler_error("inserting fiber failed");
+
+ // put fiber to runnable-queue
+ runnable_fibers_.push_back( result.first->first);
+}
+
+fiber::id
+strategy::get_id() const
+{ return active_.get_id(); }
+
+void
+strategy::yield()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ // set state ready
+ active_.info_()->state = STATE_READY;
+
+ // put fiber to runnable-queue
+ runnable_fibers_.push_back( active_.get_id() );
+
+ // switch to master-fiber
+ active_.switch_to_( master_);
+}
+
+void
+strategy::cancel()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ schedulable s( fibers_[active_.get_id()]);
+
+ // invoke each fiber waiting on this fiber
+ BOOST_FOREACH( fiber::id id__, s.joining_fibers)
+ {
+ schedulable s__( fibers_[id__]);
+ fiber f__( s__.f);
+ BOOST_ASSERT( s__.waiting_on);
+ BOOST_ASSERT( active_.get_id() == * s__.waiting_on);
+ BOOST_ASSERT( HAS_STATE_WAIT_FOR_JOIN( f__.info_()->state) );
+
+ // clear waiting-on
+ fibers_[id__].waiting_on.reset();
+
+ // remove wait-for-join state
+ f__.info_()->state &= ~STATE_WAIT_FOR_JOIN;
+
+ // if fiber is in state ready or running and not suspended
+ // put it on runnable-queue
+ if ( ( HAS_STATE_READY( f__.info_()->state) || HAS_STATE_RUNNING( f__.info_()->state) )
+ && ! HAS_STATE_SUSPENDED( f__.info_()->state) )
+ {
+ f__.info_()->state = STATE_READY;
+ runnable_fibers_.push_back( id__);
+ }
+ }
+ // clear waiting-queue
+ fibers_[active_.get_id()].joining_fibers.clear();
+
+ // set state to terminated
+ active_.info_()->state = STATE_TERMINATED;
+
+ // put fiber to terminated-queue
+ terminated_fibers_.push( active_.get_id() );
+
+ // switch to master-fiber
+ active_.switch_to_( master_);
+}
+
+void
+strategy::suspend()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ // set state suspended
+ active_.info_()->state |= STATE_SUSPENDED;
+
+ // switch to master-fiber
+ active_.switch_to_( master_);
+}
+
+void
+strategy::interrupt()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ // gets invoked by interruption-points
+ // if interruption flag is set throw fiber_interrupted
+ // exceptions
+ if ( INTERRUPTION_ENABLED == active_.info_()->interrupt)
+ throw fiber_interrupted();
+}
+
+bool
+strategy::interruption_requested()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ return active_.interruption_requested();
+}
+
+bool
+strategy::interruption_enabled()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ return active_.info_()->interrupt == detail::INTERRUPTION_ENABLED;
+}
+
+fiber_interrupt_t &
+strategy::interrupt_flags()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ return active_.info_()->interrupt;
+}
+
+int
+strategy::priority()
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ return active_.priority();
+}
+
+void
+strategy::priority( int prio)
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ // set priority
+ active_.priority( prio);
+}
+
+void
+strategy::at_exit( callable_t ca)
+{
+ BOOST_ASSERT( STATE_RUNNING == active_.info_()->state);
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ // push a exit-callback on fibers stack
+ active_.info_()->at_exit.push( ca);
+}
+
+void
+strategy::interrupt( fiber::id const& id)
+{
+ container::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ schedulable s( i->second);
+ fiber f( s.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_()->state) );
+
+ // nothing to do for al terminated fiber
+ if ( HAS_STATE_TERMINATED( f.info_()->state) ) return;
+
+ // remove disabled flag
+ f.info_()->interrupt &= ~detail::INTERRUPTION_DISABLED;
+
+ // set enabled flag
+ f.info_()->interrupt |= detail::INTERRUPTION_ENABLED;
+
+ // if fiber is waiting
+ if ( HAS_STATE_WAIT_FOR_JOIN( f.info_()->state) )
+ {
+ // fiber is waiting (joining) on another fiber
+ // remove it from the waiting-queue, reset waiting-on
+ // and reset the waiting state
+ BOOST_ASSERT( s.waiting_on);
+ fibers_[* s.waiting_on].joining_fibers.remove( id);
+ fibers_[id].waiting_on.reset();
+ f.info_()->interrupt &= ~STATE_WAIT_FOR_JOIN;
+
+ // if fiber is not suspended put it to runnable-queue
+ if ( ! HAS_STATE_SUSPENDED( f.info_()->state) )
+ {
+ BOOST_ASSERT(
+ HAS_STATE_READY( f.info_()->state) ||
+ HAS_STATE_RUNNING( f.info_()->state) );
+ f.info_()->state = STATE_READY;
+ runnable_fibers_.push_back( id);
+ }
+ }
+}
+
+void
+strategy::cancel( fiber::id const& id)
+{
+ container::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ schedulable s( i->second);
+ fiber f( s.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_()->state) );
+
+ // nothing to do for al terminated fiber
+ if ( HAS_STATE_TERMINATED( f.info_()->state) ) return;
+
+ // invoke each fiber waiting on this fiber
+ BOOST_FOREACH( fiber::id id__, s.joining_fibers)
+ {
+ schedulable s__( fibers_[id__]);
+ fiber f__( s__.f);
+ BOOST_ASSERT( s__.waiting_on);
+ BOOST_ASSERT( HAS_STATE_WAIT_FOR_JOIN( f__.info_()->state) );
+
+ // clear waiting-on
+ fibers_[id__].waiting_on.reset();
+
+ // remove wait-for-join state
+ f__.info_()->state &= ~STATE_WAIT_FOR_JOIN;
+
+ // if fiber is in state ready or running and not suspended
+ // put it on runnable-queue
+ if ( ( HAS_STATE_READY( f__.info_()->state) || HAS_STATE_RUNNING( f__.info_()->state) )
+ && ! HAS_STATE_SUSPENDED( f__.info_()->state) )
+ {
+ f__.info_()->state = STATE_READY;
+ runnable_fibers_.push_back( id__);
+ }
+ }
+ // clear waiting-queue
+ fibers_[id].joining_fibers.clear();
+
+ // if fiber is ready remove it from the runnable-queue
+ // and put it to terminated-queue
+ if ( HAS_STATE_READY( f.info_()->state) )
+ {
+ f.info_()->state = STATE_TERMINATED;
+ runnable_fibers_.remove( id);
+ terminated_fibers_.push( id);
+ }
+ // if fiber is running (== active fiber)
+ // put it to terminated-queue and switch
+ // to master fiber
+ else if ( HAS_STATE_RUNNING( f.info_()->state) )
+ {
+ BOOST_ASSERT( active_.get_id() == id);
+ f.info_()->state = STATE_TERMINATED;
+ terminated_fibers_.push( id);
+ f.switch_to_( master_);
+ }
+ // if fiber is waiting then remove it from the
+ // waiting-queue and put it to terminated-queue
+ else if ( HAS_STATE_WAIT_FOR_JOIN( f.info_()->state) )
+ {
+ BOOST_ASSERT( s.waiting_on);
+ f.info_()->state = STATE_TERMINATED;
+ fibers_[* s.waiting_on].joining_fibers.remove( id);
+ terminated_fibers_.push( id);
+ }
+ // suspended state is only used with one of the
+ // other states
+ else
+ BOOST_ASSERT( ! "should never reached");
+}
+
+void
+strategy::suspend( fiber::id const& id)
+{
+ container::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ fiber f( i->second.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_()->state) );
+
+ // nothing to do for a terminated fiber
+ if ( HAS_STATE_TERMINATED( f.info_()->state) ) return;
+
+ // if fiber is ready remove it from the
+ // runnable-queue
+ if ( HAS_STATE_READY( f.info_()->state) )
+ {
+ f.info_()->state |= STATE_SUSPENDED;
+ runnable_fibers_.remove( id);
+ }
+ // if fiber is running (== active fiber)
+ // switch to master-fiber
+ else if ( HAS_STATE_RUNNING( f.info_()->state) )
+ {
+ BOOST_ASSERT( active_.get_id() == id);
+ f.info_()->state |= STATE_SUSPENDED;
+ f.switch_to_( master_);
+ }
+ // if fiber is in waiting state mark it only
+ // as suspended
+ else if ( HAS_STATE_WAIT_FOR_JOIN( f.info_()->state) )
+ f.info_()->state |= STATE_SUSPENDED;
+ else
+ BOOST_ASSERT( ! "should never reached");
+}
+
+void
+strategy::resume( fiber::id const& id)
+{
+ container::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ fiber f( i->second.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_()->state) );
+
+ BOOST_ASSERT( active_.get_id() != id);
+
+ // nothing to do for already terminated fiber
+ if ( HAS_STATE_TERMINATED( f.info_()->state) ) return;
+
+ // remove suspended state an requeue fiber
+ if ( HAS_STATE_SUSPENDED( f.info_()->state) )
+ {
+ f.info_()->state &= ~STATE_SUSPENDED;
+ // if suspended fiber was ready or running and not waiting
+ // put it to the runnable-queue
+ if ( ( HAS_STATE_READY( f.info_()->state) || HAS_STATE_RUNNING( f.info_()->state) )
+ && ! HAS_STATE_WAIT_FOR_JOIN( f.info_()->state) )
+ {
+ f.info_()->state = STATE_READY;
+ runnable_fibers_.push_back( id);
+ }
+ }
+}
+
+void
+strategy::join( fiber::id const& id)
+{
+ container::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ schedulable s( i->second);
+ fiber f( s.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_()->state) );
+
+ // nothing to do for a terminated fiber
+ if ( HAS_STATE_TERMINATED( f.info_()->state) ) return;
+
+ // prevent self-join
+ if ( active_.get_id() == id) throw scheduler_error("self-join denied");
+
+ // register on fiber to be joined
+ fibers_[id].joining_fibers.push_back( active_.get_id() );
+
+ // set state waiting
+ active_.info_()->state |= STATE_WAIT_FOR_JOIN;
+
+ // set fiber-id waiting-on
+ fibers_[active_.get_id()].waiting_on = id;
+
+ // switch to master-fiber
+ active_.switch_to_( master_);
+
+ // fiber was invoked
+ BOOST_ASSERT( ! HAS_STATE_WAIT_FOR_JOIN( active_.info_()->state) );
+ BOOST_ASSERT( ! fibers_[active_.get_id()].waiting_on);
+
+ // check if interruption was requested
+ interrupt();
+}
+
+void
+strategy::reschedule( fiber::id const& id)
+{
+ container::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ fiber f( i->second.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_NOT_STARTED( f.info_()->state) );
+ BOOST_ASSERT( ! HAS_STATE_TERMINATED( f.info_()->state) );
+
+ // TODO: re-schedule fiber == remove from
+ // runnable_fibers + re-insert
+}
+
+bool
+strategy::run()
+{
+ bool result( false);
+ if ( ! runnable_fibers_.empty() )
+ {
+ schedulable s = fibers_[runnable_fibers_.front()];
+ active_ = s.f;
+ BOOST_ASSERT( ! s.waiting_on);
+ BOOST_ASSERT( active_.info_()->state == STATE_READY);
+ active_.info_()->state = STATE_RUNNING;
+ master_.switch_to_( active_);
+ runnable_fibers_.pop_front();
+ result = true;
+ }
+ else
+ active_.move();
+
+ while ( ! terminated_fibers_.empty() )
+ {
+ schedulable s = fibers_[terminated_fibers_.front()];
+ fiber f( s.f);
+ terminated_fibers_.pop();
+ BOOST_ASSERT( s.joining_fibers.empty() );
+ BOOST_ASSERT( STATE_TERMINATED == f.info_()->state);
+ fibers_.erase( f.get_id() );
+ result = true;
+ }
+ return result;
+}
+
+bool
+strategy::empty()
+{ return fibers_.empty(); }
+
+std::size_t
+strategy::size()
+{ return fibers_.size(); }
+
+#undef HAS_STATE_MASTER
+#undef HAS_STATE_NOT_STARTED
+#undef HAS_STATE_READY
+#undef HAS_STATE_RUNNING
+#undef HAS_STATE_SUSPENDED
+#undef HAS_STATE_WAIT_FOR_JOIN
+#undef HAS_STATE_TERMINATED
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>


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