Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58153 - in sandbox/fiber: boost/fiber boost/fiber/detail boost/fiber/object libs/fiber/build libs/fiber/doc libs/fiber/src libs/fiber/test
From: oliver.kowalke_at_[hidden]
Date: 2009-12-05 03:26:20


Author: olli
Date: 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
New Revision: 58153
URL: http://svn.boost.org/trac/boost/changeset/58153

Log:
- refactoring

Added:
   sandbox/fiber/boost/fiber/detail/info.hpp (contents, props changed)
   sandbox/fiber/boost/fiber/detail/info_base.hpp (contents, props changed)
   sandbox/fiber/boost/fiber/detail/info_base_posix.hpp (contents, props changed)
   sandbox/fiber/boost/fiber/detail/info_base_windows.hpp (contents, props changed)
   sandbox/fiber/boost/fiber/detail/interrupt_flags.hpp (contents, props changed)
   sandbox/fiber/boost/fiber/detail/state_flags.hpp (contents, props changed)
   sandbox/fiber/boost/fiber/object/
   sandbox/fiber/boost/fiber/object/id.hpp (contents, props changed)
   sandbox/fiber/libs/fiber/src/info_base_posix.cpp (contents, props changed)
   sandbox/fiber/libs/fiber/src/info_base_windows.cpp (contents, props changed)
Removed:
   sandbox/fiber/boost/fiber/detail/fiber_info.hpp
   sandbox/fiber/boost/fiber/detail/fiber_info_base.hpp
   sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp
   sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp
   sandbox/fiber/boost/fiber/detail/fiber_state.hpp
   sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp
   sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp
Text files modified:
   sandbox/fiber/boost/fiber/auto_reset_event.hpp | 5
   sandbox/fiber/boost/fiber/condition.hpp | 3
   sandbox/fiber/boost/fiber/count_down_event.hpp | 4
   sandbox/fiber/boost/fiber/fiber.hpp | 34 ++--
   sandbox/fiber/boost/fiber/interruption.hpp | 12
   sandbox/fiber/boost/fiber/manual_reset_event.hpp | 4
   sandbox/fiber/boost/fiber/mutex.hpp | 5
   sandbox/fiber/boost/fiber/round_robin.hpp | 40 ++++-
   sandbox/fiber/boost/fiber/scheduler.hpp | 1
   sandbox/fiber/boost/fiber/strategy.hpp | 81 ++++++++---
   sandbox/fiber/boost/fiber/utility.hpp | 24 +-
   sandbox/fiber/libs/fiber/build/Jamfile.v2 | 4
   sandbox/fiber/libs/fiber/doc/todo.qbk | 4
   sandbox/fiber/libs/fiber/src/auto_reset_event.cpp | 19 +-
   sandbox/fiber/libs/fiber/src/condition.cpp | 63 +++++---
   sandbox/fiber/libs/fiber/src/count_down_event.cpp | 20 +-
   sandbox/fiber/libs/fiber/src/fiber.cpp | 13 +
   sandbox/fiber/libs/fiber/src/fiber_posix.cpp | 6
   sandbox/fiber/libs/fiber/src/fiber_windows.cpp | 6
   sandbox/fiber/libs/fiber/src/manual_reset_event.cpp | 18 +-
   sandbox/fiber/libs/fiber/src/mutex.cpp | 16 +
   sandbox/fiber/libs/fiber/src/round_robin.cpp | 268 +++++++++++++++++++++++++++++----------
   sandbox/fiber/libs/fiber/src/strategy.cpp | 107 ++++++++++++---
   sandbox/fiber/libs/fiber/test/Jamfile.v2 | 12
   sandbox/fiber/libs/fiber/test/test_auto_reset_event.cpp | 1
   sandbox/fiber/libs/fiber/test/test_condition.cpp | 59 +++++---
   sandbox/fiber/libs/fiber/test/test_count_down_event.cpp | 15 +
   sandbox/fiber/libs/fiber/test/test_manual_reset_event.cpp | 3
   sandbox/fiber/libs/fiber/test/test_mutex.cpp | 47 ++++--
   sandbox/fiber/libs/fiber/test/test_scheduler.cpp | 4
   30 files changed, 611 insertions(+), 287 deletions(-)

Modified: sandbox/fiber/boost/fiber/auto_reset_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/auto_reset_event.hpp (original)
+++ sandbox/fiber/boost/fiber/auto_reset_event.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -10,6 +10,8 @@
 #include <boost/cstdint.hpp>
 #include <boost/utility.hpp>
 
