$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r57438 - in sandbox/fiber: boost boost/fiber boost/fiber/detail libs/fiber/build libs/fiber/examples libs/fiber/src libs/fiber/test
From: oliver.kowalke_at_[hidden]
Date: 2009-11-06 15:36:06
Author: olli
Date: 2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
New Revision: 57438
URL: http://svn.boost.org/trac/boost/changeset/57438
Log:
- rework -> with scheduler
Added:
   sandbox/fiber/boost/fiber/attributes.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/detail/config.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/detail/fiber.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/detail/fiber_info.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/detail/scheduler_data.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/scheduler.hpp   (contents, props changed)
   sandbox/fiber/boost/fiber/utility.hpp   (contents, props changed)
   sandbox/fiber/libs/fiber/build/Jamfile.v2   (contents, props changed)
   sandbox/fiber/libs/fiber/examples/
   sandbox/fiber/libs/fiber/examples/Jamfile.v2   (contents, props changed)
   sandbox/fiber/libs/fiber/examples/simple.cpp   (contents, props changed)
   sandbox/fiber/libs/fiber/src/
   sandbox/fiber/libs/fiber/src/attributes.cpp   (contents, props changed)
   sandbox/fiber/libs/fiber/src/fiber.cpp   (contents, props changed)
   sandbox/fiber/libs/fiber/src/fiber_info_posix.cpp   (contents, props changed)
   sandbox/fiber/libs/fiber/src/fiber_posix.cpp   (contents, props changed)
   sandbox/fiber/libs/fiber/src/scheduler.cpp   (contents, props changed)
   sandbox/fiber/libs/fiber/test/Jamfile.v2   (contents, props changed)
   sandbox/fiber/libs/fiber/test/test_fiber.cpp   (contents, props changed)
Removed:
   sandbox/fiber/boost/fiber/context.hpp
   sandbox/fiber/boost/fiber/detail/context.hpp
   sandbox/fiber/boost/fiber/detail/fiber_base.hpp
   sandbox/fiber/boost/fiber/detail/fiber_base_posix.hpp
   sandbox/fiber/boost/fiber/detail/fiber_base_windows.hpp
   sandbox/fiber/boost/fiber/fiber.hpp
   sandbox/fiber/boost/fiber/result.hpp
   sandbox/fiber/boost/fiber/stacksize.hpp
   sandbox/fiber/boost/fiber/wrapper.hpp
Text files modified: 
   sandbox/fiber/boost/fiber.hpp            |    25 ++++++++++++-------------               
   sandbox/fiber/boost/fiber/exceptions.hpp |    28 +++++++++++++++-------------            
   2 files changed, 27 insertions(+), 26 deletions(-)
Modified: sandbox/fiber/boost/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber.hpp	(original)
+++ sandbox/fiber/boost/fiber.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -1,16 +1,15 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_FIBERS_H
-#define BOOST_FIBERS_FIBERS_H
+//          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/fibers/fiber.hpp>
-#include <boost/fibers/context.hpp>
-#include <boost/fibers/exceptions.hpp>
-#include <boost/fibers/result.hpp>
-#include <boost/fibers/stacksize.hpp>
-#include <boost/fibers/wrapper.hpp>
+#ifndef BOOST_FIBER_H
+#define BOOST_FIBER_H
 
