|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57679 - in sandbox/fiber: boost/fiber/detail libs/fiber/src
From: oliver.kowalke_at_[hidden]
Date: 2009-11-15 04:23:27
Author: olli
Date: 2009-11-15 04:23:26 EST (Sun, 15 Nov 2009)
New Revision: 57679
URL: http://svn.boost.org/trac/boost/changeset/57679
Log:
- some modifications related to WIN32 fiber API
Text files modified:
sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp | 6 +---
sandbox/fiber/boost/fiber/detail/fiber_info_base_windows.hpp | 34 +++---------------------------
sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp | 2 +
sandbox/fiber/libs/fiber/src/fiber_info_base_windows.cpp | 31 ++++++++++++++-------------
sandbox/fiber/libs/fiber/src/fiber_posix.cpp | 4 +-
sandbox/fiber/libs/fiber/src/fiber_windows.cpp | 43 ++++++++++++++++++++++++++++++++-------
6 files changed, 61 insertions(+), 59 deletions(-)
Modified: sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp (original)
+++ sandbox/fiber/boost/fiber/detail/fiber_info_base_posix.hpp 2009-11-15 04:23:26 EST (Sun, 15 Nov 2009)
@@ -35,7 +35,7 @@
attributes attrs;
::ucontext_t uctx;
shared_array< char > uctx_stack;
- fiber_state_t state;
+ fiber_state_t state;
static void convert_thread_to_fiber() {}
@@ -54,9 +54,7 @@
{ if ( --p->use_count == 0) delete p; }
};
-}}
-
-}
+}}}
#include <boost/config/abi_suffix.hpp>
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 04:23:26 EST (Sun, 15 Nov 2009)
@@ -14,13 +14,12 @@
}
-#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_array.hpp>
#include <boost/fiber/attributes.hpp>
#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/detail/fiber_state.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -33,8 +32,9 @@
typedef intrusive_ptr< fiber_info_base > ptr_t;
uint32_t use_count;
- attributes attribs;
+ attributes attrs;
LPVOID uctx;
+ fiber_state_t state;
static void convert_thread_to_fiber() {}
@@ -46,40 +46,14 @@
virtual void run() = 0;
-#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
-
inline friend void intrusive_ptr_add_ref( fiber_info_base * p)
{ ++p->use_count; }
inline friend void intrusive_ptr_release( fiber_info_base * p)
{ if ( --p->use_count == 0) delete p; }
-
-#else
-
- void add_ref()
- { ++use_count; }
-
- void release()
- { if ( --use_count == 0) delete this; }
-
-#endif
};
-}}
-
-#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
-
-inline
-void intrusive_ptr_add_ref( fiber::detail::fiber_info_base * p)
-{ p->add_ref(); }
-
-inline
-void intrusive_ptr_release( fiber::detail::fiber_info_base * p)
-{ p->release(); }
-
-#endif
-
-}
+}}}
#include <boost/config/abi_suffix.hpp>
Modified: sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_info_base_posix.cpp 2009-11-15 04:23:26 EST (Sun, 15 Nov 2009)
@@ -18,6 +18,7 @@
namespace detail {
fiber_info_base::fiber_info_base() :
+ use_count( 0),
attrs(),
uctx(),
uctx_stack(),
@@ -25,6 +26,7 @@
{}
fiber_info_base::fiber_info_base( attributes const& attrs_) :
+ use_count( 0),
attrs( attrs_),
uctx(),
uctx_stack( new char[attrs.stack_size()]),
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 04:23:26 EST (Sun, 15 Nov 2009)
@@ -18,28 +18,29 @@
namespace detail {
fiber_info_base::fiber_info_base() :
- attribs(),
+ use_count( 0),
+ attrs(),
uctx(),
- uctx_stack()
-{}
-
-fiber_info_base::fiber_info_base( attributes const& attribs_) :
- attribs( attribs_),
- uctx(),
- uctx_stack( new char[attribs.stack_size()])
+ state( STATE_MASTER)
{
- BOOST_ASSERT( uctx_stack);
-
- if ( ::getcontext( & uctx) == -1)
+ uctx = ::GetCurrentFiber();
+ if ( ! uctx)
throw system::system_error(
system::error_code(
- errno,
+ ::GetLastError(),
system::system_category) );
- uctx.uc_stack.ss_sp = uctx_stack.get();
- uctx.uc_stack.ss_size = attribs.stack_size();
- uctx.uc_link = 0;
}
+fiber_info_base::~fiber_info_base()
+{ ::DeleteFiber( uctx); }
+
+fiber_info_base::fiber_info_base( attributes const& attrs_) :
+ use_count( 0),
+ attrs( attrs_),
+ uctx(),
+ state( STATE_NOT_STARTED)
+{}
+
}}}
#include <boost/config/abi_suffix.hpp>
Modified: sandbox/fiber/libs/fiber/src/fiber_posix.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber_posix.cpp (original)
+++ sandbox/fiber/libs/fiber/src/fiber_posix.cpp 2009-11-15 04:23:26 EST (Sun, 15 Nov 2009)
@@ -14,11 +14,11 @@
#include <cerrno>
+#include <boost/system/system_error.hpp>
+
#include <boost/fiber/exceptions.hpp>
#include <boost/fiber/utility.hpp>
-#include <boost/system/system_error.hpp>
-
#include <boost/config/abi_prefix.hpp>
namespace boost {
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 04:23:26 EST (Sun, 15 Nov 2009)
@@ -17,28 +17,55 @@
#include <boost/system/system_error.hpp>
+#include <boost/fiber/exceptions.hpp>
+#include <boost/fiber/utility.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost {
namespace fiber {
+VOID trampoline( LPVOID vp)
+{
+ detail::fiberinfo_base * self(
+ static_cast< detail::fiber_info_base * >( vp) );
+ BOOST_ASSERT( self);
+ try
+ { self->run(); }
+ catch ( fiber_interrupted const&)
+ {}
+ catch (...)
+ {}
+ this_fiber::cancel();
+}
+
void
fiber::init_()
{
- typedef void fn_type( fiber *);
- typedef void ( * st_fn)();
- fn_type * fn_ptr( trampoline);
+ if ( ! info_) throw fiber_moved();
info_->uctx = ::CreateFiber(
- info_->stack_size_,
- static_cast< LPFIBER_START_ROUTINE >( & trampoline< fiber >),
- static_cast< LPVOID >( this) );
+ info_->attrs.stacksize(),
+ static_cast< LPFIBER_START_ROUTINE >( & trampoline),
+ static_cast< LPVOID >( info_.get() ) );
+}
+
+void
+fiber::switch_to_( fiber & to)
+{
+ if ( ! info_) throw fiber_moved();
+
+ if ( ::SiwtchToFiber( & to.info_->uctx) != 0)
+ throw system::system_error(
+ system::error_code(
+ ::GetLastError(),
+ system::system_category) );
}
void
-fiber::switch_to( fiber & to)
+fiber::convert_thread_to_fiber()
{
- if ( ::SiwtchToFiber( & info_->uctx) != 0)
+ if ( ! ::ConvertThreadToFiber( 0) )
throw system::system_error(
system::error_code(
::GetLastError(),
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