+#include <boost/fiber/object/id.hpp>
+
 namespace boost {
 namespace fibers {
 
@@ -23,10 +25,13 @@
         };
 
         volatile uint32_t state_;
+ object::id id_;
 
 public:
         explicit auto_reset_event( bool = false);
 
+ ~auto_reset_event();
+
         void set();
 
         void wait();

Modified: sandbox/fiber/boost/fiber/condition.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/condition.hpp (original)
+++ sandbox/fiber/boost/fiber/condition.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -12,6 +12,7 @@
 #include <boost/cstdint.hpp>
 #include <boost/utility.hpp>
 
+#include <boost/fiber/object/id.hpp>
 #include <boost/fiber/exceptions.hpp>
 #include <boost/fiber/mutex.hpp>
 
@@ -32,9 +33,9 @@
         volatile uint32_t waiters_;
         mutex enter_mtx_;
         mutex check_mtx_;
+ object::id id_;
 
         void wait_( mutex &);
- void notify_( uint32_t);
 
 public:
         condition();

Modified: sandbox/fiber/boost/fiber/count_down_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/count_down_event.hpp (original)
+++ sandbox/fiber/boost/fiber/count_down_event.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -10,6 +10,7 @@
 #include <boost/cstdint.hpp>
 #include <boost/utility.hpp>
 
+#include <boost/fiber/object/id.hpp>
 #include <boost/fiber/mutex.hpp>
 
 namespace boost {
@@ -20,10 +21,13 @@
 private:
         uint32_t initial_;
         volatile uint32_t current_;
+ object::id id_;
 
 public:
         explicit count_down_event( uint32_t);
 
+ ~count_down_event();
+
         uint32_t initial() const;
 
         uint32_t current() const;

Deleted: sandbox/fiber/boost/fiber/detail/fiber_info.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,114 +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_FIBER_INFO_H
-#define BOOST_FIBERS_DETAIL_FIBER_INFO_H
-
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
-#include <boost/type_traits/remove_reference.hpp>
-
-#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_info_base.hpp>
-#include <boost/fiber/detail/move.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-class BOOST_FIBER_DECL fiber_info_default : public fiber_info_base
-{
-private:
- fiber_info_default( fiber_info_default &);
- fiber_info_default & operator=( fiber_info_default const&);
-
-public:
- fiber_info_default() :
- fiber_info_base()
- {}
-
- void run()
- { BOOST_ASSERT( ! "run() of master-fiber should never be executed"); }
-};
-
-template< typename Fn >
-class fiber_info : public fiber_info_base
-{
-private:
- Fn fn_;
-
- fiber_info( fiber_info &);
- fiber_info & operator=( fiber_info const&);
-
-public:
-#ifdef BOOST_HAS_RVALUE_REFS
- thread_data( Fn && fn, std::size_t stack_size) :
- fiber_info_base( stack_size),
- fn_( static_cast< Fn && >( fn) )
- {}
-#else
- fiber_info( Fn fn, std::size_t stack_size) :
- fiber_info_base( stack_size),
- fn_( fn)
- {}
-
- fiber_info( boost::detail::fiber_move_t< Fn > fn, std::size_t stack_size) :
- fiber_info_base( stack_size),
- fn_( fn)
- {}
-#endif
-
- void run()
- { fn_(); }
-};
-
-template< typename Fn >
-class fiber_info< reference_wrapper< Fn > > : public fiber_info_base
-{
-private:
- Fn & fn_;
-
- fiber_info( fiber_info &);
- fiber_info & operator=( fiber_info const&);
-
-public:
- fiber_info( reference_wrapper< Fn > fn, std::size_t stack_size) :
- fiber_info_base( stack_size),
- fn_( fn)
- {}
-
- void run()
- { fn_(); }
-};
-
-template< typename Fn >
-class fiber_info< const reference_wrapper< Fn > > : public fiber_info_base
-{
-private:
- Fn & fn_;
-
- fiber_info( fiber_info &);
- fiber_info & operator=( fiber_info const&);
-
-public:
- fiber_info( const reference_wrapper< Fn > fn, std::size_t stack_size) :
- fiber_info_base( stack_size),
- fn_( fn)
- {}
-
- void run()
- { fn_(); }
-};
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_INFO_H

Deleted: sandbox/fiber/boost/fiber/detail/fiber_info_base.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_base.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,18 +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_INFO_BASE_H
-#define BOOST_FIBER_DETAIL_FIBER_INFO_BASE_H
-
-#include <boost/fiber/detail/config.hpp>
-
-# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-#include <boost/fiber/detail/fiber_info_base_windows.hpp>
-# elif defined(_POSIX_VERSION)
-#include <boost/fiber/detail/fiber_info_base_posix.hpp>
-# endif
-
-#endif // BOOST_FIBER_DETAIL_FIBER_INFO_BASE_H

Deleted: sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,71 +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_FIBER_INFO_POSIX_H
-#define BOOST_FIBERS_DETAIL_FIBER_INFO_POSIX_H
-
-extern "C" {
-
-#include <ucontext.h>
-
-}
-
-#include <cstddef>
-#include <stack>
-
-#include <boost/cstdint.hpp>
-#include <boost/function.hpp>
-#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_array.hpp>
-
-#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-
-class strategy;
-
-namespace detail {
-
-struct BOOST_FIBER_DECL fiber_info_base
-{
- typedef intrusive_ptr< fiber_info_base > ptr_t;
- typedef function< void() > callable_t;
- typedef std::stack< callable_t > callable_stack_t;
-
- uint32_t use_count;
- std::size_t stack_size;
- int priority;
- ::ucontext_t uctx;
- shared_array< char > uctx_stack;
- fiber_state_t state;
- fiber_interrupt_t interrupt;
- callable_stack_t at_exit;
- strategy * st;
-
- fiber_info_base();
-
- fiber_info_base( std::size_t);
-
- virtual ~fiber_info_base() {}
-
- virtual void run() = 0;
-
- 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; }
-};
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_INFO_POSIX_H

Deleted: sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,78 +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_FIBER_INFO_WINDOWS_H
-#define BOOST_FIBERS_DETAIL_FIBER_INFO_WINDOWS_H
-
-extern "C" {
-
-#include <windows.h>
-
-}
-
-#include <cstddef>
-#include <stack>
-
-#include <boost/cstdint.hpp>
-#include <boost/function.hpp>
-#include <boost/intrusive_ptr.hpp>
-
-#include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-# if defined(BOOST_MSVC)
-# pragma warning(push)
-# pragma warning(disable:4251 4275)
-# endif
-
-namespace boost {
-namespace fibers {
-
-class strategy;
-
-namespace detail {
-
-struct BOOST_FIBER_DECL fiber_info_base
-{
- typedef intrusive_ptr< fiber_info_base > ptr_t;
- typedef function< void() > callable_t;
- typedef std::stack< callable_t > callable_stack_t;
-
- uint32_t use_count;
- std::size_t stack_size;
- int priority;
- LPVOID uctx;
- fiber_state_t state;
- fiber_interrupt_t interrupt;
- callable_stack_t at_exit;
- strategy * st;
-
- fiber_info_base();
-
- fiber_info_base( std::size_t);
-
- virtual ~fiber_info_base();
-
- virtual void run() = 0;
-
- 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; }
-};
-
-}}}
-
-# if defined(BOOST_MSVC)
-# pragma warning(pop)
-# endif
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_INFO_WINDOWS_H

Deleted: sandbox/fiber/boost/fiber/detail/fiber_state.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_state.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,43 +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_FIBER_STATE_H
-#define BOOST_FIBERS_DETAIL_FIBER_STATE_H
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-enum state_t
-{
- STATE_MASTER = 1 << 0,
- STATE_NOT_STARTED = 1 << 1,
- STATE_READY = 1 << 2,
- STATE_RUNNING = 1 << 3,
- STATE_WAIT_FOR_JOIN = 1 << 4,
- STATE_TERMINATED = 1 << 5
-};
-
-typedef char fiber_state_t;
-
-#define IS_ALIVE_BIT_MASK 0x1C
-
-enum interrupt_t
-{
- INTERRUPTION_DISABLED = 1 << 0,
- INTERRUPTION_ENABLED = 1 << 1,
- INTERRUPTION_BLOCKED = 1 << 2
-};
-
-typedef char fiber_interrupt_t;
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_STATE_H

Added: sandbox/fiber/boost/fiber/detail/info.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/info.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,114 @@
+
+// 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_INFO_H
+#define BOOST_FIBERS_DETAIL_INFO_H
+
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/config.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/detail/info_base.hpp>
+#include <boost/fiber/detail/move.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+class BOOST_FIBER_DECL info_default : public info_base
+{
+private:
+ info_default( info_default &);
+ info_default & operator=( info_default const&);
+
+public:
+ info_default() :
+ info_base()
+ {}
+
+ void run()
+ { BOOST_ASSERT( ! "run() of master-fiber should never be executed"); }
+};
+
+template< typename Fn >
+class info : public info_base
+{
+private:
+ Fn fn_;
+
+ info( info &);
+ info & operator=( info const&);
+
+public:
+#ifdef BOOST_HAS_RVALUE_REFS
+ thread_data( Fn && fn, std::size_t stack_size) :
+ info_base( stack_size),
+ fn_( static_cast< Fn && >( fn) )
+ {}
+#else
+ info( Fn fn, std::size_t stack_size) :
+ info_base( stack_size),
+ fn_( fn)
+ {}
+
+ info( boost::detail::fiber_move_t< Fn > fn, std::size_t stack_size) :
+ info_base( stack_size),
+ fn_( fn)
+ {}
+#endif
+
+ void run()
+ { fn_(); }
+};
+
+template< typename Fn >
+class info< reference_wrapper< Fn > > : public info_base
+{
+private:
+ Fn & fn_;
+
+ info( info &);
+ info & operator=( info const&);
+
+public:
+ info( reference_wrapper< Fn > fn, std::size_t stack_size) :
+ info_base( stack_size),
+ fn_( fn)
+ {}
+
+ void run()
+ { fn_(); }
+};
+
+template< typename Fn >
+class info< const reference_wrapper< Fn > > : public info_base
+{
+private:
+ Fn & fn_;
+
+ info( info &);
+ info & operator=( info const&);
+
+public:
+ info( const reference_wrapper< Fn > fn, std::size_t stack_size) :
+ info_base( stack_size),
+ fn_( fn)
+ {}
+
+ void run()
+ { fn_(); }
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBERS_DETAIL_INFO_H

Added: sandbox/fiber/boost/fiber/detail/info_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/info_base.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,18 @@
+
+// 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_INFO_BASE_H
+#define BOOST_FIBER_DETAIL_INFO_BASE_H
+
+#include <boost/fiber/detail/config.hpp>
+
+# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#include <boost/fiber/detail/info_base_windows.hpp>
+# elif defined(_POSIX_VERSION)
+#include <boost/fiber/detail/info_base_posix.hpp>
+# endif
+
+#endif // BOOST_FIBER_DETAIL_INFO_BASE_H

Added: sandbox/fiber/boost/fiber/detail/info_base_posix.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/info_base_posix.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,72 @@
+
+// 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_INFO_POSIX_H
+#define BOOST_FIBERS_DETAIL_INFO_POSIX_H
+
+extern "C" {
+
+#include <ucontext.h>
+
+}
+
+#include <cstddef>
+#include <stack>
+
+#include <boost/cstdint.hpp>
+#include <boost/function.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/shared_array.hpp>
+
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/detail/interrupt_flags.hpp>
+#include <boost/fiber/detail/state_flags.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+
+class strategy;
+
+namespace detail {
+
+struct BOOST_FIBER_DECL info_base
+{
+ typedef intrusive_ptr< info_base > ptr_t;
+ typedef function< void() > callable_t;
+ typedef std::stack< callable_t > callable_stack_t;
+
+ uint32_t use_count;
+ std::size_t stack_size;
+ int priority;
+ ::ucontext_t uctx;
+ shared_array< char > uctx_stack;
+ state_t state;
+ interrupt_t interrupt;
+ callable_stack_t at_exit;
+ strategy * st;
+
+ info_base();
+
+ info_base( std::size_t);
+
+ virtual ~info_base() {}
+
+ virtual void run() = 0;
+
+ inline friend void intrusive_ptr_add_ref( info_base * p)
+ { ++p->use_count; }
+
+ inline friend void intrusive_ptr_release( info_base * p)
+ { if ( --p->use_count == 0) delete p; }
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBERS_DETAIL_INFO_POSIX_H

Added: sandbox/fiber/boost/fiber/detail/info_base_windows.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/info_base_windows.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,79 @@
+
+// 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_INFO_WINDOWS_H
+#define BOOST_FIBERS_DETAIL_INFO_WINDOWS_H
+
+extern "C" {
+
+#include <windows.h>
+
+}
+
+#include <cstddef>
+#include <stack>
+
+#include <boost/cstdint.hpp>
+#include <boost/function.hpp>
+#include <boost/intrusive_ptr.hpp>
+
+#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/detail/interrupt_flags.hpp>
+#include <boost/fiber/detail/state_flags.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+# if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable:4251 4275)
+# endif
+
+namespace boost {
+namespace fibers {
+
+class strategy;
+
+namespace detail {
+
+struct BOOST_FIBER_DECL info_base
+{
+ typedef intrusive_ptr< info_base > ptr_t;
+ typedef function< void() > callable_t;
+ typedef std::stack< callable_t > callable_stack_t;
+
+ uint32_t use_count;
+ std::size_t stack_size;
+ int priority;
+ LPVOID uctx;
+ state_t state;
+ interrupt_t interrupt;
+ callable_stack_t at_exit;
+ strategy * st;
+
+ info_base();
+
+ info_base( std::size_t);
+
+ virtual ~info_base();
+
+ virtual void run() = 0;
+
+ inline friend void intrusive_ptr_add_ref( info_base * p)
+ { ++p->use_count; }
+
+ inline friend void intrusive_ptr_release( info_base * p)
+ { if ( --p->use_count == 0) delete p; }
+};
+
+}}}
+
+# if defined(BOOST_MSVC)
+# pragma warning(pop)
+# endif
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBERS_DETAIL_INFO_WINDOWS_H

Added: sandbox/fiber/boost/fiber/detail/interrupt_flags.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/interrupt_flags.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,29 @@
+
+// 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_INTERRUPT_FLAGS_H
+#define BOOST_FIBERS_DETAIL_INTERRUPT_FLAGS_H
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+enum interrupt_t_
+{
+ INTERRUPTION_DISABLED = 1 << 0,
+ INTERRUPTION_ENABLED = 1 << 1,
+ INTERRUPTION_BLOCKED = 1 << 2
+};
+
+typedef char interrupt_t;
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBERS_DETAIL_INTERRUPT_FLAGS_H

Added: sandbox/fiber/boost/fiber/detail/state_flags.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/state_flags.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,35 @@
+
+// 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_STATE_FLAGS_H
+#define BOOST_FIBERS_DETAIL_STATE_FLAGS_H
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+enum state_t_
+{
+ STATE_MASTER = 1 << 0,
+ STATE_NOT_STARTED = 1 << 1,
+ STATE_READY = 1 << 2,
+ STATE_RUNNING = 1 << 3,
+ STATE_WAIT_FOR_FIBER = 1 << 4,
+ STATE_WAIT_FOR_OBJECT = 1 << 5,
+ STATE_TERMINATED = 1 << 6
+};
+
+typedef char state_t;
+
+#define IS_ALIVE_BIT_MASK 0x3C
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBERS_DETAIL_STATE_FLAGS_H

Modified: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/fiber.hpp (original)
+++ sandbox/fiber/boost/fiber/fiber.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -18,7 +18,7 @@
 #include <boost/utility.hpp>
 
 #include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_info.hpp>
+#include <boost/fiber/detail/info.hpp>
 #include <boost/fiber/detail/move.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -45,43 +45,43 @@
         static void convert_thread_to_fiber();
         static void convert_fiber_to_thread();
 
- detail::fiber_info_base::ptr_t info_base_;
+ detail::info_base::ptr_t info_base_;
 
- explicit fiber( detail::fiber_info_base::ptr_t);
+ explicit fiber( detail::info_base::ptr_t);
 
         void init_();
 
- detail::fiber_info_base::ptr_t info_() const;
+ detail::info_base::ptr_t info_() const;
 
         void switch_to_( fiber &);
 
 #ifdef BOOST_HAS_RVALUE_REFS
         template< typename Fn >
- static detail::fiber_info_base::ptr_t make_info_(
+ static detail::info_base::ptr_t make_info_(
                 std::size_t stack_size, Fn && fn)
         {
- return detail::fiber_info_base::ptr_t(
- new detail::fiber_info< typename remove_reference< Fn >::type >(
+ return detail::info_base::ptr_t(
+ new detail::info< typename remove_reference< Fn >::type >(
                                 static_cast< Fn && >( fn), stack_size) );
         }
 
- static detail::fiber_info_base::ptr_t make_info_(
+ static detail::info_base::ptr_t make_info_(
                 std::size_t stack_size, void ( * fn)() );
 #else
         template< typename Fn >
- static detail::fiber_info_base::ptr_t make_info_(
+ static detail::info_base::ptr_t make_info_(
                 std::size_t stack_size, Fn fn)
         {
- return detail::fiber_info_base::ptr_t(
- new detail::fiber_info< Fn >( fn, stack_size) );
+ return detail::info_base::ptr_t(
+ new detail::info< Fn >( fn, stack_size) );
         }
 
         template< typename Fn >
- static detail::fiber_info_base::ptr_t make_info_(
+ static detail::info_base::ptr_t make_info_(
                 std::size_t stack_size, boost::detail::fiber_move_t< Fn > fn)
         {
- return detail::fiber_info_base::ptr_t(
- new detail::fiber_info< Fn >( fn, stack_size) );
+ return detail::info_base::ptr_t(
+ new detail::info< Fn >( fn, stack_size) );
         }
 #endif
 
@@ -178,7 +178,7 @@
 
 #undef BOOST_FIBER_FIBER_CTOR
 
- typedef detail::fiber_info_base::ptr_t::unspecified_bool_type unspecified_bool_type;
+ typedef detail::info_base::ptr_t::unspecified_bool_type unspecified_bool_type;
 
         operator unspecified_bool_type() const;
 
@@ -211,9 +211,9 @@
 private:
         friend class fiber;
 
- detail::fiber_info_base::ptr_t info_;
+ detail::info_base::ptr_t info_;
 
- explicit id( detail::fiber_info_base::ptr_t info) :
+ explicit id( detail::info_base::ptr_t info) :
                 info_( info)
         {}
 

Modified: sandbox/fiber/boost/fiber/interruption.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/interruption.hpp (original)
+++ sandbox/fiber/boost/fiber/interruption.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -12,7 +12,7 @@
 #include <boost/utility.hpp>
 
 #include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
+#include <boost/fiber/detail/interrupt_flags.hpp>
 #include <boost/fiber/strategy.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -31,10 +31,10 @@
 
 public:
         disable_interruption() :
- set_( ( fibers::strategy::interrupt_flags() & fibers::detail::INTERRUPTION_BLOCKED) != 0)
+ set_( ( fibers::strategy::interrupt_flags_() & fibers::detail::INTERRUPTION_BLOCKED) != 0)
         {
                 if ( ! set_)
- fibers::strategy::interrupt_flags() |= fibers::detail::INTERRUPTION_BLOCKED;
+ fibers::strategy::interrupt_flags_() |= fibers::detail::INTERRUPTION_BLOCKED;
         }
 
         ~disable_interruption()
@@ -42,7 +42,7 @@
                 try
                 {
                         if ( ! set_)
- fibers::strategy::interrupt_flags() &= ~fibers::detail::INTERRUPTION_BLOCKED;
+ fibers::strategy::interrupt_flags_() &= ~fibers::detail::INTERRUPTION_BLOCKED;
                 }
                 catch (...)
                 {}
@@ -59,7 +59,7 @@
                 disabler_( disabler)
         {
                 if ( ! disabler_.set_)
- fibers::strategy::interrupt_flags() &= ~fibers::detail::INTERRUPTION_BLOCKED;
+ fibers::strategy::interrupt_flags_() &= ~fibers::detail::INTERRUPTION_BLOCKED;
         }
 
         ~restore_interruption()
@@ -67,7 +67,7 @@
            try
            {
                         if ( ! disabler_.set_)
- fibers::strategy::interrupt_flags() |= fibers::detail::INTERRUPTION_BLOCKED;
+ fibers::strategy::interrupt_flags_() |= fibers::detail::INTERRUPTION_BLOCKED;
                 }
                 catch (...)
                 {}

Modified: sandbox/fiber/boost/fiber/manual_reset_event.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/manual_reset_event.hpp (original)
+++ sandbox/fiber/boost/fiber/manual_reset_event.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -10,6 +10,7 @@
 #include <boost/cstdint.hpp>
 #include <boost/utility.hpp>
 
+#include <boost/fiber/object/id.hpp>
 #include <boost/fiber/mutex.hpp>
 
 namespace boost {
@@ -27,10 +28,13 @@
         volatile uint32_t state_;
         volatile uint32_t waiters_;
         mutex enter_mtx_;
+ object::id id_;
 
 public:
         explicit manual_reset_event( bool = false);
 
+ ~manual_reset_event();
+
         void set();
 
         void reset();

Modified: sandbox/fiber/boost/fiber/mutex.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/mutex.hpp (original)
+++ sandbox/fiber/boost/fiber/mutex.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -13,6 +13,8 @@
 #include <boost/thread/locks.hpp>
 #include <boost/utility.hpp>
 
+#include <boost/fiber/object/id.hpp>
+
 namespace boost {
 namespace fibers {
 
@@ -20,12 +22,15 @@
 {
 private:
         volatile uint32_t state_;
+ object::id id_;
 
 public:
         typedef unique_lock< mutex > scoped_lock;
 
         mutex();
 
+ ~mutex();
+
         void lock();
 
         bool try_lock();

Added: sandbox/fiber/boost/fiber/object/id.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/object/id.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 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_FIBERS_DETAIL_ID_H
+#define BOOST_FIBERS_DETAIL_ID_H
+
+#include <iostream>
+
+namespace boost {
+namespace fibers {
+namespace object {
+
+class id
+{
+private:
+ void const* vp_;
+
+public:
+ template< typename T >
+ id( T const& t) :
+ vp_( static_cast< void const* >( & t) )
+ {}
+
+ bool operator==( id const& other) const
+ { return vp_ == other.vp_; }
+
+ bool operator!=( id const& other) const
+ { return vp_ != other.vp_; }
+
+ bool operator<( id const& other) const
+ { return vp_ < other.vp_; }
+
+ bool operator>( id const& other) const
+ { return other.vp_ < vp_; }
+
+ bool operator<=( id const& other) const
+ { return !( other.vp_ < vp_); }
+
+ bool operator>=( id const& other) const
+ { return ! ( vp_ < other.vp_); }
+
+ template< typename charT, class traitsT >
+ friend std::basic_ostream< charT, traitsT > &
+ operator<<( std::basic_ostream< charT, traitsT > & os, id const& other)
+ {
+ if ( other.vp_)
+ return os << other.vp_;
+ else
+ return os << "{not-a-object}";
+ }
+};
+
+}}}
+
+#endif // BOOST_FIBERS_DETAIL_ID_H

Modified: sandbox/fiber/boost/fiber/round_robin.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/round_robin.hpp (original)
+++ sandbox/fiber/boost/fiber/round_robin.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -17,7 +17,7 @@
 #include <boost/utility.hpp>
 
 #include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
+#include <boost/fiber/object/id.hpp>
 #include <boost/fiber/fiber.hpp>
 #include <boost/fiber/strategy.hpp>
 
@@ -39,24 +39,30 @@
         {
                 fiber f;
                 std::list< fiber::id > joining_fibers;
- optional< fiber::id > waiting_on;
+ optional< fiber::id > waiting_on_fiber;
+ optional< object::id > waiting_on_object;
 
                 schedulable() :
- f(), joining_fibers(), waiting_on()
+ f(), joining_fibers(),
+ waiting_on_fiber(), waiting_on_object()
                 {}
 
                 schedulable( fiber f_) :
- f( f_), joining_fibers(), waiting_on()
+ f( f_), joining_fibers(),
+ waiting_on_fiber(), waiting_on_object()
                 {}
         };
 
- typedef std::map< fiber::id, schedulable > container;
- typedef std::list< fiber::id > runnable_queue;
- typedef std::queue< fiber::id > terminated_queue;
+ typedef std::map< fiber::id, schedulable > fiber_map;
+ typedef std::list< fiber::id > fiber_id_list;
+ typedef std::map< object::id, fiber_id_list > object_map;
+ typedef std::list< fiber::id > runnable_queue;
+ typedef std::queue< fiber::id > terminated_queue;
 
- container fibers_;
+ fiber_map fibers_;
         runnable_queue runnable_fibers_;
         terminated_queue terminated_fibers_;
+ object_map objects_;
 
 public:
         round_robin();
@@ -65,16 +71,26 @@
 
         void add( fiber);
 
- void yield( fiber::id const&);
-
- void cancel( fiber::id const&);
-
         void join( fiber::id const&);
 
         void interrupt( fiber::id const&);
 
         void reschedule( fiber::id const&);
 
+ void cancel( fiber::id const&);
+
+ void yield();
+
+ void register_object( object::id const&);
+
+ void unregister_object( object::id const&);
+
+ void wait_for_object( object::id const&);
+
+ void object_notify_one( object::id const&);
+
+ void object_notify_all( object::id const&);
+
         bool run();
 
         bool empty();

Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -15,7 +15,6 @@
 #include <boost/utility.hpp>
 
 #include <boost/fiber/detail/config.hpp>
-#include <boost/fiber/detail/fiber_state.hpp>
 #include <boost/fiber/fiber.hpp>
 #include <boost/fiber/round_robin.hpp>
 #include <boost/fiber/strategy.hpp>

Modified: sandbox/fiber/boost/fiber/strategy.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/strategy.hpp (original)
+++ sandbox/fiber/boost/fiber/strategy.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -8,11 +8,14 @@
 #define BOOST_FIBERS_STRATEGY_H
 
 #include <cstddef>
+#include <list>
+#include <map>
 
 #include <boost/function.hpp>
 #include <boost/thread/tss.hpp>
 
-#include <boost/fiber/detail/fiber_state.hpp>
+#include <boost/fiber/detail/interrupt_flags.hpp>
+#include <boost/fiber/object/id.hpp>
 #include <boost/fiber/fiber.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -47,6 +50,12 @@
 
 namespace fibers {
 
+class auto_reset_event;
+class condition;
+class count_down_event;
+class manual_reset_event;
+class mutex;
+
 class BOOST_FIBER_DECL strategy
 {
 private:
@@ -65,36 +74,52 @@
         friend void this_fiber::at_fiber_exit( void (*)() );
         friend class this_fiber::disable_interruption;
         friend class this_fiber::restore_interruption;
+ friend class auto_reset_event;
+ friend class condition;
+ friend class count_down_event;
+ friend class manual_reset_event;
+ friend class mutex;
 
         typedef function< void() > callable_t;
 
- static bool runs_as_fiber();
+ static bool runs_as_fiber_();
+
+ static fiber::id get_id_();
+
+ static void interruption_point_();
+
+ static bool interruption_requested_();
+
+ static detail::interrupt_t & interrupt_flags_();
 
- static fiber::id get_id();
+ static bool interruption_enabled_();
 
- static void interruption_point();
+ static int priority_();
 
- static bool interruption_requested();
+ static void priority_( int);
 
- static detail::fiber_interrupt_t & interrupt_flags();
+ static void at_fiber_exit_( callable_t);
 
- static bool interruption_enabled();
+ static void yield_();
 
- static int priority();
+ static void cancel_();
 
- static void priority( int);
+ static void register_object_( object::id const&);
 
- static void at_fiber_exit( callable_t);
+ static void unregister_object_( object::id const&);
 
- static void yield();
+ static void wait_for_object_( object::id const&);
 
- static void cancel();
+ static void object_notify_one_( object::id const&);
+
+ static void object_notify_all_( object::id const&);
 
 protected:
- typedef thread_specific_ptr< fiber > active_fiber_t;
+ typedef thread_specific_ptr< fiber > fiber_t;
+
+ static fiber_t active_fiber;
 
- static active_fiber_t active_fiber;
- fiber master_fiber;
+ fiber master_fiber;
 
         void attach( fiber &);
 
@@ -114,7 +139,9 @@
 
         bool in_state_running( fiber const&);
 
- bool in_state_wait_for_join( fiber const&);
+ bool in_state_wait_for_fiber( fiber const&);
+
+ bool in_state_wait_for_object( fiber const&);
 
         bool in_state_terminated( fiber const&);
 
@@ -122,7 +149,9 @@
 
         void set_state_running( fiber &);
 
- void set_state_wait_for_join( fiber &);
+ void set_state_wait_for_fiber( fiber &);
+
+ void set_state_wait_for_object( fiber &);
 
         void set_state_terminated( fiber &);
 
@@ -132,16 +161,26 @@
         virtual ~strategy();
 
         virtual void add( fiber) = 0;
-
- virtual void yield( fiber::id const&) = 0;
-
- virtual void cancel( fiber::id const&) = 0;
 
         virtual void join( fiber::id const&) = 0;
 
         virtual void interrupt( fiber::id const&) = 0;
 
         virtual void reschedule( fiber::id const&) = 0;
+
+ virtual void cancel( fiber::id const&) = 0;
+
+ virtual void yield() = 0;
+
+ virtual void register_object( object::id const&) = 0;
+
+ virtual void unregister_object( object::id const&) = 0;
+
+ virtual void wait_for_object( object::id const&) = 0;
+
+ virtual void object_notify_one( object::id const&) = 0;
+
+ virtual void object_notify_all( object::id const&) = 0;
 
         virtual bool run() = 0;
 

Modified: sandbox/fiber/boost/fiber/utility.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/utility.hpp (original)
+++ sandbox/fiber/boost/fiber/utility.hpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -20,51 +20,51 @@
 
 inline
 bool runs_as_fiber()
-{ return fibers::strategy::runs_as_fiber(); }
+{ return fibers::strategy::runs_as_fiber_(); }
 
 inline
 fiber::id get_id()
-{ return fibers::strategy::get_id(); }
+{ return fibers::strategy::get_id_(); }
 
 inline
 int priority()
-{ return fibers::strategy::priority(); }
+{ return fibers::strategy::priority_(); }
 
 inline
 void priority( int prio)
-{ fibers::strategy::priority( prio); }
+{ fibers::strategy::priority_( prio); }
 
 inline
 void interruption_point()
-{ fibers::strategy::interruption_point(); }
+{ fibers::strategy::interruption_point_(); }
 
 inline
 bool interruption_requested()
-{ return fibers::strategy::interruption_requested(); }
+{ return fibers::strategy::interruption_requested_(); }
 
 inline
 bool interruption_enabled()
-{ return fibers::strategy::interruption_enabled(); }
+{ return fibers::strategy::interruption_enabled_(); }
 
 inline
 void at_fiber_exit( function< void() > ca)
-{ fibers::strategy::at_fiber_exit( ca); }
+{ fibers::strategy::at_fiber_exit_( ca); }
 
 template< typename Callable >
 void at_fiber_exit( Callable ca)
-{ fibers::strategy::at_fiber_exit( boost::bind( boost::type< void >(), ca) ); }
+{ fibers::strategy::at_fiber_exit_( boost::bind( boost::type< void >(), ca) ); }
 
 inline
 void at_fiber_exit( void ( * ca)() )
-{ fibers::strategy::at_fiber_exit( boost::bind( boost::type< void >(), ca) ); }
+{ fibers::strategy::at_fiber_exit_( boost::bind( boost::type< void >(), ca) ); }
 
 inline
 void yield()
-{ fibers::strategy::yield(); }
+{ fibers::strategy::yield_(); }
 
 inline
 void cancel()
-{ fibers::strategy::cancel(); }
+{ fibers::strategy::cancel_(); }
 
 }}
 

Modified: sandbox/fiber/libs/fiber/build/Jamfile.v2
==============================================================================
--- sandbox/fiber/libs/fiber/build/Jamfile.v2 (original)
+++ sandbox/fiber/libs/fiber/build/Jamfile.v2 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -45,8 +45,8 @@
         condition.cpp
         count_down_event.cpp
         fiber.cpp
- fiber_info_base_windows.cpp
         fiber_windows.cpp
+ info_base_windows.cpp
         manual_reset_event.cpp
         mutex.cpp
         round_robin.cpp
@@ -61,8 +61,8 @@
         condition.cpp
         count_down_event.cpp
         fiber.cpp
- fiber_info_base_posix.cpp
         fiber_posix.cpp
+ info_base_posix.cpp
         manual_reset_event.cpp
         mutex.cpp
         round_robin.cpp

Modified: sandbox/fiber/libs/fiber/doc/todo.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/todo.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/todo.qbk 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -9,13 +9,13 @@
 
 [section:todo Todo]
 
-* replace spin-waiting in condition- and event-variables
+* replace spin-waiting in mutex, condition- and event-variables
 
 * improve implementation of atomic-ops
 
 * replace system calls related to fiber switching (like swapcontext()) by assembler
 
-* explicit migraton of fiber between schedulers (== between threads)
+* explicit migration of fiber between schedulers (== between threads)
 
 * improve scheduling algorithm (take priorities into acount)
 

Modified: sandbox/fiber/libs/fiber/src/auto_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/auto_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/auto_reset_event.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -7,7 +7,7 @@
 #include "boost/fiber/auto_reset_event.hpp"
 
 #include <boost/fiber/detail/atomic.hpp>
-#include <boost/fiber/utility.hpp>
+#include <boost/fiber/strategy.hpp>
 
 namespace boost {
 namespace fibers {
@@ -16,12 +16,19 @@
         state_(
                 isset ?
                 static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) )
-{}
+ static_cast< uint32_t >( RESET) ),
+ id_( * this)
+{ strategy::register_object_( id_); }
+
+auto_reset_event::~auto_reset_event()
+{ strategy::unregister_object_( id_); }
 
 void
 auto_reset_event::set()
-{ detail::atomic_exchange( & state_, static_cast< uint32_t >( SET) ); }
+{
+ detail::atomic_exchange( & state_, static_cast< uint32_t >( SET) );
+ strategy::object_notify_one_( id_);
+}
 
 void
 auto_reset_event::wait()
@@ -31,9 +38,7 @@
                         & state_, & expected,
                         static_cast< uint32_t >( RESET) ) )
         {
- this_fiber::interruption_point();
- this_fiber::yield();
- this_fiber::interruption_point();
+ strategy::wait_for_object_( id_);
                 expected = static_cast< uint32_t >( SET);
         }
 }

Modified: sandbox/fiber/libs/fiber/src/condition.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/condition.cpp (original)
+++ sandbox/fiber/libs/fiber/src/condition.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -11,29 +11,13 @@
 
 #include <boost/fiber/detail/atomic.hpp>
 #include <boost/fiber/mutex.hpp>
+#include <boost/fiber/strategy.hpp>
 #include <boost/fiber/utility.hpp>
 
 namespace boost {
 namespace fibers {
 
 void
-condition::notify_( uint32_t cmd)
-{
- enter_mtx_.lock();
-
- if ( 0 == detail::atomic_load( & waiters_) )
- {
- enter_mtx_.unlock();
- return;
- }
-
- uint32_t expected = static_cast< uint32_t >( SLEEPING);
- while ( ! detail::atomic_compare_exchange_strong(
- & cmd_, & expected, cmd) )
- this_fiber::yield();
-}
-
-void
 condition::wait_( mutex & mtx)
 {
         {
@@ -47,7 +31,7 @@
         for (;;)
         {
                 while ( static_cast< uint32_t >( SLEEPING) == detail::atomic_load( & cmd_) )
- this_fiber::yield();
+ strategy::wait_for_object_( id_);
 
                 mutex::scoped_lock lk( check_mtx_);
                 BOOST_ASSERT( lk);
@@ -88,18 +72,51 @@
         cmd_( static_cast< uint32_t >( SLEEPING) ),
         waiters_( 0),
         enter_mtx_(),
- check_mtx_()
-{}
+ check_mtx_(),
+ id_( * this)
+{ strategy::register_object_( id_); }
 
 condition::~condition()
-{}
+{ strategy::unregister_object_( id_); }
 
 void
 condition::notify_one()
-{ notify_( static_cast< uint32_t >( NOTIFY_ONE) ); }
+{
+ enter_mtx_.lock();
+
+ if ( 0 == detail::atomic_load( & waiters_) )
+ {
+ enter_mtx_.unlock();
+ return;
+ }
+
+ uint32_t cmd = static_cast< uint32_t >( NOTIFY_ONE);
+ uint32_t expected = static_cast< uint32_t >( SLEEPING);
+ while ( ! detail::atomic_compare_exchange_strong(
+ & cmd_, & expected, cmd) )
+ this_fiber::yield();
+
+ strategy::object_notify_one_( id_);
+}
 
 void
 condition::notify_all()
-{ notify_( static_cast< uint32_t >( NOTIFY_ALL) ); }
+{
+ enter_mtx_.lock();
+
+ if ( 0 == detail::atomic_load( & waiters_) )
+ {
+ enter_mtx_.unlock();
+ return;
+ }
+
+ uint32_t cmd = static_cast< uint32_t >( NOTIFY_ALL);
+ uint32_t expected = static_cast< uint32_t >( SLEEPING);
+ while ( ! detail::atomic_compare_exchange_strong(
+ & cmd_, & expected, cmd) )
+ this_fiber::yield();
+
+ strategy::object_notify_all_( id_);
+}
 
 }}

Modified: sandbox/fiber/libs/fiber/src/count_down_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/count_down_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/count_down_event.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -8,15 +8,19 @@
 
 #include <boost/fiber/detail/atomic.hpp>
 #include <boost/fiber/mutex.hpp>
-#include <boost/fiber/utility.hpp>
+#include <boost/fiber/strategy.hpp>
 
 namespace boost {
 namespace fibers {
 
 count_down_event::count_down_event( uint32_t initial) :
         initial_( initial),
- current_( initial_)
-{}
+ current_( initial_),
+ id_( * this)
+{ strategy::register_object_( id_); }
+
+count_down_event::~count_down_event()
+{ strategy::unregister_object_( id_); }
 
 uint32_t
 count_down_event::initial() const
@@ -39,19 +43,17 @@
                         return;
                 uint32_t expected = current_;
                 if ( detail::atomic_compare_exchange_strong( & current_, & expected, expected - 1) )
- return;
+ break;
         }
+ if ( 0 == detail::atomic_load( & current_) )
+ strategy::object_notify_all_( id_);
 }
 
 void
 count_down_event::wait()
 {
         while ( 0 != detail::atomic_load( & current_) )
- {
- this_fiber::interruption_point();
- this_fiber::yield();
- this_fiber::interruption_point();
- }
+ strategy::wait_for_object_( id_);
 }
 
 }}

Modified: sandbox/fiber/libs/fiber/src/fiber.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -8,7 +8,8 @@
 
 #include <boost/assert.hpp>
 
-#include <boost/fiber/detail/fiber_state.hpp>
+#include <boost/fiber/detail/interrupt_flags.hpp>
+#include <boost/fiber/detail/state_flags.hpp>
 #include <boost/fiber/exceptions.hpp>
 #include <boost/fiber/strategy.hpp>
 
@@ -18,11 +19,11 @@
 namespace fibers {
 
 #ifdef BOOST_HAS_RVALUE_REFS
-detail::fiber_info_base::ptr_t
+detail::info_base::ptr_t
 fiber::make_info_( std::size_t stack_size, void ( * fn)() )
 {
- return detail::fiber_info_base::ptr_t(
- new detail::fiber_info< void( *)() >( fn, stack_size) );
+ return detail::info_base::ptr_t(
+ new detail::info< void( *)() >( fn, stack_size) );
 }
 #endif
 
@@ -30,7 +31,7 @@
         info_base_()
 {}
 
-fiber::fiber( detail::fiber_info_base::ptr_t info_base) :
+fiber::fiber( detail::info_base::ptr_t info_base) :
         info_base_( info_base)
 {}
 
@@ -75,7 +76,7 @@
 }
 #endif
 
-detail::fiber_info_base::ptr_t
+detail::info_base::ptr_t
 fiber::info_() const
 { return info_base_; }
 

Deleted: sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,54 +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/fiber_info_base_posix.hpp>
-
-#include <cerrno>
-
-#include <boost/assert.hpp>
-#include <boost/system/system_error.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-fiber_info_base::fiber_info_base() :
- use_count( 0),
- stack_size( 0),
- priority( 0),
- uctx(),
- uctx_stack(),
- state( STATE_MASTER),
- interrupt( INTERRUPTION_DISABLED),
- at_exit()
-{}
-
-fiber_info_base::fiber_info_base( std::size_t stack_size_) :
- use_count( 0),
- stack_size( stack_size_),
- priority( 0),
- uctx(),
- uctx_stack( new char[stack_size]),
- state( STATE_NOT_STARTED),
- interrupt( INTERRUPTION_DISABLED)
-{
- BOOST_ASSERT( uctx_stack);
-
- if ( ::getcontext( & uctx) == -1)
- throw system::system_error(
- system::error_code(
- errno,
- system::system_category) );
- uctx.uc_stack.ss_sp = uctx_stack.get();
- uctx.uc_stack.ss_size = stack_size;
- uctx.uc_link = 0;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>

Deleted: sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
+++ (empty file)
@@ -1,52 +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/fiber_info_base_windows.hpp>
-
-#include <cerrno>
-
-#include <boost/assert.hpp>
-#include <boost/system/system_error.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace fibers {
-namespace detail {
-
-fiber_info_base::fiber_info_base() :
- use_count( 0),
- stack_size( 0),
- priority( 0),
- uctx(),
- state( STATE_MASTER),
- interrupt( INTERRUPTION_DISABLED),
- at_exit(),
- st( 0)
-{
- uctx = ::GetCurrentFiber();
- if ( ! uctx)
- throw system::system_error(
- system::error_code(
- ::GetLastError(),
- system::system_category) );
-}
-
-fiber_info_base::~fiber_info_base()
-{ if ( state != STATE_MASTER) ::DeleteFiber( uctx); }
-
-fiber_info_base::fiber_info_base( std::size_t stack_size_) :
- use_count( 0),
- stack_size( stack_size_),
- priority( 0),
- uctx(),
- state( STATE_NOT_STARTED),
- interrupt( INTERRUPTION_DISABLED)
-{}
-
-}}}
-
-#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-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -24,7 +24,7 @@
 namespace boost {
 namespace fibers {
 
-void trampoline( detail::fiber_info_base * self)
+void trampoline( detail::info_base * self)
 {
         BOOST_ASSERT( self);
         try
@@ -33,7 +33,7 @@
         catch (...) {}
         while ( ! self->at_exit.empty() )
         {
- detail::fiber_info_base::callable_t ca;
+ detail::info_base::callable_t ca;
                 self->at_exit.top().swap( ca);
                 self->at_exit.pop();
                 ca();
@@ -44,7 +44,7 @@
 void
 fiber::init_()
 {
- typedef void fn_type( detail::fiber_info_base *);
+ typedef void fn_type( detail::info_base *);
         typedef void ( * st_fn)();
         fn_type * fn_ptr( trampoline);
 

Modified: sandbox/fiber/libs/fiber/src/fiber_windows.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_windows.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_windows.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -40,8 +40,8 @@
 
 VOID CALLBACK trampoline( LPVOID vp)
 {
- detail::fiber_info_base * self(
- static_cast< detail::fiber_info_base * >( vp) );
+ detail::info_base * self(
+ static_cast< detail::info_base * >( vp) );
         BOOST_ASSERT( self);
         try
         { self->run(); }
@@ -49,7 +49,7 @@
         catch (...) {}
         while ( ! self->at_exit.empty() )
         {
- detail::fiber_info_base::callable_t ca;
+ detail::info_base::callable_t ca;
                 self->at_exit.top().swap( ca);
                 self->at_exit.pop();
                 ca();

Added: sandbox/fiber/libs/fiber/src/info_base_posix.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/info_base_posix.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,54 @@
+
+// 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/info_base_posix.hpp>
+
+#include <cerrno>
+
+#include <boost/assert.hpp>
+#include <boost/system/system_error.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+info_base::info_base() :
+ use_count( 0),
+ stack_size( 0),
+ priority( 0),
+ uctx(),
+ uctx_stack(),
+ state( STATE_MASTER),
+ interrupt( INTERRUPTION_DISABLED),
+ at_exit()
+{}
+
+info_base::info_base( std::size_t stack_size_) :
+ use_count( 0),
+ stack_size( stack_size_),
+ priority( 0),
+ uctx(),
+ uctx_stack( new char[stack_size]),
+ state( STATE_NOT_STARTED),
+ interrupt( INTERRUPTION_DISABLED)
+{
+ BOOST_ASSERT( uctx_stack);
+
+ if ( ::getcontext( & uctx) == -1)
+ throw system::system_error(
+ system::error_code(
+ errno,
+ system::system_category) );
+ uctx.uc_stack.ss_sp = uctx_stack.get();
+ uctx.uc_stack.ss_size = stack_size;
+ uctx.uc_link = 0;
+}
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>

Added: sandbox/fiber/libs/fiber/src/info_base_windows.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/info_base_windows.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -0,0 +1,52 @@
+
+// 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/info_base_windows.hpp>
+
+#include <cerrno>
+
+#include <boost/assert.hpp>
+#include <boost/system/system_error.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fibers {
+namespace detail {
+
+info_base::info_base() :
+ use_count( 0),
+ stack_size( 0),
+ priority( 0),
+ uctx(),
+ state( STATE_MASTER),
+ interrupt( INTERRUPTION_DISABLED),
+ at_exit(),
+ st( 0)
+{
+ uctx = ::GetCurrentFiber();
+ if ( ! uctx)
+ throw system::system_error(
+ system::error_code(
+ ::GetLastError(),
+ system::system_category) );
+}
+
+info_base::~info_base()
+{ if ( state != STATE_MASTER) ::DeleteFiber( uctx); }
+
+info_base::info_base( std::size_t stack_size_) :
+ use_count( 0),
+ stack_size( stack_size_),
+ priority( 0),
+ uctx(),
+ state( STATE_NOT_STARTED),
+ interrupt( INTERRUPTION_DISABLED)
+{}
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>

Modified: sandbox/fiber/libs/fiber/src/manual_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/manual_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/manual_reset_event.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -9,7 +9,7 @@
 #include <boost/assert.hpp>
 
 #include <boost/fiber/detail/atomic.hpp>
-#include <boost/fiber/utility.hpp>
+#include <boost/fiber/strategy.hpp>
 
 namespace boost {
 namespace fibers {
@@ -20,8 +20,12 @@
                         static_cast< uint32_t >( SET) :
                         static_cast< uint32_t >( RESET) ),
         waiters_( 0),
- enter_mtx_()
-{}
+ enter_mtx_(),
+ id_( * this)
+{ strategy::register_object_( id_); }
+
+manual_reset_event::~manual_reset_event()
+{ strategy::unregister_object_( id_); }
 
 void
 manual_reset_event::set()
@@ -34,6 +38,8 @@
                         static_cast< uint32_t >( SET) ) ||
                 ! detail::atomic_load( & waiters_ ) )
                 enter_mtx_.unlock();
+ else
+ strategy::object_notify_all_( id_);
 }
 
 void
@@ -56,11 +62,7 @@
         }
 
         while ( static_cast< uint32_t >( RESET) == detail::atomic_load( & state_) )
- {
- this_fiber::interruption_point();
- this_fiber::yield();
- this_fiber::interruption_point();
- }
+ strategy::wait_for_object_( id_);
 
         if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
                 enter_mtx_.unlock();

Modified: sandbox/fiber/libs/fiber/src/mutex.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/mutex.cpp (original)
+++ sandbox/fiber/libs/fiber/src/mutex.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -7,14 +7,18 @@
 #include <boost/fiber/mutex.hpp>
 
 #include <boost/fiber/detail/atomic.hpp>
-#include <boost/fiber/utility.hpp>
+#include <boost/fiber/strategy.hpp>
 
 namespace boost {
 namespace fibers {
 
 mutex::mutex() :
- state_( 0)
-{}
+ state_( 0),
+ id_( * this)
+{ strategy::register_object_( id_); }
+
+mutex::~mutex()
+{ strategy::unregister_object_( id_); }
 
 void
 mutex::lock()
@@ -25,7 +29,7 @@
                 if ( detail::atomic_compare_exchange_strong( & state_, & expected, 1) )
                         break;
                 else
- this_fiber::yield();
+ strategy::wait_for_object_( id_);
         }
 }
 
@@ -39,8 +43,8 @@
 void
 mutex::unlock()
 {
- uint32_t expected = 1;
- detail::atomic_compare_exchange_strong( & state_, & expected, 0);
+ detail::atomic_exchange( & state_, 0);
+ strategy::object_notify_one_( id_);
 }
 
 }}

Modified: sandbox/fiber/libs/fiber/src/round_robin.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/round_robin.cpp (original)
+++ sandbox/fiber/libs/fiber/src/round_robin.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -13,7 +13,6 @@
 #include <boost/foreach.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>
@@ -24,12 +23,13 @@
 round_robin::round_robin() :
         fibers_(),
         runnable_fibers_(),
- terminated_fibers_()
+ terminated_fibers_(),
+ objects_()
 {}
 
 round_robin::~round_robin()
 {
- BOOST_FOREACH( container::value_type va, fibers_)
+ BOOST_FOREACH( fiber_map::value_type va, fibers_)
         { detach( va.second.f); }
 }
 
@@ -62,26 +62,101 @@
 }
 
 void
-round_robin::yield( fiber::id const& id)
+round_robin::join( fiber::id const& id)
 {
- BOOST_ASSERT( active_fiber->get_id() == id);
- BOOST_ASSERT( in_state_running( ( * active_fiber) ) );
- BOOST_ASSERT( ! fibers_[active_fiber->get_id()].waiting_on);
+ BOOST_ASSERT( active_fiber.get() );
+ fiber_map::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ schedulable s( i->second);
+ fiber f( s.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! is_master( f) );
+ BOOST_ASSERT( ! in_state_not_started( f) );
 
- // set state ready
- set_state_ready( ( * active_fiber) );
+ // nothing to do for a terminated fiber
+ if ( in_state_terminated( f) ) return;
 
- // put fiber to runnable-queue
- runnable_fibers_.push_back( id);
+ // prevent self-join
+ if ( active_fiber->get_id() == id)
+ throw scheduler_error("self-join denied");
+
+ // register on fiber to be joined
+ fibers_[id].joining_fibers.push_back( active_fiber->get_id() );
+
+ // set state waiting
+ set_state_wait_for_fiber( ( * active_fiber) );
+
+ // set fiber-id waiting-on
+ fibers_[active_fiber->get_id()].waiting_on_fiber = id;
 
         // switch to master-fiber
         switch_between( * active_fiber, master_fiber);
+
+ // fiber returned
+ BOOST_ASSERT( in_state_running( ( * active_fiber) ) );
+ BOOST_ASSERT( ! fibers_[active_fiber->get_id()].waiting_on_fiber);
+
+ // check if interruption was requested
+ if ( interruption_enabled( * active_fiber) )
+ throw fiber_interrupted();
+}
+
+void
+round_robin::interrupt( fiber::id const& id)
+{
+ fiber_map::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ schedulable s( i->second);
+ fiber f( s.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! is_master( f) );
+ BOOST_ASSERT( ! in_state_not_started( f) );
+
+ // nothing to do for al terminated fiber
+ if ( in_state_terminated( f) ) return;
+
+ enable_interruption( f);
+
+ // if fiber is waiting
+ if ( in_state_wait_for_fiber( f) )
+ {
+ // 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_fiber);
+ fibers_[* s.waiting_on_fiber].joining_fibers.remove( id);
+ fibers_[id].waiting_on_fiber.reset();
+ set_state_ready( f);
+ runnable_fibers_.push_back( id);
+ } else if ( in_state_wait_for_object( f) ) {
+ // fiber is waiting on an object
+ // remove it from the waiting-queue, reset waiting-on
+ // and reset the waiting state
+ BOOST_ASSERT( s.waiting_on_object);
+ objects_.at( * s.waiting_on_object).remove( id);
+ fibers_[id].waiting_on_object.reset();
+ set_state_ready( f);
+ runnable_fibers_.push_back( id);
+ }
+}
+
+void
+round_robin::reschedule( fiber::id const& id)
+{
+ fiber_map::iterator i = fibers_.find( id);
+ if ( i == fibers_.end() ) return;
+ fiber f( i->second.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! is_master( f) );
+ BOOST_ASSERT( ! in_state_not_started( f) );
+ BOOST_ASSERT( ! in_state_terminated( f) );
 }
 
 void
 round_robin::cancel( fiber::id const& id)
 {
- container::iterator i = fibers_.find( id);
+ BOOST_ASSERT( active_fiber.get() );
+ fiber_map::iterator i = fibers_.find( id);
         if ( i == fibers_.end() ) return;
         schedulable s( i->second);
         fiber f( s.f);
@@ -97,11 +172,11 @@
         {
                 schedulable s__( fibers_[id__]);
                 fiber f__( s__.f);
- BOOST_ASSERT( s__.waiting_on);
- BOOST_ASSERT( in_state_wait_for_join( f__) );
+ BOOST_ASSERT( s__.waiting_on_fiber);
+ BOOST_ASSERT( in_state_wait_for_fiber( f__) );
 
                 // clear waiting-on
- fibers_[id__].waiting_on.reset();
+ fibers_[id__].waiting_on_fiber.reset();
 
                 // put fiber on runnable-queue
                 set_state_ready( f__);
@@ -131,11 +206,11 @@
         }
         // if fiber is waiting then remove it from the
         // waiting-queue and put it to terminated-queue
- else if ( in_state_wait_for_join( f) )
+ else if ( in_state_wait_for_fiber( f) )
         {
- BOOST_ASSERT( s.waiting_on);
+ BOOST_ASSERT( s.waiting_on_fiber);
                 set_state_terminated( f);
- fibers_[* s.waiting_on].joining_fibers.remove( id);
+ fibers_[* s.waiting_on_fiber].joining_fibers.remove( id);
                 terminated_fibers_.push( id);
         }
         else
@@ -143,84 +218,139 @@
 }
 
 void
-round_robin::join( fiber::id const& id)
+round_robin::yield()
 {
- container::iterator i = fibers_.find( id);
+ BOOST_ASSERT( active_fiber.get() );
+ BOOST_ASSERT( in_state_running( ( * active_fiber) ) );
+ BOOST_ASSERT( ! fibers_[active_fiber->get_id()].waiting_on_fiber);
+
+ // set state ready
+ set_state_ready( ( * active_fiber) );
+
+ // put fiber to runnable-queue
+ runnable_fibers_.push_back( active_fiber->get_id() );
+
+ // switch to master-fiber
+ switch_between( * active_fiber, master_fiber);
+}
+
+void
+round_robin::register_object( object::id const& oid)
+{
+ std::pair< object_map::iterator, bool > p(
+ objects_.insert(
+ std::make_pair( oid, fiber_id_list() ) ) );
+ BOOST_ASSERT( p.second);
+}
+
+void
+round_robin::unregister_object( object::id const& oid)
+{
+ BOOST_ASSERT( objects_.end() != objects_.find( oid) );
+ objects_.erase( oid);
+}
+
+void
+round_robin::wait_for_object( object::id const& oid)
+{
+ BOOST_ASSERT( active_fiber.get() );
+ fiber::id id = active_fiber->get_id();
+ fiber_map::iterator i = fibers_.find( id);
         if ( i == fibers_.end() ) return;
         schedulable s( i->second);
         fiber f( s.f);
         BOOST_ASSERT( f);
         BOOST_ASSERT( ! is_master( f) );
- BOOST_ASSERT( ! in_state_not_started( f) );
-
- // nothing to do for a terminated fiber
- if ( in_state_terminated( f) ) return;
-
- // prevent self-join
- if ( active_fiber->get_id() == id)
- throw scheduler_error("self-join denied");
-
- // register on fiber to be joined
- fibers_[id].joining_fibers.push_back( active_fiber->get_id() );
-
+ BOOST_ASSERT( active_fiber->get_id() == id);
+ BOOST_ASSERT( in_state_running( f) );
+ BOOST_ASSERT( ! s.waiting_on_fiber);
+ BOOST_ASSERT( ! s.waiting_on_object);
+
+ // register on object to be waiting on
+ objects_.at( oid).push_back( id);
+
         // set state waiting
- set_state_wait_for_join( ( * active_fiber) );
-
- // set fiber-id waiting-on
- fibers_[active_fiber->get_id()].waiting_on = id;
+ set_state_wait_for_object( f);
+
+ // set object-id waiting-on
+ fibers_[id].waiting_on_object = oid;
 
         // switch to master-fiber
         switch_between( * active_fiber, master_fiber);
 
         // fiber returned
- BOOST_ASSERT( in_state_running( ( * active_fiber) ) );
- BOOST_ASSERT( ! fibers_[active_fiber->get_id()].waiting_on);
+ BOOST_ASSERT( active_fiber->get_id() == id);
+ BOOST_ASSERT( in_state_running( fibers_[id].f) );
+ BOOST_ASSERT( ! fibers_[id].waiting_on_fiber);
+ BOOST_ASSERT( ! fibers_[id].waiting_on_object);
 
         // check if interruption was requested
- if ( interruption_enabled( * active_fiber) )
+ if ( interruption_enabled( f) )
                 throw fiber_interrupted();
 }
 
 void
-round_robin::interrupt( fiber::id const& id)
+round_robin::object_notify_one( object::id const& oid)
 {
- container::iterator i = fibers_.find( id);
- if ( i == fibers_.end() ) return;
- schedulable s( i->second);
+ object_map::iterator oi( objects_.find( oid) );
+ BOOST_ASSERT( oi != objects_.end() );
+ if ( oi->second.empty() ) return;
+ fiber::id id( oi->second.front() );
+ oi->second.pop_front();
+
+ fiber_map::iterator fi = fibers_.find( id);
+ BOOST_ASSERT( fi != fibers_.end() );
+ schedulable s( fi->second);
         fiber f( s.f);
         BOOST_ASSERT( f);
         BOOST_ASSERT( ! is_master( f) );
- BOOST_ASSERT( ! in_state_not_started( f) );
-
- // nothing to do for al terminated fiber
- if ( in_state_terminated( f) ) return;
+ BOOST_ASSERT( ! s.waiting_on_fiber);
+ BOOST_ASSERT( s.waiting_on_object);
+ BOOST_ASSERT( * s.waiting_on_object == oid);
+
+ // remove object waiting for
+ fibers_[id].waiting_on_object.reset();
+
+ // set state ready
+ set_state_ready( f);
 
- enable_interruption( f);
+ // put fiber to runnable-queue
+ runnable_fibers_.push_back( id);
+}
 
- // if fiber is waiting
- if ( in_state_wait_for_join( f) )
+void
+round_robin::object_notify_all( object::id const& oid)
+{
+ object_map::iterator oi( objects_.find( oid) );
+ BOOST_ASSERT( oi != objects_.end() );
+ fiber_id_list::iterator fe( oi->second.end() );
+ for (
+ fiber_id_list::iterator fi( oi->second.begin() );
+ fi != fe;
+ ++fi)
         {
- // 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();
+ fiber::id id( * fi);
+
+ fiber_map::iterator i = fibers_.find( id);
+ BOOST_ASSERT( i != fibers_.end() );
+ schedulable s( i->second);
+ fiber f( s.f);
+ BOOST_ASSERT( f);
+ BOOST_ASSERT( ! is_master( f) );
+ BOOST_ASSERT( ! s.waiting_on_fiber);
+ BOOST_ASSERT( s.waiting_on_object);
+ BOOST_ASSERT( * s.waiting_on_object == oid);
+
+ // remove object waiting for
+ fibers_[id].waiting_on_object.reset();
+
+ // set state ready
                 set_state_ready( f);
+
+ // put fiber to runnable-queue
                 runnable_fibers_.push_back( id);
         }
-}
-
-void
-round_robin::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( ! is_master( f) );
- BOOST_ASSERT( ! in_state_not_started( f) );
- BOOST_ASSERT( ! in_state_terminated( f) );
+ oi->second.clear();
 }
 
 bool
@@ -232,7 +362,7 @@
                 schedulable s = fibers_[runnable_fibers_.front()];
                 std::auto_ptr< fiber > orig( active_fiber.release() );
                 active_fiber.reset( new fiber( s.f) );
- BOOST_ASSERT( ! s.waiting_on);
+ BOOST_ASSERT( ! s.waiting_on_fiber);
                 BOOST_ASSERT( in_state_ready( ( * active_fiber) ) );
                 set_state_running( ( * active_fiber) );
                 switch_between( master_fiber, * active_fiber);

Modified: sandbox/fiber/libs/fiber/src/strategy.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/strategy.cpp (original)
+++ sandbox/fiber/libs/fiber/src/strategy.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -1,22 +1,25 @@
 #include <boost/fiber/strategy.hpp>
 
+#include <utility>
+
 #include <boost/assert.hpp>
 
-#include <boost/fiber/detail/fiber_info.hpp>
-#include <boost/fiber/detail/fiber_info_base.hpp>
+#include <boost/fiber/detail/info.hpp>
+#include <boost/fiber/detail/info_base.hpp>
+#include <boost/fiber/detail/state_flags.hpp>
 #include <boost/fiber/exceptions.hpp>
 
 namespace boost {
 namespace fibers {
 
-strategy::active_fiber_t strategy::active_fiber;
+strategy::fiber_t strategy::active_fiber;
 
 bool
-strategy::runs_as_fiber()
+strategy::runs_as_fiber_()
 { return active_fiber.get() != 0; }
 
 fiber::id
-strategy::get_id()
+strategy::get_id_()
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
@@ -24,24 +27,24 @@
 }
 
 void
-strategy::interruption_point()
+strategy::interruption_point_()
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
- if ( active->info_()->interrupt == detail::INTERRUPTION_ENABLED)
+ if ( detail::INTERRUPTION_ENABLED == active->info_()->interrupt)
                 throw fiber_interrupted();
 }
 
 bool
-strategy::interruption_requested()
+strategy::interruption_requested_()
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
         return active->interruption_requested();
 }
 
-detail::fiber_interrupt_t &
-strategy::interrupt_flags()
+detail::interrupt_t &
+strategy::interrupt_flags_()
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
@@ -49,7 +52,7 @@
 }
 
 bool
-strategy::interruption_enabled()
+strategy::interruption_enabled_()
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
@@ -57,7 +60,7 @@
 }
 
 int
-strategy::priority()
+strategy::priority_()
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
@@ -65,7 +68,7 @@
 }
 
 void
-strategy::priority( int prio)
+strategy::priority_( int prio)
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
@@ -73,7 +76,7 @@
 }
 
 void
-strategy::at_fiber_exit( callable_t ca)
+strategy::at_fiber_exit_( callable_t ca)
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
@@ -81,21 +84,66 @@
 }
 
 void
-strategy::yield()
+strategy::yield_()
+{
+ fiber * active( active_fiber.get() );
+ if ( ! active) throw fiber_error("not a fiber");
+ if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
+ active->info_()->st->yield();
+}
+
+void
+strategy::cancel_()
+{
+ fiber * active( active_fiber.get() );
+ if ( ! active) throw fiber_error("not a fiber");
+ if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
+ active->info_()->st->cancel( active_fiber->get_id() );
+}
+
+void
+strategy::register_object_( object::id const& oid)
+{
+ fiber * active( active_fiber.get() );
+ if ( ! active) throw fiber_error("not a fiber");
+ if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
+ active->info_()->st->register_object( oid);
+}
+
+void
+strategy::unregister_object_( object::id const& oid)
+{
+ fiber * active( active_fiber.get() );
+ if ( ! active) throw fiber_error("not a fiber");
+ if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
+ active->info_()->st->unregister_object( oid);
+}
+
+void
+strategy::wait_for_object_( object::id const& oid)
+{
+ fiber * active( active_fiber.get() );
+ if ( ! active) throw fiber_error("not a fiber");
+ if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
+ active->info_()->st->wait_for_object( oid);
+}
+
+void
+strategy::object_notify_one_( object::id const& oid)
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
         if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
- active->info_()->st->yield( active->get_id() );
+ active->info_()->st->object_notify_one( oid);
 }
 
 void
-strategy::cancel()
+strategy::object_notify_all_( object::id const& oid)
 {
         fiber * active( active_fiber.get() );
         if ( ! active) throw fiber_error("not a fiber");
         if ( ! active->info_()->st) throw scheduler_error("no valid scheduler");
- active->info_()->st->cancel( active->get_id() );
+ active->info_()->st->object_notify_all( oid);
 }
 
 strategy::strategy() :
@@ -103,8 +151,9 @@
 {
         fiber::convert_thread_to_fiber();
         master_fiber = fiber(
- detail::fiber_info_base::ptr_t(
- new detail::fiber_info_default() ) );
+ detail::info_base::ptr_t(
+ new detail::info_default() ) );
+ attach( master_fiber);
 }
 
 strategy::~strategy()
@@ -138,7 +187,7 @@
 
 bool
 strategy::is_master( fiber const& f)
-{ return master_fiber == f; }
+{ return f == master_fiber; }
 
 bool
 strategy::in_state_not_started( fiber const& f)
@@ -153,8 +202,12 @@
 { return detail::STATE_RUNNING == f.info_()->state; }
 
 bool
-strategy::in_state_wait_for_join( fiber const& f)
-{ return detail::STATE_WAIT_FOR_JOIN == f.info_()->state; }
+strategy::in_state_wait_for_fiber( fiber const& f)
+{ return detail::STATE_WAIT_FOR_FIBER == f.info_()->state; }
+
+bool
+strategy::in_state_wait_for_object( fiber const& f)
+{ return detail::STATE_WAIT_FOR_OBJECT == f.info_()->state; }
 
 bool
 strategy::in_state_terminated( fiber const& f)
@@ -169,8 +222,12 @@
 { f.info_()->state = detail::STATE_RUNNING; }
 
 void
-strategy::set_state_wait_for_join( fiber & f)
-{ f.info_()->state = detail::STATE_WAIT_FOR_JOIN; }
+strategy::set_state_wait_for_fiber( fiber & f)
+{ f.info_()->state = detail::STATE_WAIT_FOR_FIBER; }
+
+void
+strategy::set_state_wait_for_object( fiber & f)
+{ f.info_()->state = detail::STATE_WAIT_FOR_OBJECT; }
 
 void
 strategy::set_state_terminated( fiber & f)

Modified: sandbox/fiber/libs/fiber/test/Jamfile.v2
==============================================================================
--- sandbox/fiber/libs/fiber/test/Jamfile.v2 (original)
+++ sandbox/fiber/libs/fiber/test/Jamfile.v2 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -33,10 +33,10 @@
     [ fiber-test test_join ]
     [ fiber-test test_interrupt ]
     [ fiber-test test_at_exit ]
- [ fiber-test test_mutex ]
- [ fiber-test test_auto_reset_event ]
- [ fiber-test test_manual_reset_event ]
- [ fiber-test test_count_down_event ]
- [ fiber-test test_unique_lock ]
- [ fiber-test test_condition ]
+# [ fiber-test test_mutex ]
+# [ fiber-test test_auto_reset_event ]
+# [ fiber-test test_manual_reset_event ]
+# [ fiber-test test_count_down_event ]
+# [ fiber-test test_unique_lock ]
+# [ fiber-test test_condition ]
     ;

Modified: sandbox/fiber/libs/fiber/test/test_auto_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_auto_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_auto_reset_event.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -102,6 +102,7 @@
 void test_case_3()
 {
         boost::fibers::auto_reset_event ev;
+ boost::fibers::scheduler<> sched;
 
         BOOST_CHECK_EQUAL( false, ev.try_wait() );
 

Modified: sandbox/fiber/libs/fiber/test/test_condition.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_condition.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_condition.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -57,11 +57,11 @@
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
@@ -73,13 +73,16 @@
         BOOST_CHECK_EQUAL( 0, value);
 
         BOOST_CHECK( sched.run() );
- BOOST_CHECK( sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
         BOOST_CHECK( sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
         BOOST_CHECK_EQUAL( 1, value);
+
+ BOOST_CHECK( ! sched.run() );
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK_EQUAL( 1, value);
 }
 
 void test_case_2()
@@ -107,7 +110,7 @@
         BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
@@ -120,20 +123,28 @@
 
         BOOST_CHECK( sched.run() );
         BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 3), sched.size() );
- BOOST_CHECK_EQUAL( 0, value);
-
- BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
- BOOST_CHECK_EQUAL( 0, value);
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
+ BOOST_CHECK_EQUAL( 1, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 1, value);
 
+ sched.make_fiber(
+ notify_one_fn,
+ boost::ref( cond) );
+
         BOOST_CHECK( sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 1, value);
+
+ BOOST_CHECK( sched.run() );
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK_EQUAL( 2, value);
+
+ BOOST_CHECK( ! sched.run() );
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK_EQUAL( 2, value);
 }
 
 void test_case_3()
@@ -161,7 +172,7 @@
         BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
         BOOST_CHECK_EQUAL( 0, value);
 
@@ -174,16 +185,16 @@
 
         BOOST_CHECK( sched.run() );
         BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 3), sched.size() );
- BOOST_CHECK_EQUAL( 0, value);
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
+ BOOST_CHECK_EQUAL( 1, value);
 
         BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
- BOOST_CHECK_EQUAL( 0, value);
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK_EQUAL( 2, value);
 
- BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
- BOOST_CHECK_EQUAL( 1, value);
+ BOOST_CHECK( ! sched.run() );
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK_EQUAL( 2, value);
 
         sched.make_fiber(
                 wait_fn,
@@ -194,11 +205,11 @@
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 2, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 2, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 2, value);
 
@@ -208,10 +219,10 @@
 
         BOOST_CHECK( sched.run() );
         BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
- BOOST_CHECK_EQUAL( 2, value);
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK_EQUAL( 3, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
         BOOST_CHECK_EQUAL( 3, value);
 }

Modified: sandbox/fiber/libs/fiber/test/test_count_down_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_count_down_event.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_count_down_event.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -31,6 +31,7 @@
 {
         boost::uint32_t n = 3;
         boost::fibers::count_down_event ev( n);
+ boost::fibers::scheduler<> sched;
 
         BOOST_CHECK_EQUAL( ev.initial(), n);
         BOOST_CHECK_EQUAL( ev.current(), n);
@@ -66,12 +67,14 @@
                 wait_fn,
                 boost::ref( ev) );
 
- for ( boost::uint32_t i = 0; i < n - 1; ++i)
- {
- ev.set();
- BOOST_CHECK( sched.run() );
- BOOST_CHECK( value != 1);
- }
+ ev.set();
+ BOOST_CHECK( sched.run() );
+ BOOST_CHECK( value != 1);
+
+ ev.set();
+ BOOST_CHECK( ! sched.run() );
+ BOOST_CHECK( value != 1);
+
         ev.set();
         BOOST_CHECK( sched.run() );
         BOOST_CHECK_EQUAL( ev.initial(), n);

Modified: sandbox/fiber/libs/fiber/test/test_manual_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_manual_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_manual_reset_event.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -92,7 +92,7 @@
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 1, value);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 1, value);
 
