|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57481 - in sandbox/fiber: boost/fiber boost/fiber/detail libs/fiber/build libs/fiber/src libs/fiber/test
From: oliver.kowalke_at_[hidden]
Date: 2009-11-08 04:16:54
Author: olli
Date: 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
New Revision: 57481
URL: http://svn.boost.org/trac/boost/changeset/57481
Log:
- removed scheduler_data
- new interface policy
- policy implementation round-robin added
- fiber move into namesapce fiber
- attributes with priority
Added:
sandbox/fiber/boost/fiber/fiber.hpp (contents, props changed)
sandbox/fiber/boost/fiber/policy.hpp (contents, props changed)
sandbox/fiber/boost/fiber/rrp.hpp (contents, props changed)
sandbox/fiber/libs/fiber/src/rrp.cpp (contents, props changed)
Removed:
sandbox/fiber/boost/fiber/detail/fiber.hpp
sandbox/fiber/boost/fiber/detail/scheduler_data.hpp
Text files modified:
sandbox/fiber/boost/fiber/attributes.hpp | 7 +++
sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp | 41 +++++++++++++++++++-
sandbox/fiber/boost/fiber/scheduler.hpp | 35 +++++++++--------
sandbox/fiber/boost/fiber/utility.hpp | 10 +++-
sandbox/fiber/libs/fiber/build/Jamfile.v2 | 2 +
sandbox/fiber/libs/fiber/src/attributes.cpp | 17 ++++++--
sandbox/fiber/libs/fiber/src/fiber.cpp | 13 ++----
sandbox/fiber/libs/fiber/src/fiber_posix.cpp | 5 +-
sandbox/fiber/libs/fiber/src/scheduler.cpp | 77 ++++++++++++---------------------------
sandbox/fiber/libs/fiber/test/test_fiber.cpp | 12 +++---
10 files changed, 122 insertions(+), 97 deletions(-)
Modified: sandbox/fiber/boost/fiber/attributes.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/attributes.hpp (original)
+++ sandbox/fiber/boost/fiber/attributes.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -20,13 +20,18 @@
{
private:
std::size_t stacksize_;
+ std::size_t priority_;
public:
attributes();
- void stack_size( std::size_t stacksize);
+ void stack_size( std::size_t);
std::size_t stack_size() const;
+
+ void priority( std::size_t);
+
+ std::size_t priority() const;
};
}}
Deleted: sandbox/fiber/boost/fiber/detail/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
+++ (empty file)
@@ -1,160 +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_FIBER_H
-#define BOOST_FIBER_DETAIL_FIBER_H
-
-#include <iostream>
-
-#include <boost/bind.hpp>
-#include <boost/preprocessor/repetition.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/fiber/attributes.hpp>
-#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_info.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fiber {
-namespace detail {
-
-class fiber;
-void trampoline( fiber * fib);
-
-class BOOST_FIBER_DECL fiber : private noncopyable
-{
-private:
- friend void trampoline( fiber *);
-
- fiber_info_base::sptr_t info;
-
- fiber( fiber &);
- fiber & operator=( fiber const&);
-
- explicit fiber( fiber_info_base::sptr_t);
-
- void init();
-
- template< typename Fn >
- static inline fiber_info_base::sptr_t make_info( Fn fn, attributes const& attribs)
- { return fiber_info_base::sptr_t( new fiber_info< Fn >( fn, attribs) ); }
-
- struct dummy;
-
-public:
- class id;
-
- static void convert_thread_to_fiber();
-
- fiber();
-
- template< typename Fn >
- explicit fiber( Fn fn, attributes const& attribs) :
- info( make_info( fn, attribs) )
- { init(); }
-
-#ifndef BOOST_FIBER_MAX_ARITY
-#define BOOST_FIBER_MAX_ARITY 10
-#endif
-
-#define BOOST_FIBER_ARG(z, n, unused) \
- BOOST_PP_CAT(A, n) BOOST_PP_CAT(a, n)
-#define BOOST_ENUM_FIBER_ARGS(n) BOOST_PP_ENUM(n, BOOST_FIBER_ARG, ~)
-
-#define BOOST_FIBER_CTOR(z, n, unused) \
- template< \
- typename Fn, \
- BOOST_PP_ENUM_PARAMS(n, typename A) \
- > \
- fiber( Fn fn, attributes const& attribs, BOOST_ENUM_FIBER_ARGS(n)) : \
- info( \
- make_info( \
- boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a) ), \
- attribs) ) \
- { init(); }
-
-BOOST_PP_REPEAT_FROM_TO( 1, BOOST_FIBER_MAX_ARITY, BOOST_FIBER_CTOR, ~)
-
-#undef BOOST_FIBER_CTOR
-#undef BOOST_FIBER_MAX_ARITY
-
- ~fiber();
-
- void swap( fiber & other);
-
- id get_id() const;
-
- bool operator==( fiber const& other) const;
- bool operator!=( fiber const& other) const;
-
- void switch_to( fiber &);
-};
-
-class fiber::id
-{
-private:
- friend class fiber;
-
- fiber_info_base::sptr_t info;
-
- explicit id( fiber_info_base::sptr_t info_) :
- info( info_)
- {}
-
-public:
- id() :
- info()
- {}
-
- bool operator==( id const& other) const
- { return info == other.info; }
-
- bool operator!=( id const& other) const
- { return info != other.info; }
-
- bool operator<( id const& other) const
- { return info < other.info; }
-
- bool operator>( id const& other) const
- { return other.info < info; }
-
- bool operator<=( id const& other) const
- { return !( other.info < info); }
-
- bool operator>=( id const& other) const
- { return ! ( info < other.info); }
-
- template< typename charT, class traitsT >
- friend std::basic_ostream< charT, traitsT > &
- operator<<( std::basic_ostream< charT, traitsT > & os, id const& other)
- {
- if ( other.info)
- return os << other.info;
- else
- return os << "{not-a-fiber}";
- }
-};
-
-void trampoline( fiber *);
-
-}
-
-typedef detail::fiber::id id;
-
-}
-
-inline
-void swap( fiber::detail::fiber & lhs, fiber::detail::fiber & rhs)
-{ return lhs.swap( rhs); }
-
-}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBER_DETAIL_FIBER_H
-
Modified: sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp (original)
+++ sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -13,8 +13,10 @@
}
+#include <boost/config.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/intrusive_ptr.hpp>
#include <boost/shared_array.hpp>
-#include <boost/shared_ptr.hpp>
#include <boost/fiber/attributes.hpp>
#include <boost/fiber/detail/config.hpp>
@@ -27,8 +29,9 @@
struct BOOST_FIBER_DECL fiber_info_base
{
- typedef shared_ptr< fiber_info_base > sptr_t;
+ typedef intrusive_ptr< fiber_info_base > ptr_t;
+ uint32_t use_count;
attributes attribs;
::ucontext_t uctx;
shared_array< char > uctx_stack;
@@ -40,9 +43,41 @@
virtual ~fiber_info_base() {}
virtual void run() = 0;
+
+#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
+
+ inline friend void intrusive_ptr_add_ref( fiber_info_base * p)
+ { ++p->use_count; }
+
+ inline friend void intrusive_ptr_release( fiber_info_base * p)
+ { if ( --p->use_count == 0) delete p; }
+
+#else
+
+ void add_ref()
+ { ++use_count_; }
+
+ void release()
+ { if ( --use_count_ == 0) delete this; }
+
+#endif
};
-}}}
+}}
+
+#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
+
+inline
+void intrusive_ptr_add_ref( fiber::detail::fiber_info_base * p)
+{ p->add_ref(); }
+
+inline
+void intrusive_ptr_release( fiber::detail::fiber_info_base * p)
+{ p->release(); }
+
+#endif
+
+}
#include <boost/config/abi_suffix.hpp>
Deleted: sandbox/fiber/boost/fiber/detail/scheduler_data.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/scheduler_data.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
+++ (empty file)
@@ -1,46 +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_SCHEDULER_DATA_H
-#define BOOST_FIBER_DETAIL_SCHEDULER_DATA_H
-
-#include <memory>
-#include <queue>
-#include <utility>
-
-#include <boost/ptr_container/ptr_map.hpp>
-
-#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fiber {
-namespace detail {
-
-struct BOOST_FIBER_DECL scheduler_data
-{
- fiber master;
- fiber::id f_id;
- ptr_map< fiber::id, fiber > fibers;
- std::queue< fiber::id > runnable_fibers;
- std::queue< fiber::id > dead_fibers;
-
- scheduler_data() :
- master(),
- f_id(),
- fibers(),
- runnable_fibers(),
- dead_fibers()
- {}
-};
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBER_DETAIL_SCHEDULER_DATA_H
Added: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/fiber.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -0,0 +1,153 @@
+
+// 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_FIBER_H
+#define BOOST_FIBER_FIBER_H
+
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/preprocessor/repetition.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/fiber/attributes.hpp>
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/detail/fiber_info.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+class fiber;
+void trampoline( fiber * fib);
+
+class BOOST_FIBER_DECL fiber : private noncopyable
+{
+private:
+ friend void trampoline( fiber *);
+
+ detail::fiber_info_base::ptr_t info;
+
+ fiber( fiber &);
+ fiber & operator=( fiber const&);
+
+ void init();
+
+ template< typename Fn >
+ static inline detail::fiber_info_base::ptr_t make_info( Fn fn, attributes const& attribs)
+ { return detail::fiber_info_base::ptr_t( new detail::fiber_info< Fn >( fn, attribs) ); }
+
+ struct dummy;
+
+public:
+ class id;
+
+ static void convert_thread_to_fiber();
+
+ fiber();
+
+ template< typename Fn >
+ explicit fiber( Fn fn, attributes const& attribs) :
+ info( make_info( fn, attribs) )
+ { init(); }
+
+#ifndef BOOST_FIBER_MAX_ARITY
+#define BOOST_FIBER_MAX_ARITY 10
+#endif
+
+#define BOOST_FIBER_ARG(z, n, unused) \
+ BOOST_PP_CAT(A, n) BOOST_PP_CAT(a, n)
+#define BOOST_ENUM_FIBER_ARGS(n) BOOST_PP_ENUM(n, BOOST_FIBER_ARG, ~)
+
+#define BOOST_FIBER_CTOR(z, n, unused) \
+ template< \
+ typename Fn, \
+ BOOST_PP_ENUM_PARAMS(n, typename A) \
+ > \
+ fiber( Fn fn, attributes const& attribs, BOOST_ENUM_FIBER_ARGS(n)) : \
+ info( \
+ make_info( \
+ boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a) ), \
+ attribs) ) \
+ { init(); }
+
+BOOST_PP_REPEAT_FROM_TO( 1, BOOST_FIBER_MAX_ARITY, BOOST_FIBER_CTOR, ~)
+
+#undef BOOST_FIBER_CTOR
+#undef BOOST_FIBER_MAX_ARITY
+
+ ~fiber();
+
+ void swap( fiber & other);
+
+ id get_id() const;
+
+ bool operator==( fiber const& other) const;
+ bool operator!=( fiber const& other) const;
+
+ void switch_to( fiber &);
+};
+
+class fiber::id
+{
+private:
+ friend class fiber;
+
+ detail::fiber_info_base::ptr_t info;
+
+ explicit id( detail::fiber_info_base::ptr_t info_) :
+ info( info_)
+ {}
+
+public:
+ id() :
+ info()
+ {}
+
+ bool operator==( id const& other) const
+ { return info == other.info; }
+
+ bool operator!=( id const& other) const
+ { return info != other.info; }
+
+ bool operator<( id const& other) const
+ { return info < other.info; }
+
+ bool operator>( id const& other) const
+ { return other.info < info; }
+
+ bool operator<=( id const& other) const
+ { return !( other.info < info); }
+
+ bool operator>=( id const& other) const
+ { return ! ( info < other.info); }
+
+ template< typename charT, class traitsT >
+ friend std::basic_ostream< charT, traitsT > &
+ operator<<( std::basic_ostream< charT, traitsT > & os, id const& other)
+ {
+ if ( other.info)
+ return os << other.info;
+ else
+ return os << "{not-a-fiber}";
+ }
+};
+
+void trampoline( fiber *);
+
+}
+
+inline
+void swap( fiber::fiber & lhs, fiber::fiber & rhs)
+{ return lhs.swap( rhs); }
+
+}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_FIBER_H
+
Added: sandbox/fiber/boost/fiber/policy.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/policy.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -0,0 +1,44 @@
+
+// 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_POLICY_H
+#define BOOST_FIBER_POLICY_H
+
+#include <cstddef>
+#include <memory>
+
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/fiber.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+struct BOOST_FIBER_DECL policy
+{
+ virtual ~policy() {}
+
+ virtual void add_fiber( std::auto_ptr< fiber >) = 0;
+
+ virtual fiber::id active_fiber() = 0;
+
+ virtual void yield_active_fiber() = 0;
+
+ virtual void exit_active_fiber() = 0;
+
+ virtual bool run() = 0;
+
+ virtual bool empty() = 0;
+
+ virtual std::size_t size() = 0;
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_POLICY_H
Added: sandbox/fiber/boost/fiber/rrp.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/rrp.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -0,0 +1,58 @@
+
+// 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_RRP_H
+#define BOOST_FIBER_RRP_H
+
+#include <cstddef>
+#include <memory>
+#include <queue>
+
+#include <boost/ptr_container/ptr_map.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/fiber.hpp>
+#include <boost/fiber/policy.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+class BOOST_FIBER_DECL rrp : private noncopyable,
+ public policy
+{
+private:
+ fiber master_;
+ fiber::id f_id_;
+ ptr_map< fiber::id, fiber > fibers_;
+ std::queue< fiber::id > runnable_fibers_;
+ std::queue< fiber::id > dead_fibers_;
+
+public:
+ rrp();
+
+ void add_fiber( std::auto_ptr< fiber >);
+
+ fiber::id active_fiber();
+
+ void yield_active_fiber();
+
+ void exit_active_fiber();
+
+ bool run();
+
+ bool empty();
+
+ std::size_t size();
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_RRP_H
Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -16,8 +16,9 @@
#include <boost/fiber/attributes.hpp>
#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber.hpp>
-#include <boost/fiber/detail/scheduler_data.hpp>
+#include <boost/fiber/fiber.hpp>
+#include <boost/fiber/policy.hpp>
+#include <boost/fiber/rrp.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -25,7 +26,8 @@
namespace this_fiber {
-fiber::id get_id();
+bool runs_as_fiber();
+fiber::fiber::id get_id();
void yield();
}
@@ -35,13 +37,16 @@
class BOOST_FIBER_DECL scheduler : private noncopyable
{
private:
- friend void detail::trampoline( detail::fiber *);
- friend id this_fiber::get_id();
+ friend void trampoline( fiber *);
+ friend bool this_fiber::runs_as_fiber();
+ friend fiber::id this_fiber::get_id();
friend void this_fiber::yield();
- typedef thread_specific_ptr< detail::scheduler_data > data_ptr_t;
+ typedef thread_specific_ptr< policy > policy_ptr_t;
- static data_ptr_t data;
+ static policy_ptr_t policy_;
+
+ static bool runs_as_fiber();
static fiber::id get_id();
@@ -49,9 +54,7 @@
static void exit();
- detail::scheduler_data * access_data();
-
- void add( std::auto_ptr< detail::fiber >);
+ policy * access_();
public:
scheduler();
@@ -59,9 +62,9 @@
template< typename Fn >
void make_fiber( Fn fn, attributes attrs = attributes() )
{
- add(
- std::auto_ptr< detail::fiber >(
- new detail::fiber( fn, attrs) ) );
+ access_()->add_fiber(
+ std::auto_ptr< fiber >(
+ new fiber( fn, attrs) ) );
}
#ifndef BOOST_FIBER_MAX_ARITY
@@ -79,9 +82,9 @@
> \
void make_fiber( Fn fn, attributes const& attribs, BOOST_ENUM_FIBER_ARGS(n)) \
{ \
- add( \
- std::auto_ptr< detail::fiber >( \
- new detail::fiber( \
+ access_()->add_fiber( \
+ std::auto_ptr< fiber >( \
+ new fiber( \
boost::bind( \
boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a) ), \
attribs) ) ); \
Modified: sandbox/fiber/boost/fiber/utility.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/utility.hpp (original)
+++ sandbox/fiber/boost/fiber/utility.hpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -11,7 +11,7 @@
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/thread/thread_time.hpp>
-#include <boost/fiber/detail/fiber.hpp>
+#include <boost/fiber/fiber.hpp>
#include <boost/fiber/scheduler.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -20,7 +20,11 @@
namespace this_fiber {
inline
-fiber::id get_id()
+bool runs_as_fiber()
+{ return fiber::scheduler::runs_as_fiber(); }
+
+inline
+fiber::fiber::id get_id()
{ return fiber::scheduler::get_id(); }
inline
@@ -39,4 +43,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_THIS_FIBER_UTILITY_H
\ No newline at end of file
+#endif // BOOST_THIS_FIBER_UTILITY_H
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-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -39,6 +39,7 @@
fiber.cpp
fiber_info_windows.cpp
fiber_windows.cpp
+ rrp.cpp
scheduler.cpp
: ## requirements ##
<fiberapi>win32
@@ -50,6 +51,7 @@
fiber.cpp
fiber_info_posix.cpp
fiber_posix.cpp
+ rrp.cpp
scheduler.cpp
: ## requirements ##
<fiberapi>posix
Modified: sandbox/fiber/libs/fiber/src/attributes.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/attributes.cpp (original)
+++ sandbox/fiber/libs/fiber/src/attributes.cpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -14,21 +14,30 @@
namespace fiber {
attributes::attributes() :
- stacksize_( 64000)
+ stacksize_( 64000),
+ priority_( 0)
{}
void
-attributes::stack_size( std::size_t stacksize)
+attributes::stack_size( std::size_t value)
{
- if ( stacksize < 1)
+ if ( value < 1)
throw std::invalid_argument("invalid stacksize");
- stacksize_ = stacksize;
+ stacksize_ = value;
}
std::size_t
attributes::stack_size() const
{ return stacksize_; }
+void
+attributes::priority( std::size_t value)
+{ priority_ = value; }
+
+std::size_t
+attributes::priority() const
+{ return priority_; }
+
}}
#include <boost/config/abi_suffix.hpp>
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-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -4,7 +4,9 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#include <boost/fiber/detail/fiber.hpp>
+#include <boost/fiber/fiber.hpp>
+
+#include <algorithm>
#include <boost/assert.hpp>
@@ -14,18 +16,13 @@
namespace boost {
namespace fiber {
-namespace detail {
void
fiber::convert_thread_to_fiber()
{}
fiber::fiber() :
- info( new fiber_info_default() )
-{}
-
-fiber::fiber( fiber_info_base::sptr_t info_) :
- info( info_)
+ info( new detail::fiber_info_default() )
{}
fiber::~fiber()
@@ -55,7 +52,7 @@
scheduler::exit();
}
-}}}
+}}
#include <boost/config/abi_suffix.hpp>
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-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -4,7 +4,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#include <boost/fiber/detail/fiber.hpp>
+#include <boost/fiber/fiber.hpp>
extern "C" {
@@ -20,7 +20,6 @@
namespace boost {
namespace fiber {
-namespace detail {
void
fiber::init()
@@ -46,7 +45,7 @@
system::system_category) );
}
-}}}
+}}
#include <boost/config/abi_suffix.hpp>
Added: sandbox/fiber/libs/fiber/src/rrp.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/rrp.cpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -0,0 +1,83 @@
+
+// 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/rrp.hpp>
+
+#include <utility>
+
+#include <boost/fiber/exceptions.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+rrp::rrp() :
+ master_(),
+ f_id_(),
+ fibers_(),
+ runnable_fibers_(),
+ dead_fibers_()
+{}
+
+void
+rrp::add_fiber( std::auto_ptr< fiber > f)
+{
+ fiber::id id( f->get_id() );
+ std::pair< ptr_map< fiber::id, fiber >::iterator, bool > result(
+ fibers_.insert( id, f) );
+ if ( ! result.second) throw scheduler_error("inserting fiber failed");
+ runnable_fibers_.push( result.first->first);
+}
+
+fiber::id
+rrp::active_fiber()
+{ return f_id_; }
+
+void
+rrp::yield_active_fiber()
+{
+ runnable_fibers_.push( f_id_);
+ fibers_[f_id_].switch_to( master_);
+}
+
+void
+rrp::exit_active_fiber()
+{
+ dead_fibers_.push( f_id_);
+ fibers_[f_id_].switch_to( master_);
+}
+
+bool
+rrp::run()
+{
+ if ( ! runnable_fibers_.empty() )
+ {
+ f_id_ = runnable_fibers_.front();
+ master_.switch_to( fibers_[f_id_]);
+ runnable_fibers_.pop();
+ return true;
+ }
+ if ( ! dead_fibers_.empty() )
+ {
+ fibers_.erase( dead_fibers_.front() );
+ dead_fibers_.pop();
+ return true;
+ }
+ return false;
+}
+
+bool
+rrp::empty()
+{ return fibers_.empty(); }
+
+std::size_t
+rrp::size()
+{ return fibers_.size(); }
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
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-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -6,98 +6,69 @@
#include <boost/fiber/scheduler.hpp>
-#include <boost/assert.hpp>
-#include <boost/ptr_container/ptr_map.hpp>
-
#include <boost/fiber/exceptions.hpp>
+#include <boost/fiber/rrp.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
namespace fiber {
-scheduler::data_ptr_t scheduler::data;
+scheduler::policy_ptr_t scheduler::policy_;
+
+bool
+scheduler::runs_as_fiber()
+{ return policy_.get() != 0; }
fiber::id
scheduler::get_id()
{
- detail::scheduler_data * dt( data.get() );
- if ( ! dt) throw fiber_error("not a fiber");
- return dt->f_id;
+ policy * po( policy_.get() );
+ if ( ! po) throw fiber_error("not a fiber");
+ return po->active_fiber();
}
void
scheduler::yield()
{
- detail::scheduler_data * dt( data.get() );
- if ( ! dt) throw fiber_error("not a fiber");
- dt->runnable_fibers.push( dt->f_id);
- dt->fibers[dt->f_id].switch_to( dt->master);
+ policy * po( policy_.get() );
+ if ( ! po) throw fiber_error("not a fiber");
+ po->yield_active_fiber();
}
void
scheduler::exit()
{
- detail::scheduler_data * dt( data.get() );
- if ( ! dt) throw fiber_error("not a fiber");
- dt->dead_fibers.push( dt->f_id);
- dt->fibers[dt->f_id].switch_to( dt->master);
+ policy * po( policy_.get() );
+ if ( ! po) throw fiber_error("not a fiber");
+ po->exit_active_fiber();
}
scheduler::scheduler()
{}
-detail::scheduler_data *
-scheduler::access_data()
+policy *
+scheduler::access_()
{
- if ( ! data.get() )
+ if ( ! policy_.get() )
{
- detail::fiber::convert_thread_to_fiber();
- data.reset( new detail::scheduler_data() );
+ fiber::convert_thread_to_fiber();
+ policy_.reset( new rrp() );
}
- return data.get();
-}
-
-void
-scheduler::add( std::auto_ptr< detail::fiber > f)
-{
- detail::scheduler_data * dt = access_data();
-
- detail::fiber::id id( f->get_id() );
- std::pair< ptr_map< detail::fiber::id, detail::fiber >::iterator, bool > result(
- dt->fibers.insert( id, f) );
- if ( ! result.second) throw scheduler_error("inserting fiber failed");
- dt->runnable_fibers.push( result.first->first);
+ return policy_.get();
}
bool
scheduler::run()
-{
- detail::scheduler_data * dt = access_data();
-
- if ( ! dt->runnable_fibers.empty() )
- {
- dt->f_id = dt->runnable_fibers.front();
- dt->master.switch_to( dt->fibers[dt->f_id]);
- dt->runnable_fibers.pop();
- return true;
- }
- if ( ! dt->dead_fibers.empty() )
- {
- dt->fibers.erase( dt->dead_fibers.front() );
- dt->dead_fibers.pop();
- return true;
- }
- return false;
-}
+{ return access_()->run(); }
bool
scheduler::empty()
-{ return access_data()->fibers.empty(); }
+{ return access_()->empty(); }
std::size_t
scheduler::size()
-{ return access_data()->fibers.size(); }
+{ return access_()->size(); }
}}
Modified: sandbox/fiber/libs/fiber/test/test_fiber.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_fiber.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_fiber.cpp 2009-11-08 04:16:52 EST (Sun, 08 Nov 2009)
@@ -18,8 +18,8 @@
void test_case_1()
{
boost::fiber::attributes attribs;
- boost::fiber::detail::fiber f1( zero_args_fn, attribs);
- boost::fiber::detail::fiber f2( zero_args_fn, attribs);
+ boost::fiber::fiber f1( zero_args_fn, attribs);
+ boost::fiber::fiber f2( zero_args_fn, attribs);
BOOST_CHECK( f1 != f2);
@@ -38,11 +38,11 @@
void test_case_2()
{
boost::fiber::attributes attribs;
- boost::fiber::detail::fiber f1( zero_args_fn, attribs);
- boost::fiber::detail::fiber f2( zero_args_fn, attribs);
+ boost::fiber::fiber f1( zero_args_fn, attribs);
+ boost::fiber::fiber f2( zero_args_fn, attribs);
- boost::fiber::id id1 = f1.get_id();
- boost::fiber::id id2 = f2.get_id();
+ boost::fiber::fiber::id id1 = f1.get_id();
+ boost::fiber::fiber::id id2 = f2.get_id();
f1.swap( f2);
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