-#endif // BOOST_FIBERS_FIBERS_H
- 
+#include <boost/fiber/attributes.hpp>
+#include <boost/fiber/exceptions.hpp>
+#include <boost/fiber/scheduler.hpp>
+#include <boost/fiber/utility.hpp>
+
+#endif // BOOST_FIBER_H
Added: sandbox/fiber/boost/fiber/attributes.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/attributes.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,36 @@
+
+//          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_ATTRIBUTES_H
+#define BOOST_FIBER_ATTRIBUTES_H
+
+#include <cstddef>
+
+#include <boost/fiber/detail/config.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+class BOOST_FIBER_DECL attributes
+{
+private:
+	std::size_t		stacksize_;
+
+public:
+	attributes();
+
+	void stack_size( std::size_t stacksize);
+
+	std::size_t stack_size() const;
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_ATTRIBUTES_H
Deleted: sandbox/fiber/boost/fiber/context.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/context.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,18 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_CONTEXT_H
-#define BOOST_FIBERS_CONTEXT_H
-
-#include <boost/fibers/detail/context.hpp>
-#include <boost/fibers/detail/fiber_base.hpp>
-
-namespace boost {
-namespace fibers
-{
-typedef detail::context< detail::fiber_base >	context;
-} }
-
-#endif // BOOST_FIBERS_CONTEXT_H
-
Added: sandbox/fiber/boost/fiber/detail/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/config.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,90 @@
+
+//          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)
+
+// this file is based on config.hpp of boost.thread
+
+#ifndef BOOST_FIBER_DETAIL_CONFIG_H
+#define BOOST_FIBER_DETAIL_CONFIG_H
+
+#include <boost/config.hpp>
+#include <boost/detail/workaround.hpp>
+
+# if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
+#   pragma warn -8008 // Condition always true/false
+#   pragma warn -8080 // Identifier declared but never used
+#   pragma warn -8057 // Parameter never used
+#   pragma warn -8066 // Unreachable code
+# endif
+
+# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FIBER_DYN_LINK)
+#   undef  BOOST_FIBER_USE_LIB
+#   define BOOST_FIBER_USE_DLL
+# endif
+
+# if defined(BOOST_WINDOWS_API) && defined(BOOST_POSIX_API)
+#   error "Both BOOST_WINDOWS_API and BOOST_POSIX_API are defined!"
+# elif ! defined(BOOST_WINDOWS_API ) && ! defined(BOOST_POSIX_API)
+#   if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
+#     define BOOST_WINDOWS_API
+#   else
+#     define BOOST_POSIX_API
+#   endif
+# endif
+
+# if defined(BOOST_FIBER_BUILD_DLL)   //Build dll
+# elif defined(BOOST_FIBER_BUILD_LIB) //Build lib
+# elif defined(BOOST_FIBER_USE_DLL)   //Use dll
+# elif defined(BOOST_FIBER_USE_LIB)   //Use lib
+# else //Use default
+#   if defined(BOOST_FIBER_PLATFORM_WIN32)
+#      if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN)
+            //For compilers supporting auto-tss cleanup
+            //with Boost.Threads lib, use Boost.Threads lib
+#         define BOOST_FIBER_USE_LIB
+#      else
+            //For compilers not yet supporting auto-tss cleanup
+            //with Boost.Threads lib, use Boost.Threads dll
+#         define BOOST_FIBER_USE_DLL
+#      endif
+#   else
+#      define BOOST_FIBER_USE_LIB
+#   endif
+# endif
+
+# if defined(BOOST_HAS_DECLSPEC)
+#   if defined(BOOST_FIBER_BUILD_DLL) //Build dll
+#      define BOOST_FIBER_DECL __declspec(dllexport)
+#   elif defined(BOOST_FIBER_USE_DLL) //Use dll
+#      define BOOST_FIBER_DECL __declspec(dllimport)
+#   else
+#      define BOOST_FIBER_DECL
+#   endif
+# else
+#   define BOOST_FIBER_DECL
+# endif
+
+// Automatically link to the correct build variant where possible.
+# if ! defined(BOOST_ALL_NO_LIB) && ! defined(BOOST_FIBER_NO_LIB) && ! defined(BOOST_FIBER_BUILD_DLL) && ! defined(BOOST_FIBER_BUILD_LIB)
+
+// Tell the autolink to link dynamically, this will get undef'ed by auto_link.hpp
+# if defined(BOOST_FIBER_USE_DLL)
+#   define BOOST_DYN_LINK
+# endif
+
+// Set the name of our library, this will get undef'ed by auto_link.hpp
+# if defined(BOOST_FIBER_LIB_NAME)
+#   define BOOST_LIB_NAME BOOST_FIBER_LIB_NAME
+# else
+#   define BOOST_LIB_NAME boost_fiber
+# endif
+
+// If we're importing code from a dll, then tell auto_link.hpp about it
+// And include the header that does the work
+#include <boost/config/auto_link.hpp>
+# endif  // auto-linking disabled
+
+#endif // BOOST_FIBER_DETAIL_CONFIG_H
+
Deleted: sandbox/fiber/boost/fiber/detail/context.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/context.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,32 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_CONTEXT_H
-#define BOOST_FIBERS_DETAIL_CONTEXT_H
-
-namespace boost { namespace fibers {
-namespace detail
-{
-template< typename FiberBase >
-class context
-{
-private:
-	FiberBase &	fib_;
-
-public:
-	context( FiberBase & fib)
-	: fib_( fib)
-	{}
-
-	void yield()
-	{ fib_.yield(); }
-
-	template< typename Fiber >
-	void yield_to( Fiber & to)
-	{ fib_.yield_to( * to.impl_); }
-};
-} } }
-
-#endif // BOOST_FIBERS_DETAIL_CONTEXT_H
-
Added: sandbox/fiber/boost/fiber/detail/fiber.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/fiber.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,160 @@
+
+//          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
+
Deleted: sandbox/fiber/boost/fiber/detail/fiber_base.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_base.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,18 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_BASE_H
-#define BOOST_FIBERS_DETAIL_FIBER_BASE_H
-
-#include <boost/config.hpp>
-
-#if defined(_POSIX_VERSION)
-#include <boost/fibers/detail/fiber_base_posix.hpp>
-#elif defined(BOOST_WINDOWS)
-#include <boost/fibers/detail/fiber_base_windows.hpp>
-#else 
-#error "Boost fibers unavailable on this platform"
-#endif
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_BASE_H
Deleted: sandbox/fiber/boost/fiber/detail/fiber_base_posix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_base_posix.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,195 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_BASE_POSIX_H
-#define BOOST_FIBERS_DETAIL_FIBER_BASE_POSIX_H
-
-extern "C"
-{
-#include <ucontext.h>
-}
-
-#include <cstddef>
-#include <utility>
-
-#include <boost/assert.hpp>
-#include <boost/function.hpp>
-#include <boost/shared_array.hpp>
-#include <boost/system/system_error.hpp>
-
-#include <boost/fibers/detail/context.hpp>
-
-namespace boost { namespace fibers {
-namespace detail
-{
-template< typename Fiber >
-void trampoline( Fiber * fib)
-{
-	BOOST_ASSERT( fib);
-	context< Fiber > ctxt( * fib);
-	BOOST_ASSERT( ! fib->fn_.empty() );
-	fib->fn_( ctxt);
-	fib->exit();
-}
-
-class fiber_base
-{
-private:
-	enum st_state
-	{
-		st_uninitialized = 0,
-		st_ready = 1,
-		st_running = 2,
-		st_exited = 3
-	};
-
-	template< typename Fiber >
-	friend
-	void trampoline( Fiber *);
-
-	function< void( context< fiber_base > &) >	fn_;
-	std::size_t									stack_size_;
-	::ucontext_t								caller_;
-	::ucontext_t								callee_;
-	shared_array< char >						stack_;
-	st_state									state_;
-
-	bool uninitialized_() const
-	{ return state_ == st_uninitialized; }
-
-	bool ready_() const
-	{ return state_ == st_ready; }
-
-	bool running_() const
-	{ return state_ == st_running; }
-
-	bool exited_() const
-	{ return state_ == st_exited; }
-
-	void yield_()
-	{
-		if ( ::swapcontext( & callee_, & caller_) == -1)
-			throw system::system_error(
-				system::error_code(
-					errno,
-					system::system_category) );
-	}
-
-	void yield_to_( fiber_base & to)
-	{
-		std::swap( caller_, to.caller_);
-		std::swap( state_, to.state_);
-		if ( ::swapcontext( & callee_, & to.callee_) == -1)
-			throw system::system_error(
-				system::error_code(
-					errno,
-					system::system_category) );
-	}
-
-	void run_()
-	{
-		if ( ::swapcontext( & caller_, & callee_) == -1)
-			throw system::system_error(
-				system::error_code(
-					errno,
-					system::system_category) );
-	}
-
-	void init_()
-	{
-		BOOST_ASSERT( state_ == st_uninitialized);
-
-		if ( ::getcontext( & caller_) == -1)
-			throw system::system_error(
-				system::error_code(
-					errno,
-					system::system_category) );
-		BOOST_ASSERT( stack_);
-		if ( ::getcontext( & callee_) == -1)
-			throw system::system_error(
-				system::error_code(
-					errno,
-					system::system_category) );
-		callee_.uc_stack.ss_sp = stack_.get();
-		callee_.uc_stack.ss_size = stack_size_;
-		callee_.uc_link = 0;
-		typedef void fn_type( fiber_base *);
-		typedef void ( * st_fn)();
-		fn_type * fn_ptr( trampoline< fiber_base >);
-
-		::makecontext(
-			& callee_,
-			( st_fn)( fn_ptr),
-			1,
-			this);
-
-		state_ = st_ready;
-	}
-
-public:
-	fiber_base(
-		function< void( context< fiber_base > &) > fn,
-		std::size_t stack_size)
-	:
-	fn_( fn),
-	stack_size_( stack_size),
-	caller_(),
-	callee_(),
-	stack_( new char[stack_size]),
-	state_( st_uninitialized)
-	{
-		BOOST_ASSERT( ! fn_.empty() );
-		BOOST_ASSERT( stack_size_ > 0);
-	}
-
-	~fiber_base()
-	{ BOOST_ASSERT( ! running_() ); }
-
-	bool ready() const
-	{ return uninitialized_() || ready_(); }
-
-    bool running() const
-	{ return running_(); }
-
-    bool exited() const
-	{ return exited_(); }
-
-	void yield()
-	{
-		BOOST_ASSERT( running_() );
-		state_ = st_ready;
-		yield_();
-		BOOST_ASSERT( running_() );
-	}
-
-	void yield_to( fiber_base & to)
-	{
-		BOOST_ASSERT( running_() );
-		if ( to.uninitialized_() ) to.init_();
-		yield_to_( to);
-		BOOST_ASSERT( running_() );
-	}
-
-	void run()
-	{
-		BOOST_ASSERT( uninitialized_() || ready_() );
-		if ( uninitialized_() ) init_();
-		BOOST_ASSERT( ready_() );
-		state_ = st_running;
-		run_();
-		BOOST_ASSERT( ready_() || exited_() );
-	}
-
-	void exit()
-	{
-		BOOST_ASSERT( running_() ) ;
-		state_ = st_exited;
-		yield_();
-		BOOST_ASSERT(!"should never be reached");
-	}
-};
-} } }
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_BASE_POSIX_H
-
Deleted: sandbox/fiber/boost/fiber/detail/fiber_base_windows.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_base_windows.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,255 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_BASE_WINDOWS_H
-#define BOOST_FIBERS_DETAIL_FIBER_BASE_WINDOWS_H
-
-extern "C"
-{
-#include <windows.h>
-#include <winnt.h>
-}
-
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/function.hpp>
-#include <boost/system/system_error.hpp>
-
-#include <boost/fibers/detail/context.hpp>
-
-namespace boost { namespace fibers {
-namespace detail
-{
-template< typename Fiber >
-VOID CALLBACK trampoline( LPVOID vp)
-{
-	Fiber * fib( static_cast< Fiber * >( vp) );
-	BOOST_ASSERT( fib);
-	context< Fiber > ctxt( * fib);
-	BOOST_ASSERT( ! fib->fn_.empty() );
-	fib->fn_( ctxt);
-	fib->exit();
-}
-
-class fiber_base
-{
-private:
-	enum st_state
-	{
-		st_uninitialized = 0,
-		st_ready = 1,
-		st_running = 2,
-		st_exited = 3
-	};
-
-	template< typename Fiber >
-	friend
-	VOID CALLBACK trampoline( LPVOID);
-
-    function< void( context< fiber_base > &) >	fn_;
-	std::size_t									stack_size_;
-	LPVOID										caller_;
-	LPVOID										callee_;
-	st_state									state_;
-
-	bool uninitialized_() const
-	{ return state_ == st_uninitialized; }
-
-	bool ready_() const
-	{ return state_ == st_ready; }
-
-	bool running_() const
-	{ return state_ == st_running; }
-
-	bool exited_() const
-	{ return state_ == st_exited; }
-
-	bool is_fiber_()
-	{
-#if (_WIN32_WINNT >= 0x0600)
-		return ::IsThreadAFiber() == TRUE;
-#else
-		LPVOID current( ::GetCurrentFiber() );
-		return current != 0 && current != reinterpret_cast< LPVOID >( 0x1E00);
-#endif
-	}
-
-	void yield_()
-	{
-		if( ! is_fiber_() )
-		{
-			BOOST_ASSERT( ! callee_);
-			callee_ = ::ConvertThreadToFiber( 0);
-			if ( ! callee_)
-				throw system::system_error(
-					system::error_code(
-						::GetLastError(),
-						system::system_category) );
-			::SwitchToFiber( caller_);
-			BOOL result = ::ConvertFiberToThread();
-			if ( ! result)
-				throw system::system_error(
-					system::error_code(
-						::GetLastError(),
-						system::system_category) );
-			caller_ = 0;
-		}
-		else
-		{
-			if ( ! callee_)
-				callee_ = ::GetCurrentFiber();
-			::SwitchToFiber( caller_);
-			if ( ! callee_)
-				callee_ = 0;
-		}
-	}
-
-	void yield_to_( fiber_base & to)
-	{
-		std::swap( caller_, to.caller_);
-		std::swap( state_, to.state_);
-		if( ! is_fiber_() )
-		{
-			BOOST_ASSERT( ! callee_);
-			callee_ = ::ConvertThreadToFiber( 0);
-			if ( ! callee_)
-				throw system::system_error(
-					system::error_code(
-						::GetLastError(),
-						system::system_category) );
-			::SwitchToFiber( to.callee_);
-			BOOL result = ::ConvertFiberToThread();
-			if ( ! result)
-				throw system::system_error(
-					system::error_code(
-						::GetLastError(),
-						system::system_category) );
-			caller_ = 0;
-		}
-		else
-		{
-			if ( ! callee_)
-				callee_ = ::GetCurrentFiber();
-			::SwitchToFiber( to.callee_);
-			if ( ! callee_)
-				callee_ = 0;
-		}
-	}
-
-	void run_()
-	{
-		if( ! is_fiber_() )
-		{
-			BOOST_ASSERT( ! caller_);
-			caller_ = ::ConvertThreadToFiber( 0);
-			if ( ! caller_)
-				throw system::system_error(
-					system::error_code(
-						::GetLastError(),
-						system::system_category) );
-			::SwitchToFiber( callee_);
-			BOOL result = ::ConvertFiberToThread();
-			if ( ! result)
-				throw system::system_error(
-					system::error_code(
-						::GetLastError(),
-						system::system_category) );
-			caller_ = 0;
-		}
-		else
-		{
-			if ( ! caller_)
-				caller_ = ::GetCurrentFiber();
-			::SwitchToFiber( callee_);
-			if ( ! caller_)
-				caller_ = 0;
-		}
-	}
-
-	void init_()
-	{
-		BOOST_ASSERT( state_ == st_uninitialized);
-
-		callee_ = ::CreateFiber(
-			stack_size_,
-			static_cast< LPFIBER_START_ROUTINE >( & trampoline< fiber_base >),
-			static_cast< LPVOID >( this) );
-		if ( ! callee_)
-			throw system::system_error(
-				system::error_code(
-					::GetLastError(),
-					system::system_category) );
-
-		state_ = st_ready;
-	}
-
-public:
-	fiber_base(
-		function< void( context< fiber_base > &) > fn,
-		std::size_t stack_size)
-	:
-	fn_( fn),
-	stack_size_( stack_size),
-	caller_( 0),
-	callee_( 0),
-	state_( st_uninitialized)
-	{
-		BOOST_ASSERT( ! fn_.empty() );
-		BOOST_ASSERT( stack_size_ > 0);
-	}
-
-	~fiber_base()
-	{
-		BOOST_ASSERT( ! running_() );
-		::DeleteFiber( callee_);
-	}
-
-	bool ready() const
-	{ return uninitialized_() || ready_(); }
-
-    bool running() const
-	{ return running_(); }
-
-    bool exited() const
-	{ return exited_(); }
-
-	void yield()
-	{
-		BOOST_ASSERT( running_() );
-		state_ = st_ready;
-		yield_();
-		BOOST_ASSERT( running_() );
-	}
-
-	void yield_to( fiber_base & to)
-	{
-		BOOST_ASSERT( running_() );
-		if ( to.uninitialized_() ) to.init_();
-		yield_to_( to);
-		BOOST_ASSERT( running_() );
-	}
-
-	void run()
-	{
-		BOOST_ASSERT( uninitialized_() || ready_() );
-		if ( uninitialized_() ) init_();
-		BOOST_ASSERT( ready_() );
-		state_ = st_running;
-		run_();
-		BOOST_ASSERT( ready_() || exited_() );
-	}
-
-	void exit()
-	{
-		BOOST_ASSERT( running_() || ready_() ) ;
-		state_ = st_exited;
-		yield_();
-		BOOST_ASSERT(!"should never be reached");
-	}
-};
-} } }
-
-#endif // BOOST_FIBERS_DETAIL_FIBER_BASE_WINDOWS_H
-
Added: sandbox/fiber/boost/fiber/detail/fiber_info.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/fiber_info.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 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_FIBER_DETAIL_FIBER_INFO_H
+#define BOOST_FIBER_DETAIL_FIBER_INFO_H
+
+extern "C" {
+
+#include <ucontext.h>
+
+}
+
+#include <boost/config.hpp>
+#include <boost/function.hpp>
+#include <boost/shared_array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+#include <boost/fiber/attributes.hpp>
+#include <boost/fiber/detail/config.hpp>
+
+# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#include <boost/fiber/detail/fiber_info_windows.hpp>
+
+# elif defined(_POSIX_VERSION)
+#include <boost/fiber/detail/fiber_info_posix.hpp>
+
+# endif
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+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() {}
+};
+
+template< typename Fn >
+class fiber_info : public fiber_info_base
+{
+private:
+	Fn	fn_;
+
+	fiber_info( fiber_info &);
+	fiber_info & operator=( fiber_info const&);
+
+public:
+	fiber_info( Fn fn, attributes const& attribs) :
+		fiber_info_base( attribs),
+		fn_( fn)
+	{}
+
+	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, attributes const& attribs) :
+		fiber_info_base( attribs),
+		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, attributes const& attribs) :
+		fiber_info_base( attribs),
+		fn_( fn)
+	{}
+	
+	void run()
+	{ fn_(); }
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_DETAIL_FIBER_INFO_H
Added: sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,49 @@
+
+//          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_POSIX_H
+#define BOOST_FIBER_DETAIL_FIBER_INFO_BASE_POSIX_H
+
+extern "C" {
+
+#include <ucontext.h>
+
+}
+
+#include <boost/shared_array.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include <boost/fiber/attributes.hpp>
+#include <boost/fiber/detail/config.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+namespace detail {
+
+struct BOOST_FIBER_DECL fiber_info_base
+{
+	typedef shared_ptr< fiber_info_base >	sptr_t;
+
+	attributes				attribs;
+	::ucontext_t			uctx;
+	shared_array< char >	uctx_stack;
+
+	fiber_info_base();
+
+	fiber_info_base( attributes const& attribs_);
+
+	virtual ~fiber_info_base() {}
+
+	virtual void run() = 0;
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_DETAIL_FIBER_INFO_BASE_POSIX_H
Added: sandbox/fiber/boost/fiber/detail/scheduler_data.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/detail/scheduler_data.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,46 @@
+
+//          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 >		run_queue;
+	std::queue< fiber::id >		zombie_queue;
+
+	scheduler_data() :
+		master(),
+		f_id(),
+		fibers(),
+		run_queue(),
+		zombie_queue()
+	{}
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_DETAIL_SCHEDULER_DATA_H
Modified: sandbox/fiber/boost/fiber/exceptions.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/exceptions.hpp	(original)
+++ sandbox/fiber/boost/fiber/exceptions.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -1,24 +1,26 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_EXCEPTIONS_H
-#define BOOST_FIBERS_EXCEPTIONS_H
+//          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_EXCEPTIONS_H
+#define BOOST_FIBER_EXCEPTIONS_H
 
 #include <stdexcept>
 #include <string>
 
 namespace boost {
-namespace fibers
-{
-class invalid_stacksize
-: public std::invalid_argument
+namespace fiber {
+
+class scheduler_error : public std::runtime_error
 {
 public:
-    invalid_stacksize( std::string const& msg)
-	: std::invalid_argument( msg)
+    scheduler_error( std::string const& msg)
+	: std::runtime_error( msg)
         {}
 };
-} }
 
-#endif // BOOST_FIBERS_EXCEPTIONS_H
+}}
+
+#endif // BOOST_FIBER_EXCEPTIONS_H
Deleted: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/fiber.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,60 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_FIBER_H
-#define BOOST_FIBERS_FIBER_H
-
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/fibers/detail/fiber_base.hpp>
-#include <boost/fibers/stacksize.hpp>
-
-namespace boost {
-namespace fibers
-{
-class fiber
-: private noncopyable
-{
-private:
-	template< typename Fiber >
-	friend
-	class detail::context;
-
-	shared_ptr< detail::fiber_base >	impl_;
-
-public:
-	enum { default_stack_size = 16384 };
-
-	template< typename Act >
-	fiber(
-		Act act,
-		stacksize const& stack_size = stacksize( default_stack_size) )
-	: impl_( new detail::fiber_base( act, stack_size) )
-	{}
-
-	bool exited() const
-	{ return impl_->exited(); }
-
-	bool ready() const
-	{ return impl_->ready(); }
-
-	bool running() const
-	{ return impl_->running(); }
-
-	void run()
-	{ impl_->run(); }
-
-	void yield()
-	{ impl_->yield(); }
-
-	void yield_to( fiber & to)
-	{ impl_->yield_to( * to.impl_); }
-};
-
-} }
-
-#endif // BOOST_FIBERS_FIBER_H
-
Deleted: sandbox/fiber/boost/fiber/result.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/result.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,235 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_RESULT_H
-#define BOOST_FIBERS_RESULT_H
-
-#include <boost/exception.hpp>
-#include <boost/exception_ptr.hpp>
-#include <boost/function.hpp>
-#include <boost/thread.hpp>
-
-#include <boost/fibers/context.hpp>
-
-namespace boost {
-namespace fibers
-{
-#define CATCH_ENABLE_CURRENT_EXCEPTION( Exception)	\
-  catch ( Exception const& e)						\
-  { throw boost::enable_current_exception( e); }
-
-template< typename R >
-class result
-{
-private:
-	struct impl
-	{
-		virtual ~impl() {}
-		virtual void operator()( context &) = 0;
-		virtual bool ready() const = 0;
-		virtual bool has_value() const = 0;
-		virtual bool has_exception() const = 0;
-		virtual R get() const = 0;
-	};
-
-	template< typename Act >
-	class impl_wrapper
-	: public impl
-	{
-	private:
-		Act				act_;
-		R				r_;
-		bool			ready_;
-		exception_ptr	except_ptr_;
-
-	public:
-		impl_wrapper( Act const& act)
-		:
-		act_( act),
-		r_(),
-		ready_( false),
-		except_ptr_()
-		{}
-
-		void operator()( context & ctxt)
-		{
-			try
-			{
-				try
-				{ r_ = act_( ctxt); }
-				CATCH_ENABLE_CURRENT_EXCEPTION( thread_interrupted )
-				CATCH_ENABLE_CURRENT_EXCEPTION( exception )
-
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::domain_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::invalid_argument )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::length_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::out_of_range )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::logic_error )
-
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::overflow_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::range_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::underflow_error)
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::runtime_error )
-
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_alloc )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_cast )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_typeid )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_exception )
-
-				// iostreams library
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::ios_base::failure )
-			}
-			catch ( ... )
-			{ except_ptr_ = current_exception(); }
-			ready_ = true;
-		}
-
-		bool ready() const
-		{ return ready_; }
-
-		bool has_value() const
-		{ return ready() && ! except_ptr_; }
-
-		bool has_exception() const
-		{ return ready() && except_ptr_; }
-
-		R get() const
-		{
-			if ( except_ptr_) rethrow_exception( except_ptr_);
-			return r_;
-		}
-	};
-
-	shared_ptr< impl >	impl_;
-
-public:
-	template< typename Act >
-	result( Act act)
-	: impl_( new impl_wrapper< Act >( act) )
-	{}
-
-	void operator()( context & ctxt)
-	{ ( * impl_)( ctxt); }
-
-	bool ready() const
-	{ return impl_->ready(); }
-
-	bool has_value() const
-	{ return impl_->has_value(); }
-
-	bool has_exception() const
-	{ return impl_->has_exception(); }
-
-	R get() const
-	{ return impl_->get(); }
-};
-
-
-template<>
-class result< void >
-{
-private:
-	struct impl
-	{
-		virtual ~impl() {}
-		virtual void operator()( context &) = 0;
-		virtual bool ready() const = 0;
-		virtual bool has_value() const = 0;
-		virtual bool has_exception() const = 0;
-		virtual void get() const = 0;
-	};
-
-	template< typename Act >
-	class impl_wrapper
-	: public impl
-	{
-	private:
-		Act				act_;
-		bool			ready_;
-		exception_ptr	except_ptr_;
-
-	public:
-		impl_wrapper( Act const& act)
-		:
-		act_( act),
-		ready_( false),
-		except_ptr_()
-		{}
-
-		void operator()( context & ctxt)
-		{
-			try
-			{
-				try
-				{ act_( ctxt); }
-				CATCH_ENABLE_CURRENT_EXCEPTION( thread_interrupted )
-				CATCH_ENABLE_CURRENT_EXCEPTION( exception )
-
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::overflow_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::range_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::underflow_error)
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::runtime_error )
-
-				// logic_error standard subclasses
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::domain_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::invalid_argument )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::length_error )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::out_of_range )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::logic_error )
-
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_alloc )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_cast )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_typeid )
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::bad_exception )
-
-				// iostreams library
-				CATCH_ENABLE_CURRENT_EXCEPTION( std::ios_base::failure )
-			}
-			catch ( ... )
-			{ except_ptr_ = current_exception(); }
-			ready_ = true;
-		}
-
-		bool ready() const
-		{ return ready_; }
-
-		bool has_value() const
-		{ return ready() && ! except_ptr_; }
-
-		bool has_exception() const
-		{ return ready() && except_ptr_; }
-
-		void get() const
-		{ if ( except_ptr_) rethrow_exception( except_ptr_); }
-	};
-
-	shared_ptr< impl >	impl_;
-
-public:
-	template< typename Act >
-	result( Act act)
-	: impl_( new impl_wrapper< Act >( act) )
-	{}
-
-	void operator()( context & ctxt)
-	{ ( * impl_)( ctxt); }
-
-	bool ready() const
-	{ return impl_->ready(); }
-
-	bool has_value() const
-	{ return impl_->has_value(); }
-
-	bool has_exception() const
-	{ return impl_->has_exception(); }
-
-	void get() const
-	{ impl_->get(); }
-};
-
-#undef CATCH_ENABLE_CURRENT_EXCEPTION
-} }
-
-#endif // BOOST_FIBERS_RESULT_H
-
Added: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/scheduler.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,106 @@
+
+//          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_SCHEDULER_H
+#define BOOST_FIBER_SCHEDULER_H
+
+#include <cstddef>
+#include <memory>
+
+#include <boost/preprocessor/repetition.hpp>
+#include <boost/thread/tss.hpp>
+#include <boost/utility.hpp>
+
+#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/config/abi_prefix.hpp>
+
+namespace boost {
+
+namespace this_fiber {
+
+fiber::id get_id();
+void yield();
+
+}
+
+namespace fiber {
+
+class BOOST_FIBER_DECL scheduler : private noncopyable
+{
+private:
+	friend void detail::trampoline( detail::fiber *);
+	friend id this_fiber::get_id();
+	friend void this_fiber::yield();
+
+	typedef thread_specific_ptr< detail::scheduler_data >	data_ptr_t;
+
+	static data_ptr_t	data;
+
+	static fiber::id get_id();
+
+	static void yield();
+
+	static void exit();
+
+	detail::scheduler_data * access_data();
+
+	void add( std::auto_ptr< detail::fiber >);
+
+public:
+	scheduler();
+
+	template< typename Fn >
+	void make_fiber( Fn fn, attributes attrs = attributes() )
+	{
+		add(
+			std::auto_ptr< detail::fiber >(
+				new detail::fiber( fn, attrs) ) );
+	}
+
+#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_MAKE_FIBER_FUNCTION(z, n, unused)	\
+	template<											\
+		typename Fn,									\
+		BOOST_PP_ENUM_PARAMS(n, typename A)				\
+	>													\
+	void make_fiber( Fn fn, attributes const& attribs, BOOST_ENUM_FIBER_ARGS(n))	\
+	{																				\
+		add(																		\
+			std::auto_ptr< detail::fiber >(											\
+				new detail::fiber(													\
+					boost::bind(													\
+						boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a) ),	\
+					attribs) ) );													\
+	}
+
+BOOST_PP_REPEAT_FROM_TO( 1, BOOST_FIBER_MAX_ARITY, BOOST_FIBER_MAKE_FIBER_FUNCTION, ~)
+
+#undef BOOST_FIBER_MAKE_FIBER_FUNCTION
+#undef BOOST_FIBER_MAX_ARITY
+
+	bool run();
+
+	bool empty();
+
+	std::size_t size();
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_FIBER_SCHEDULER_H
Deleted: sandbox/fiber/boost/fiber/stacksize.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/stacksize.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,30 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_STACKSIZE_H
-#define BOOST_FIBERS_STACKSIZE_H
-
-#include <cstddef>
-
-#include <boost/fibers/exceptions.hpp>
-
-namespace boost {
-namespace fibers
-{
-class stacksize
-{
-private:
-	std::size_t	value_;
-
-public:
-	explicit stacksize( std::size_t value)
-	: value_( value)
-	{ if ( value <= 0) throw invalid_stacksize("stacksize must be greater than zero"); }
-
-	operator std::size_t () const
-	{ return value_; }
-};
-} }
-
-#endif // BOOST_FIBERS_STACKSIZE_H
Added: sandbox/fiber/boost/fiber/utility.hpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/boost/fiber/utility.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,42 @@
+
+//          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_THIS_FIBER_UTILITY_H
+#define BOOST_THIS_FIBER_UTILITY_H
+
+#include <boost/config.hpp>
+#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/scheduler.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace this_fiber {
+
+inline
+fiber::id get_id()
+{ return fiber::scheduler::get_id(); }
+
+inline
+void yield()
+{ fiber::scheduler::yield(); }
+
+inline
+void sleep( system_time const& abs_time)
+{}
+
+template< typename TimeDuration >
+void sleep( TimeDuration const& rel_time)
+{}
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_THIS_FIBER_UTILITY_H
\ No newline at end of file
Deleted: sandbox/fiber/boost/fiber/wrapper.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/wrapper.hpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
+++ (empty file)
@@ -1,34 +0,0 @@
-//  Copyright (c) 2008 Oliver Kowalke. 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_WRAPPER_H
-#define BOOST_FIBERS_WRAPPER_H
-
-#include <boost/fibers/context.hpp>
-
-namespace boost {
-namespace fibers
-{
-template< typename Act >
-class wrapper
-{
-private:
-	Act	act_;
-
-public:
-	wrapper( Act act)
-	: act_( act)
-	{}
-
-	typename Act::result_type operator()( context &)
-	{ return act_(); }
-};
-
-template< typename Act >
-wrapper< Act > wrap( Act act)
-{ return wrapper< Act >( act); }
-} }
-
-#endif // BOOST_FIBERS_WRAPPER_H
-
Added: sandbox/fiber/libs/fiber/build/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/build/Jamfile.v2	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,66 @@
+# Boost.fiber Library Build Jamfile
+
+#          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)
+
+import os ;
+import feature ;
+import indirect ;
+import path ;
+
+project boost/fiber
+    : source-location
+        ../src
+    : requirements
+        <library>/boost/thread//boost_thread
+        <library>/boost/system//boost_system
+        <link>static:<define>BOOST_FIBER_BUILD_LIB=1
+        <link>shared:<define>BOOST_FIBER_BUILD_DLL=1
+        <threading>multi
+    : default-build
+        <threading>multi
+    ;
+
+local rule default_fiberapi ( )
+{
+    local api = posix ;
+    if [ os.name ] = "NT" { api = win32 ; }
+    return $(api) ;
+}
+
+feature.feature fiberapi : posix win32 : propagated ;
+feature.set-default fiberapi : [ default_fiberapi ] ;
+
+alias fiber_sources
+    : ## win32 sources ##
+	attributes.cpp
+	fiber.cpp
+	fiber_info_windows.cpp
+	fiber_windows.cpp
+	scheduler.cpp
+    : ## requirements ##
+      <fiberapi>win32
+    ;
+
+alias fiber_sources
+    : ## posix sources ##
+	attributes.cpp
+	fiber.cpp
+	fiber_info_posix.cpp
+	fiber_posix.cpp
+	scheduler.cpp
+    : ## requirements ##
+      <fiberapi>posix
+    ;
+
+explicit fiber_sources ;
+
+lib boost_fiber
+    : fiber_sources
+    : <link>shared:<define>BOOST_FIBER_USE_DLL=1
+      <link>static:<define>BOOST_FIBER_USE_LIB=1
+   ;
+
+boost-install boost_fiber ;
Added: sandbox/fiber/libs/fiber/examples/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/examples/Jamfile.v2	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,26 @@
+# Boost.Fiber Library Examples Jamfile
+
+#          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)
+
+# For more information, see http://www.boost.org/
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+	lib socket ;
+}
+
+project boost/fiber/example
+    : requirements
+        <library>../../thread/build//boost_thread
+        <library>../../system/build//boost_system
+        <library>../build//boost_fiber
+        <link>static
+        <threading>multi
+    ;
+
+exe simple : simple.cpp ;
Added: sandbox/fiber/libs/fiber/examples/simple.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/examples/simple.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,50 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <boost/bind.hpp>
+#include <boost/system/system_error.hpp>
+
+#include <boost/fiber.hpp>
+
+inline
+void f( std::string const& str, int n)
+{
+	for ( int i = 0; i < n; ++i)
+	{
+		std::cout << i << ": " << str << std::endl;
+		boost::this_fiber::yield();
+	}
+}
+
+int main()
+{
+	try
+	{
+		boost::fiber::scheduler sched;
+
+		sched.make_fiber( & f, boost::fiber::attributes(), "abc", 5);
+		sched.make_fiber( & f, boost::fiber::attributes(), "xyz", 7);
+
+		std::cout << "start" << std::endl;
+
+		for (;;)
+		{
+			while ( sched.run() );
+			if ( sched.empty() ) break;
+		}
+
+		std::cout << "finish" << std::endl;
+
+		return EXIT_SUCCESS;
+	}
+	catch ( boost::system::system_error const& e)
+	{ std::cerr << "system_error: " << e.code().value() << std::endl; }
+	catch ( boost::fiber::scheduler_error const& e)
+	{ std::cerr << "scheduler_error: " << e.what() << std::endl; }
+	catch ( std::exception const& e)
+	{ std::cerr << "exception: " << e.what() << std::endl; }
+	catch (...)
+	{ std::cerr << "unhandled exception" << std::endl; }
+	return EXIT_FAILURE;
+}
Added: sandbox/fiber/libs/fiber/src/attributes.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/attributes.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,34 @@
+
+//          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/attributes.hpp>
+
+#include <stdexcept>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+attributes::attributes() :
+	stacksize_( 64000)
+{}
+
+void
+attributes::stack_size( std::size_t stacksize)
+{
+	if ( stacksize < 1)
+		throw std::invalid_argument("invalid stacksize");
+	stacksize_ = stacksize;
+}
+
+std::size_t
+attributes::stack_size() const
+{ return stacksize_; }
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
Added: sandbox/fiber/libs/fiber/src/fiber.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/fiber.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,62 @@
+
+//          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.hpp>
+
+#include <boost/assert.hpp>
+
+#include <boost/fiber/scheduler.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+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_)
+{}
+
+fiber::~fiber()
+{}
+
+void
+fiber::swap( fiber & other)
+{ info.swap( other.info); }
+
+fiber::id
+fiber::get_id() const
+{ return fiber::id( info); }
+
+bool
+fiber::operator==( fiber const& other) const
+{ return get_id() == other.get_id(); }
+
+bool
+fiber::operator!=( fiber const& other) const
+{ return !( get_id() == other.get_id() ); }
+
+void trampoline( fiber * self)
+{
+	BOOST_ASSERT( self);
+	BOOST_ASSERT( self->info);
+	self->info->run();
+ 	scheduler::exit();
+}
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+
Added: sandbox/fiber/libs/fiber/src/fiber_info_posix.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/fiber_info_posix.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,45 @@
+
+//          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_posix.hpp>
+
+#include <cerrno>
+
+#include <boost/assert.hpp>
+#include <boost/system/system_error.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+namespace detail {
+
+fiber_info_base::fiber_info_base() :
+	attribs(),
+	uctx(),
+	uctx_stack()
+{}
+
+fiber_info_base::fiber_info_base( attributes const& attribs_) :
+	attribs( attribs_),
+	uctx(),
+	uctx_stack( new char[attribs.stack_size()])
+{
+	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 = attribs.stack_size();
+	uctx.uc_link = 0;
+}
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
Added: sandbox/fiber/libs/fiber/src/fiber_posix.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/fiber_posix.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,53 @@
+
+//          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.hpp>
+
+extern "C" {
+
+#include <ucontext.h>
+
+}
+
+#include <cerrno>
+
+#include <boost/system/system_error.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+namespace detail {
+
+void
+fiber::init()
+{
+	typedef void fn_type( fiber *);
+	typedef void ( * st_fn)();
+	fn_type * fn_ptr( trampoline);
+
+	::makecontext(
+		& info->uctx,
+		( st_fn)( fn_ptr),
+		1,
+		this);
+}
+
+void
+fiber::switch_to( fiber & to)
+{
+	if ( ::swapcontext( & info->uctx, & to.info->uctx) != 0)
+		throw system::system_error(
+			system::error_code(
+				errno,
+				system::system_category) );
+}
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+
Added: sandbox/fiber/libs/fiber/src/scheduler.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/src/scheduler.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,104 @@
+
+//          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/scheduler.hpp>
+
+#include <boost/assert.hpp>
+#include <boost/ptr_container/ptr_map.hpp>
+
+#include <boost/fiber/exceptions.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace fiber {
+
+scheduler::data_ptr_t scheduler::data;
+
+fiber::id
+scheduler::get_id()
+{
+	detail::scheduler_data * dt( data.get() );
+	BOOST_ASSERT( dt);
+	return dt->f_id;
+}
+
+void
+scheduler::yield()
+{
+	detail::scheduler_data * dt( data.get() );
+	BOOST_ASSERT( dt);
+	dt->run_queue.push( dt->f_id);
+	dt->fibers[dt->f_id].switch_to( dt->master);
+}
+
+void
+scheduler::exit()
+{
+	detail::scheduler_data * dt( data.get() );
+	BOOST_ASSERT( dt);
+	dt->zombie_queue.push( dt->f_id);
+	dt->fibers[dt->f_id].switch_to( dt->master);
+}
+
+scheduler::scheduler()
+{}
+
+detail::scheduler_data *
+scheduler::access_data()
+{
+	if ( ! data.get() )
+	{
+		detail::fiber::convert_thread_to_fiber();
+		data.reset( new detail::scheduler_data() );
+	}
+	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->run_queue.push( result.first->first);
+}
+
+bool
+scheduler::run()
+{
+	detail::scheduler_data * dt = access_data();
+
+	if ( ! dt->run_queue.empty() )
+	{
+		dt->f_id = dt->run_queue.front();
+		dt->master.switch_to( dt->fibers[dt->f_id]);
+		dt->run_queue.pop();
+		return true;
+	}
+	if ( ! dt->zombie_queue.empty() )
+	{
+		dt->fibers.erase( dt->zombie_queue.front() );
+		dt->zombie_queue.pop();
+		return true;
+	}
+	return false;
+}
+
+bool
+scheduler::empty()
+{ return access_data()->fibers.empty(); }
+
+std::size_t
+scheduler::size()
+{ return access_data()->fibers.size(); }
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
Added: sandbox/fiber/libs/fiber/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/test/Jamfile.v2	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,29 @@
+# Boost.fiber Library Tests Jamfile
+
+#          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)
+
+import testing ;
+
+project boost/fiber/test
+    : requirements
+        <library>../../test/build//boost_unit_test_framework
+        <library>../../thread/build//boost_thread
+        <library>../../system/build//boost_system
+        <library>../build//boost_fiber
+        <link>static
+        <threading>multi
+    ;
+
+rule fiber-test ( source )
+{
+    return
+        [ run $(source).cpp ]
+    ;
+}
+
+test-suite fiber :
+    [ fiber-test test_fiber ]
+    ;
Added: sandbox/fiber/libs/fiber/test/test_fiber.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/test/test_fiber.cpp	2009-11-06 15:36:03 EST (Fri, 06 Nov 2009)
@@ -0,0 +1,62 @@
+
+//          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 <sstream>
+#include <string>
+
+#include <boost/test/unit_test.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/fiber.hpp>
+
+void zero_args_fn() {}
+
+// check fiber
+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_CHECK( f1 != f2);
+
+	std::ostringstream os1;
+	os1 << f1.get_id();
+	std::ostringstream os2;
+	os2 << f2.get_id();
+
+	std::string not_a_fiber("{not-a-fiber}");
+	BOOST_CHECK( os1.str() != os2.str() );
+	BOOST_CHECK( os1.str() != not_a_fiber);
+	BOOST_CHECK( os2.str() != not_a_fiber);
+}
+
+// check swap
+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::id id1 = f1.get_id();
+	boost::fiber::id id2 = f2.get_id();
+
+	f1.swap( f2);
+
+	BOOST_CHECK_EQUAL( f1.get_id(), id2);
+	BOOST_CHECK_EQUAL( f2.get_id(), id1);
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+	boost::unit_test::test_suite * test =
+		BOOST_TEST_SUITE("Boost.Fiber: fiber test suite");
+
+	test->add( BOOST_TEST_CASE( & test_case_1) );
+	test->add( BOOST_TEST_CASE( & test_case_2) );
+
+	return test;
+}