@@ -131,6 +131,7 @@
 void test_case_4()
 {
         boost::fibers::manual_reset_event ev;
+ boost::fibers::scheduler<> sched;
 
         BOOST_CHECK_EQUAL( false, ev.try_wait() );
 

Modified: sandbox/fiber/libs/fiber/test/test_mutex.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_mutex.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_mutex.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -30,7 +30,6 @@
     void operator()()
     {
         mutex_type mutex;
- boost::fibers::condition condition;
 
         // Test the lock's constructors.
         {
@@ -53,7 +52,7 @@
     test_lock< boost::fibers::mutex >()();
 }
 
-void test_case1()
+void test_1()
 {
         boost::fibers::scheduler<> sched;
     sched.make_fiber( & do_test_mutex);
@@ -73,11 +72,12 @@
 
 void test_fn2( boost::fibers::mutex & mtx)
 {
+ ++value2;
         boost::fibers::mutex::scoped_lock lk( mtx);
         ++value2;
 }
 
-void test_case2()
+void test_2()
 {
         boost::fibers::mutex mtx;
         boost::fibers::scheduler<> sched;
@@ -95,29 +95,46 @@
         BOOST_CHECK( sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
         BOOST_CHECK_EQUAL( 1, value1);
- BOOST_CHECK_EQUAL( 0, value2);
+ BOOST_CHECK_EQUAL( 1, value2);
 
         BOOST_CHECK( sched.run() );
         BOOST_CHECK( sched.run() );
         BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
- BOOST_CHECK_EQUAL( 1, value1);
- BOOST_CHECK_EQUAL( 0, value2);
-
- BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 2), sched.size() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 1, value1);
- BOOST_CHECK_EQUAL( 0, value2);
+ BOOST_CHECK_EQUAL( 1, value2);
 
         BOOST_CHECK( sched.run() );
- BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
         BOOST_CHECK_EQUAL( 1, value1);
- BOOST_CHECK_EQUAL( 0, value2);
+ BOOST_CHECK_EQUAL( 2, value2);
 
- BOOST_CHECK( sched.run() );
+ BOOST_CHECK( ! sched.run() );
         BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
         BOOST_CHECK_EQUAL( 1, value1);
- BOOST_CHECK_EQUAL( 1, value2);
+ BOOST_CHECK_EQUAL( 2, value2);
+}
+
+void test_case1()
+{
+ boost::fibers::scheduler<> sched;
+ sched.make_fiber( & test_1);
+ for (;;)
+ {
+ while ( sched.run() );
+ if ( sched.empty() ) break;
+ }
+}
+
+void test_case2()
+{
+ boost::fibers::scheduler<> sched;
+ sched.make_fiber( & test_2);
+ for (;;)
+ {
+ while ( sched.run() );
+ if ( sched.empty() ) break;
+ }
 }
 
 boost::unit_test::test_suite * init_unit_test_suite( int, char* [])

Modified: sandbox/fiber/libs/fiber/test/test_scheduler.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_scheduler.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_scheduler.cpp 2009-12-05 03:26:16 EST (Sat, 05 Dec 2009)
@@ -181,13 +181,13 @@
         BOOST_CHECK_EQUAL( std::size_t( 1), sched.size() );
         BOOST_CHECK_EQUAL( 0, value1);
         BOOST_CHECK_EQUAL( 0, value2);
-
+
         for (;;)
         {
                 while ( sched.run() );
                 if ( sched.empty() ) break;
         }
-
+
         BOOST_CHECK( ! sched.run() );
         BOOST_CHECK( sched.empty() );
         BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );


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