|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58528 - in sandbox/fiber: . libs/fiber/doc libs/fiber/src/spin
From: oliver.kowalke_at_[hidden]
Date: 2009-12-25 14:35:03
Author: olli
Date: 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
New Revision: 58528
URL: http://svn.boost.org/trac/boost/changeset/58528
Log:
- spinning sync. primitives check if running inside a fiber (if not -> this_thread::yield() )
- documentation updated
Text files modified:
sandbox/fiber/change.log | 4 +
sandbox/fiber/libs/fiber/doc/fiber_ref.qbk | 109 ++++++++++-----------------------------
sandbox/fiber/libs/fiber/doc/spin_barrier.qbk | 3
sandbox/fiber/libs/fiber/doc/spin_condition_variables.qbk | 3
sandbox/fiber/libs/fiber/doc/spin_event_variables.qbk | 2
sandbox/fiber/libs/fiber/doc/spin_fifos.qbk | 2
sandbox/fiber/libs/fiber/doc/spin_mutexes.qbk | 2
sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp | 7 ++
sandbox/fiber/libs/fiber/src/spin/condition.cpp | 7 ++
sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp | 9 ++
sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp | 8 ++
sandbox/fiber/libs/fiber/src/spin/mutex.cpp | 6 +
12 files changed, 72 insertions(+), 90 deletions(-)
Modified: sandbox/fiber/change.log
==============================================================================
--- sandbox/fiber/change.log (original)
+++ sandbox/fiber/change.log 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -1,3 +1,7 @@
+0.3.4:
+------
+- spinning sync. primitives check if invoked in a fiber
+
0.3.3:
------
- default_stacksize is public static member of fiber
Modified: sandbox/fiber/libs/fiber/doc/fiber_ref.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/fiber_ref.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/fiber_ref.qbk 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -16,8 +16,8 @@
void f()
{
- boost::fiber f1( boost::fibers::make_fiber( some_fn) );
- boost::fiber f2( boost::fibers::make_fiber( another_fn) );
+ boost::fiber f1( boost::fibers::make_fiber( some_fn, boost::fiber::default_stacksize) );
+ boost::fiber f2( boost::fibers::make_fiber( another_fn, boost::fiber::default_stacksize) );
boost::fibers::scheduler<> s;
s.submit( f1); // f1 gets copied
@@ -48,7 +48,7 @@
boost::fiber oops()
{
callable x;
- return boost::fiber( boost::ref( x) );
+ return boost::fiber( boost::ref( x), boost::fiber::default_stacksize);
} // x is destroyed, but the newly-created fiber still has a reference
// this leads to undefined behaviour
@@ -57,19 +57,19 @@
void find_the_question( int the_answer);
- boost::fiber deep_thought_2( find_the_question, 42);
+ boost::fiber deep_thought_2( find_the_question, 42, boost::fiber::default_stacksize);
The arguments are ['copied] into the internal fiber structure: if a reference is required, use `boost::ref`, just as
for references to callable functions.
For convinience `boost::fibers::make_fiber()` is provided:
- boost::fiber f( boost::fibers::make_fiber( new_fn, arg1, arg2, arg3) );
+ boost::fiber f( boost::fibers::make_fiber( new_fn, arg1, arg2, arg3, boost::fiber::default_stacksize) );
Another alternative is to use `scheduler<>::make_fiber()` which creates and stores the new fiber inside the scheduler.
boost::fibers::scheduler<> sched;
- sched.make_fiber( new_fn, arg1, arg2, arg3);
+ sched.make_fiber( new_fn, arg1, arg2, arg3, boost::fiber_default_stacksize);
[caution If you encounter segmentation faults or bus errors it may be possible that the stacksize for the fibers is
too small.]
@@ -96,9 +96,9 @@
{ f.join(); }
boost:.fibers::scheduler<> sched;
- boost::fiber f( some_fn);
+ boost::fiber f( some_fn, boost::fiber_default_stacksize);
sched.submit_fiber( f);
- sched.make_fiber( joining_fiber, f);
+ sched.make_fiber( joining_fiber, f, boost::fiber_default_stacksize);
for (;;)
{
while ( sched.run() );
@@ -191,25 +191,17 @@
~fiber();
template< typename Fn >
- explicit fiber( Fn fn);
+ explicit fiber( Fn fn, std::size_t stack_size);
- template< typename Fn >
- explicit fiber( std::size_t stack_size, Fn fn);
-
- template< typename Fn, typename A1, typename A2,...>
- fiber( Fn fn, A1 a1, A2 a2,...);
-
- template< typename Fn, typename A1, typename A2,...>
- fiber( std::size_t stack_size, Fn fn, A1 a1, A2 a2,...);
+ template< typename Fn, typename A1, typename A2,..., typename A10 >
+ fiber( Fn fn, A1 a1, A2 a2,..., A10 a10, std::size_t stack_size);
template< typename Fn >
- fiber( detail::fiber_move_t< Fn > f);
+ explicit fiber( Fn && fn, std::size_t stack_size);
// move support
- fiber( detail::fiber_move_t< fiber > x);
- fiber & operator=( detail::fiber_move_t< fiber > x);
- operator detail::fiber_move_t< fiber >();
- detail::fiber_move_t< fiber > move();
+ fiber( fiber && x);
+ fiber & operator=( fiber && x);
operator unspecified-bool-type() const;
@@ -239,16 +231,10 @@
void swap( fiber & lhs, fiber & rhs);
template< typename Fn >
- fiber make_fiber( Fn fn);
-
- template< typename Fn >
- fiber make_fiber( std::size_t stack_size, Fn fn);
+ fiber make_fiber( Fn fn, std::size_t stack_size);
- template< typename Fn, typename A1, typename A2,... >
- fiber make_fiber( Fn fn, A1 a1, A2 a2,...);
-
- template< typename Fn, typename A1, typename A2,... >
- fiber make_fiber( std::size_t stack_size, Fn fn, A1 a1, A2 a2,...);
+ template< typename Fn, typename A1, typename A2,..., typename A10 >
+ fiber make_fiber( Fn fn, A1 a1, A2 a2,..., A10 a10, std::size_t stack_size);
[section:default_constructor `fiber()`]
@@ -258,7 +244,7 @@
]
[endsect]
-[section:callable_constructor `template< typename Callable > fiber( Callable fn)`]
+[section:callable_constructor_stack `template< typename Fn > fiber( Fn fn, std::size_t stack_size)`]
[variablelist
[[Preconditions:] [`Callable` must by copyable.]]
[[Effects:] [`fn` is copied into storage managed internally by the fiber library, and that copy is invoked on a
@@ -268,29 +254,7 @@
]
[endsect]
-[section:callable_constructor_stack `template< typename Callable > fiber( std::size_t stack_size, Callable fn)`]
-[variablelist
-[[Preconditions:] [`Callable` must by copyable.]]
-[[Effects:] [`fn` is copied into storage managed internally by the fiber library, and that copy is invoked on a
-newly-created fiber. Second version sets the stack-size of the fiber.]]
-[[Postconditions:] [`*this` refers to the newly created fiber.]]
-[[Throws:] [__system_error__ if system call failed.]]
-]
-[endsect]
-
-[section:multiple_argument_constructor `template< typename Fn, typename A1, typename A2,...> fiber( Fn fn, A1 a1, A2 a2,...)`]
-[variablelist
-[[Preconditions:] [`Fn` and each `A`n must by copyable or movable.]]
-[[Effects:] [As if `fiber( boost::bind( fn, a1, a2,...) )`. Consequently, `fn` and each `a`n
-are copied into internal storage for access by the new fiber.
-Second version additionaly sets the stack-size used by the fiber.]]
-[[Postconditions:] [`*this` refers to the newly created fiber.]]
-[[Throws:] [__system_error__ if system call failed.]]
-[[Note:] [Currently up to nine additional arguments `a1` to `a9` can be specified in addition to the function `fn`.]]
-]
-[endsect]
-
-[section:multiple_argument_constructor_stack `template< typename Fn, typename A1, typename A2,...> fiber( std::size_t stack_size, Fn fn, A1 a1, A2 a2,...)`]
+[section:multiple_argument_constructor `template< typename Fn, typename A1, typename A2,..., typename A10 > fiber( Fn fn, A1 a1, A2 a2,..., A10 a10, std::size_t stack_size)`]
[variablelist
[[Preconditions:] [`Fn` and each `A`n must by copyable or movable.]]
[[Effects:] [As if `fiber( boost::bind( fn, a1, a2,...) )`. Consequently, `fn` and each `a`n
@@ -315,6 +279,7 @@
a default-constructed __fiber_id__.]]
[[Throws:] [Nothing.]]
]
+
[endsect]
[section:join `void join()`]
@@ -414,16 +379,10 @@
#include <boost/fiber/fiber.hpp>
template< typename Fn >
- fiber make_fiber( Fn fn);
-
- template< typename Fn >
- fiber make_fiber( std::size_t stack_size, Fn fn);
-
- template< typename Fn, typename A1, typename A2,... >
- fiber make_fiber( Fn fn, A1 a1, A2 a2,...);
+ fiber make_fiber( Fn fn, std::size_t stack_size);
- template< typename Fn, typename A1, typename A2,... >
- fiber make_fiber( std::size_t stack_size, Fn fn, A1 a1, A2 a2,...);
+ template< typename Fn, typename A1, typename A2,..., typename A10 >
+ fiber make_fiber( Fn fn, A1 a1, A2 a2,..., A10 a10, std::size_t stack_size);
[variablelist
[[Effects:] [Creates a fiber.]]
@@ -762,16 +721,13 @@
void submit_fiber( fiber);
template< typename Fn >
- void make_fiber( Fn fn);
+ void make_fiber( Fn fn, std::size_t stack_size);
template< typename Fn >
- void make_fiber( std::size_t stack_size, Fn fn);
-
- template< typename Fn, typename A1, typename A2,... >
- void make_fiber( Fn fn, A0 a0, A1 a1,...);
+ void make_fiber( Fn && fn, std::size_t stack_size);
- template< typename Fn, typename A1, typename A2,... >
- void make_fiber( std::size_t stack_size, Fn fn, A1 a1, A2 a2,...);
+ template< typename Fn, typename A1, typename A2,..., typename A10 >
+ void make_fiber( Fn fn, A0 a0, A1 a1,..., A10 a10, std:size_t stack_size);
void migrate_fiber( fiber f);
@@ -832,21 +788,14 @@
]
[endsect]
-[section:make_fiber1 `template< typename Fn > void make_fiber( Fn fn)`]
-[variablelist
-[[Effects:] [The functions create a fiber which gets stored in the internal structures from scheduler.]]
-[[Throws:] [Nothing.]]
-]
-[endsect]
-
-[section:make_fiber2 `template< typename Fn > void make_fiber( std::size_t stack_size, Fn fn)`]
+[section:make_fiber2 `template< typename Fn > void make_fiber( Fn fn, std::size_t stack_size)`]
[variablelist
[[Effects:] [The functions create a fiber which gets stored in the internal structures from scheduler.]]
[[Throws:] [Nothing.]]
]
[endsect]
-[section:make_fiber3 `template< typename Fn, typename A1, typename A2,... > void make_fiber( Fn fn, A0 a0, A1 a1,...)`]
+[section:make_fiber3 `template< typename Fn, typename A1, typename A2,..., typename A10 > void make_fiber( Fn fn, A0 a0, A1 a1,..., A10 a10, std::size_t stack_size)`]
[variablelist
[[Effects:] [The functions create a fiber which gets stored in the internal structures from scheduler.]]
[[Throws:] [Nothing.]]
Modified: sandbox/fiber/libs/fiber/doc/spin_barrier.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/spin_barrier.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/spin_barrier.qbk 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -12,7 +12,8 @@
fibers reach the barrier they must wait until all `n` fibers have arrived. Once the `n`-th fiber has reached the
barrier, all the waiting fibers can proceed, and the barrier is reset.
-[note __spin_barrier__ is ['not] bound to a __scheduler__ and can be used by fibers managed by different schedulers.]
+[note __spin_barrier__ is ['not] bound to a __scheduler__ and can be used by fibers managed by different schedulers
+or code not running in a fiber.]
[section:barrier Class `barrier`]
Modified: sandbox/fiber/libs/fiber/doc/spin_condition_variables.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/spin_condition_variables.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/spin_condition_variables.qbk 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -55,7 +55,8 @@
Note that the same mutex is locked before the shared data is updated, but that the mutex does not have to be locked
across the call to `notify_one`.
-[note __spin_condition__ is ['not] bound to a __scheduler__ and can be used by fibers managed by different schedulers.]
+[note __spin_condition__ is ['not] bound to a __scheduler__ and can be used by fibers managed by different schedulers
+or code not running in a fiber.]
[section:condition Class `condition`]
Modified: sandbox/fiber/libs/fiber/doc/spin_event_variables.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/spin_event_variables.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/spin_event_variables.qbk 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -13,7 +13,7 @@
A event-variable has two states `set` (`signaled`) or `reset` (`nonsignaled`).
[note event-variables are ['not] bound to a __scheduler__ and can be used by fibers
-managed by different schedulers.]
+managed by different schedulers or code not running in a fiber.]
boost::fibers::spin::auto_reset_event ev;
Modified: sandbox/fiber/libs/fiber/doc/spin_fifos.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/spin_fifos.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/spin_fifos.qbk 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -10,7 +10,7 @@
__boost_fiber__ provides a bounded and a unbounded fifo suitable to synchonize fibers via message passing.
[note fifos are ['not] bound to a __scheduler__ and can only be used by fibers
-managed by different schedulers.]
+managed by different schedulers or code not running in a fiber.]
typedef boost::fibers::spin::unbounded_fifo< int > fifo_t;
Modified: sandbox/fiber/libs/fiber/doc/spin_mutexes.qbk
==============================================================================
--- sandbox/fiber/libs/fiber/doc/spin_mutexes.qbk (original)
+++ sandbox/fiber/libs/fiber/doc/spin_mutexes.qbk 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -29,7 +29,7 @@
__unlock__ shall be permitted.
[note __spin_mutex__ is ['not] bound to a __scheduler__ and can only be used by fibers
-managed by different schedulers.]
+managed by different schedulers or code not running in a fiber.]
[endsect]
Modified: sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/auto_reset_event.cpp 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -6,6 +6,8 @@
#include "boost/fiber/spin/auto_reset_event.hpp"
+#include <boost/thread/thread.hpp>
+
#include <boost/fiber/utility.hpp>
namespace boost {
@@ -26,7 +28,10 @@
state expected = SET;
while ( ! state_.compare_exchange_strong( expected, RESET) )
{
- this_fiber::yield();
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
+ else
+ this_thread::yield();
expected = SET;
}
}
Modified: sandbox/fiber/libs/fiber/src/spin/condition.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/condition.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/condition.cpp 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -6,6 +6,8 @@
#include "boost/fiber/spin/condition.hpp"
+#include <boost/thread/thread.hpp>
+
namespace boost {
namespace fibers {
namespace spin {
@@ -24,7 +26,10 @@
command expected = SLEEPING;
while ( ! cmd_.compare_exchange_strong( expected, cmd) )
{
- this_fiber::yield();
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
+ else
+ this_thread::yield();
expected = SLEEPING;
}
}
Modified: sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/count_down_event.cpp 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -6,6 +6,8 @@
#include "boost/fiber/spin/count_down_event.hpp"
+#include <boost/thread/thread.hpp>
+
#include <boost/fiber/spin/mutex.hpp>
#include <boost/fiber/utility.hpp>
@@ -47,7 +49,12 @@
count_down_event::wait()
{
while ( 0 != current_.load() )
- this_fiber::yield();
+ {
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
+ else
+ this_thread::yield();
+ }
}
}}}
Modified: sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/manual_reset_event.cpp 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -7,6 +7,7 @@
#include "boost/fiber/spin/manual_reset_event.hpp"
#include <boost/assert.hpp>
+#include <boost/thread/thread.hpp>
#include <boost/fiber/utility.hpp>
@@ -50,7 +51,12 @@
}
while ( RESET == state_.load() )
- this_fiber::yield();
+ {
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
+ else
+ this_thread::yield();
+ }
if ( 1 == waiters_.fetch_sub( 1) )
enter_mtx_.unlock();
Modified: sandbox/fiber/libs/fiber/src/spin/mutex.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/spin/mutex.cpp (original)
+++ sandbox/fiber/libs/fiber/src/spin/mutex.cpp 2009-12-25 14:35:02 EST (Fri, 25 Dec 2009)
@@ -6,6 +6,8 @@
#include <boost/fiber/spin/mutex.hpp>
+#include <boost/thread/thread.hpp>
+
#include <boost/fiber/utility.hpp>
namespace boost {
@@ -24,8 +26,10 @@
state expected = UNLOCKED;
if ( state_.compare_exchange_strong( expected, LOCKED) )
break;
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
else
- this_fiber::yield();
+ this_thread::yield();
}
}
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