Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57690 - in sandbox/fiber: boost/fiber boost/fiber/detail libs/fiber/src
From: oliver.kowalke_at_[hidden]
Date: 2009-11-15 15:18:40


Author: olli
Date: 2009-11-15 15:18:39 EST (Sun, 15 Nov 2009)
New Revision: 57690
URL: http://svn.boost.org/trac/boost/changeset/57690

Log:
- corrections for Windows
- thread-specific-ptr removed from scheduler
Text files modified:
   sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp | 5 +
   sandbox/fiber/boost/fiber/scheduler.hpp | 20 ++++----
   sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp | 6 +
   sandbox/fiber/libs/fiber/src/fiber_windows.cpp | 25 +++++------
   sandbox/fiber/libs/fiber/src/scheduler.cpp | 81 +++++++++++++++------------------------
   5 files changed, 59 insertions(+), 78 deletions(-)

Modified: sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp (original)
+++ sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp 2009-11-15 15:18:39 EST (Sun, 15 Nov 2009)
@@ -7,10 +7,11 @@
 #ifndef BOOST_FIBERS_DETAIL_FIBER_INFO_WINDOWS_H
 #define BOOST_FIBERS_DETAIL_FIBER_INFO_WINDOWS_H
 
+#define _WIN32_WINNT 0x0501
+
 extern "C" {
 
 #include <windows.h>
-#include <winnt.h>
 
 }
 
@@ -40,7 +41,7 @@
 
         fiber_info_base( attributes const&);
 
- virtual ~fiber_info_base() {}
+ virtual ~fiber_info_base();
 
         virtual void run() = 0;
 

Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-11-15 15:18:39 EST (Sun, 15 Nov 2009)
@@ -11,7 +11,7 @@
 #include <memory>
 
 #include <boost/preprocessor/repetition.hpp>
-#include <boost/thread/tss.hpp>
+#include <boost/scoped_ptr.hpp>
 #include <boost/utility.hpp>
 
 #include <boost/fiber/attributes.hpp>
@@ -26,7 +26,7 @@
 namespace this_fiber {
 
 bool runs_as_fiber();
-fiber::fiber::id get_id();
+boost::fiber::id get_id();
 void yield();
 void cancel();
 void suspend();
@@ -49,9 +49,9 @@
         friend void this_fiber::priority( int);
         friend class fiber;
 
- typedef thread_specific_ptr< detail::scheduler_impl > tss_impl_t;
+ typedef scoped_ptr< detail::scheduler_impl > impl_t;
 
- static tss_impl_t impl_;
+ static impl_t impl_;
 
         static bool runs_as_fiber();
 
@@ -77,9 +77,9 @@
 
         static void join( fiber::id const&);
 
- detail::scheduler_impl * access_();
-
 public:
+ scheduler();
+
         ~scheduler();
 
         bool run();
@@ -92,11 +92,11 @@
 
         template< typename Fn >
         void make_fiber( Fn fn)
- { access_()->add_fiber( fiber( fn) ); }
+ { impl_->add_fiber( fiber( fn) ); }
 
         template< typename Fn >
         void make_fiber( attributes attrs, Fn fn)
- { access_()->add_fiber( fiber( attrs, fn) ); }
+ { impl_->add_fiber( fiber( attrs, fn) ); }
 
 #ifndef BOOST_FIBER_MAX_ARITY
 #define BOOST_FIBER_MAX_ARITY 10
@@ -109,10 +109,10 @@
 #define BOOST_FIBER_MAKE_FIBER_FUNCTION(z, n, unused) \
         template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
         void make_fiber( Fn fn, BOOST_ENUM_FIBER_ARGS(n)) \
- { access_()->add_fiber( fiber( fn, BOOST_PP_ENUM_PARAMS(n, a) ) ); } \
+ { impl_->add_fiber( fiber( fn, BOOST_PP_ENUM_PARAMS(n, a) ) ); } \
         template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
         void make_fiber( attributes const& attrs, Fn fn, BOOST_ENUM_FIBER_ARGS(n)) \
- { access_()->add_fiber( fiber( attrs, fn, BOOST_PP_ENUM_PARAMS(n, a) ) ); }
+ { impl_->add_fiber( fiber( attrs, fn, BOOST_PP_ENUM_PARAMS(n, a) ) ); }
 
 BOOST_PP_REPEAT_FROM_TO( 1, BOOST_FIBER_MAX_ARITY, BOOST_FIBER_MAKE_FIBER_FUNCTION, ~)
 

Modified: sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp 2009-11-15 15:18:39 EST (Sun, 15 Nov 2009)
@@ -4,7 +4,9 @@
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <boost/fiber/detail/fiber_info_base_posix.hpp>
+#define _WIN32_WINNT 0x0501
+
+#include <boost/fiber/detail/fiber_info_base_windows.hpp>
 
 #include <cerrno>
 
@@ -32,7 +34,7 @@
 }
 
 fiber_info_base::~fiber_info_base()
-{ ::DeleteFiber( uctx); }
+{ if ( state != STATE_MASTER) ::DeleteFiber( uctx); }
 
 fiber_info_base::fiber_info_base( attributes const& attrs_) :
         use_count( 0),

Modified: sandbox/fiber/libs/fiber/src/fiber_windows.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_windows.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_windows.cpp 2009-11-15 15:18:39 EST (Sun, 15 Nov 2009)
@@ -4,12 +4,13 @@
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#define _WIN32_WINNT 0x0501
+
 #include <boost/fiber/fiber.hpp>
 
 extern "C" {
 
 #include <windows.h>
-#include <winnt.h>
 
 }
 
@@ -23,11 +24,11 @@
 #include <boost/config/abi_prefix.hpp>
 
 namespace boost {
-namespace fiber {
+namespace fibers {
 
-LPVOID trampoline( LPVOID vp)
+VOID CALLBACK trampoline( LPVOID vp)
 {
- detail::fiberinfo_base * self(
+ detail::fiber_info_base * self(
                         static_cast< detail::fiber_info_base * >( vp) );
         BOOST_ASSERT( self);
         try
@@ -45,7 +46,7 @@
         if ( ! info_) throw fiber_moved();
 
         info_->uctx = ::CreateFiber(
- info_->attrs.stacksize(),
+ info_->attrs.stack_size(),
                 static_cast< LPFIBER_START_ROUTINE >( & trampoline),
                 static_cast< LPVOID >( info_.get() ) );
 }
@@ -55,30 +56,26 @@
 {
         if ( ! info_) throw fiber_moved();
 
- if ( ::SiwtchToFiber( & to.info_->uctx) != 0)
- throw system::system_error(
- system::error_code(
- ::GetLastError(),
- system::system_category) );
+ ::SwitchToFiber( to.info_->uctx);
 }
 
 void
 fiber::convert_thread_to_fiber()
 {
- if ( ! ::ConvertThreadToFiber( 0) )
+ if ( ::ConvertThreadToFiber( 0) == 0)
                 throw system::system_error(
                         system::error_code(
- ::GetLastError(),
+ GetLastError(),
                                 system::system_category) );
 }
 
 void
 fiber::convert_fiber_to_thread()
 {
- if ( ! ::ConvertFiberToThread( 0) )
+ if ( ::ConvertFiberToThread() == 0)
                 throw system::system_error(
                         system::error_code(
- ::GetLastError(),
+ GetLastError(),
                                 system::system_category) );
 }
 

Modified: sandbox/fiber/libs/fiber/src/scheduler.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/scheduler.cpp (original)
+++ sandbox/fiber/libs/fiber/src/scheduler.cpp 2009-11-15 15:18:39 EST (Sun, 15 Nov 2009)
@@ -15,128 +15,109 @@
 namespace boost {
 namespace fibers {
 
-scheduler::tss_impl_t scheduler::impl_;
+scheduler::impl_t scheduler::impl_;
 
 bool
 scheduler::runs_as_fiber()
-{ return impl_.get() != 0; }
+{ return impl_; }
 
 fiber::id
 scheduler::active_fiber()
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- return impl->active_fiber();
+ if ( ! impl_) throw fiber_error("not a fiber");
+ return impl_->active_fiber();
 }
 
 void
 scheduler::yield_active_fiber()
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->yield_active_fiber();
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->yield_active_fiber();
 }
 
 void
 scheduler::cancel_active_fiber()
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->cancel_active_fiber();
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->cancel_active_fiber();
 }
 
 void
 scheduler::suspend_active_fiber()
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->suspend_active_fiber();
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->suspend_active_fiber();
 }
 
 void
 scheduler::cancel_fiber( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->cancel_fiber( id);
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->cancel_fiber( id);
 }
 
 void
 scheduler::suspend_fiber( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->suspend_fiber( id);
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->suspend_fiber( id);
 }
 
 void
 scheduler::resume_fiber( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->resume_fiber( id);
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->resume_fiber( id);
 }
 
 int
 scheduler::priority( fiber::id const& id)
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- return impl->priority( id);
+ if ( ! impl_) throw fiber_error("not a fiber");
+ return impl_->priority( id);
 }
 
 void
 scheduler::priority( fiber::id const& id, int prio)
 {
- detail::scheduler_impl * impl( impl_.get() );
- if ( ! impl) throw fiber_error("not a fiber");
- impl->priority( id, prio);
+ if ( ! impl_) throw fiber_error("not a fiber");
+ impl_->priority( id, prio);
         re_schedule( id);
 }
 
 void
 scheduler::re_schedule( fiber::id const& id)
-{
- detail::scheduler_impl * impl( impl_.get() );
- impl->re_schedule( id);
-}
+{ impl_->re_schedule( id); }
 
 void
 scheduler::join( fiber::id const& id)
-{
- detail::scheduler_impl * impl( impl_.get() );
- impl->join( id);
-}
+{ impl_->join( id); }
 
-detail::scheduler_impl *
-scheduler::access_()
+scheduler::scheduler()
 {
- if ( ! impl_.get() )
- {
- fiber::convert_thread_to_fiber();
- impl_.reset( new detail::scheduler_impl() );
- }
- return impl_.get();
+ fiber::convert_thread_to_fiber();
+ impl_.reset(
+ new detail::scheduler_impl() );
 }
 
 scheduler::~scheduler()
-{ impl_.reset(); }
+{ fiber::convert_fiber_to_thread(); }
 
 bool
 scheduler::run()
-{ return access_()->run(); }
+{ return impl_->run(); }
 
 bool
 scheduler::empty()
-{ return access_()->empty(); }
+{ return impl_->empty(); }
 
 std::size_t
 scheduler::size()
-{ return access_()->size(); }
+{ return impl_->size(); }
 
 void
 scheduler::submit_fiber( fiber f)
-{ access_()->add_fiber( f); }
+{ impl_->add_fiber( f); }
 
 }}
 


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