|
- 32 µs
+ 16 µs
|
@@ -257,7 +248,56 @@
(from overhead_future.cpp)
- Table 1.5. Scaling of creating and joining
+ Table 1.5. Overhead of fiber creation (contains fiber-stack allocation and preparation,
+ fiber-context construction, scheduler handling)
+
+
+
+
+
+
+
+|
+
+ thread
+
+ |
+
+
+ fiber (atomics)
+
+ |
+
+
+ fiber (raw)
+
+ |
+
+
+|
+
+ 18 µs
+
+ |
+
+
+ 210 ns
+
+ |
+
+
+ 205 ns
+
+ |
+
+
+
+
+ (from overhead_create.cpp)
+
+
+ Table 1.6. Scaling of creating and joining
@@ -296,7 +336,7 @@
|
- 50.65 µs
+ 8.21 µs
|
@@ -318,7 +358,7 @@
|
- 52.99 µs
+ 6.67 µs
|
@@ -340,7 +380,7 @@
|
- 50.44 µs
+ 6.79 µs
|
@@ -362,7 +402,7 @@
|
- 45.19 µs
+ 8.25 µs
|
@@ -384,7 +424,7 @@
|
- 42.59 µs
+ 7.71 µs
|
@@ -406,7 +446,7 @@
|
- 42.30 µs
+ 5.67 µs
|
@@ -428,7 +468,7 @@
|
- 41.07 µs
+ 5.25 µs
|
diff --git a/doc/html/fiber/scheduling.html b/doc/html/fiber/scheduling.html
index e7cb2f98..41683692 100644
--- a/doc/html/fiber/scheduling.html
+++ b/doc/html/fiber/scheduling.html
@@ -267,10 +267,9 @@
A scheduler class directly derived from sched_algorithm can
- use any information available from context to implement
- the sched_algorithm interface.
- But a custom scheduler might need to track additional properties for a fiber.
- For instance, a priority-based scheduler would need to track a fiber's priority.
+ use any information available from context to implement the sched_algorithm interface. But a custom scheduler
+ might need to track additional properties for a fiber. For instance, a priority-based
+ scheduler would need to track a fiber's priority.
Boost.Fiber provides a mechanism by which
@@ -503,8 +502,8 @@
instance is already passed to sched_algorithm_with_properties::awakened() and
sched_algorithm_with_properties::property_change().
However, every sched_algorithm subclass is expected
- to track a collection of ready context instances.
- This method allows your custom scheduler to retrieve the fiber_properties subclass
+ to track a collection of ready context instances. This method
+ allows your custom scheduler to retrieve the fiber_properties subclass
instance for any context
in its collection.
@@ -580,12 +579,12 @@
- While you are free to treat context* as an opaque token, certain context members may be useful to a
- custom scheduler implementation.
+ While you are free to treat context* as an opaque token, certain context members may be useful to a custom
+ scheduler implementation.
- (Most context members
- are implementation details; most of interest are implementations of fiber methods.)
+ (Most context members are implementation
+ details; most of interest are implementations of fiber methods.)
#include <boost/fiber/context.hpp>
@@ -615,9 +614,9 @@
This link pointer may be used to help implement a custom scheduler's
ready queue. It is overwritten by the fiber manager every time this
- context is returned
- by sched_algorithm::pick_next(), but between
- the time the fiber manager passes this context
+ context is returned by
+ sched_algorithm::pick_next(), but between the
+ time the fiber manager passes this context
to sched_algorithm::awakened() (or sched_algorithm_with_properties::awakened())
and the time your pick_next() returns it to the fiber manager, it
is available for use by your custom scheduler.
@@ -629,8 +628,8 @@
diff --git a/doc/html/index.html b/doc/html/index.html
index a6782021..be5aef34 100644
--- a/doc/html/index.html
+++ b/doc/html/index.html
@@ -107,7 +107,7 @@
-Last revised: September 05, 2015 at 11:41:45 GMT |
+Last revised: September 07, 2015 at 15:34:24 GMT |
|
diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp
index 44efc5a2..9d74ac46 100644
--- a/include/boost/fiber/context.hpp
+++ b/include/boost/fiber/context.hpp
@@ -27,7 +27,7 @@
#include
#include
#include
-#include
+#include
#include
#ifdef BOOST_HAS_ABI_HEADERS
@@ -90,14 +90,14 @@ private:
fiber_status state_;
int flags_;
#endif
- detail::spinlock splk_;
- fiber_manager * mgr_;
- boost::context::execution_context ctx_;
- fss_data_t fss_data_;
- std::vector< context * > waiting_;
- std::exception_ptr except_;
- std::chrono::steady_clock::time_point tp_;
- fiber_properties * properties_;
+ detail::spinlock splk_;
+ scheduler * scheduler_;
+ boost::context::execution_context ctx_;
+ fss_data_t fss_data_;
+ std::vector< context * > waiting_;
+ std::exception_ptr except_;
+ std::chrono::steady_clock::time_point tp_;
+ fiber_properties * properties_;
protected:
virtual void deallocate() {
@@ -172,7 +172,7 @@ public:
state_( fiber_status::running),
flags_( flag_main_fiber),
splk_(),
- mgr_( nullptr),
+ scheduler_( nullptr),
ctx_( boost::context::execution_context::current() ),
fss_data_(),
waiting_(),
@@ -192,7 +192,7 @@ public:
state_( fiber_status::ready),
flags_( 0),
splk_(),
- mgr_( nullptr),
+ scheduler_( nullptr),
ctx_( palloc, salloc,
// lambda, executed in execution context
// mutable: generated operator() is not const -> enables std::move( fn)
@@ -229,13 +229,13 @@ public:
virtual ~context();
- void manager( fiber_manager * mgr) {
+ void set_scheduler( scheduler * mgr) {
BOOST_ASSERT( nullptr != mgr);
- mgr_ = mgr;
+ scheduler_ = mgr;
}
- fiber_manager * manager() const noexcept {
- return mgr_;
+ scheduler * get_scheduler() const noexcept {
+ return scheduler_;
}
id get_id() const noexcept {
@@ -371,13 +371,13 @@ public:
template< typename Clock, typename Duration >
bool do_wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time,
detail::spinlock_lock & lk) {
- return mgr_->wait_until( timeout_time, lk);
+ return scheduler_->wait_until( timeout_time, lk);
}
template< typename Rep, typename Period >
bool do_wait_for( std::chrono::duration< Rep, Period > const& timeout_duration,
detail::spinlock_lock & lk) {
- return mgr_->wait_for( timeout_duration, lk);
+ return scheduler_->wait_for( timeout_duration, lk);
}
void do_yield();
@@ -390,7 +390,7 @@ public:
template< typename Rep, typename Period >
void do_wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept {
- mgr_->wait_interval( wait_interval);
+ scheduler_->wait_interval( wait_interval);
}
std::chrono::steady_clock::duration do_wait_interval() noexcept;
diff --git a/include/boost/fiber/fiber_manager.hpp b/include/boost/fiber/scheduler.hpp
similarity index 92%
rename from include/boost/fiber/fiber_manager.hpp
rename to include/boost/fiber/scheduler.hpp
index efcbfabb..d92d7d68 100644
--- a/include/boost/fiber/fiber_manager.hpp
+++ b/include/boost/fiber/scheduler.hpp
@@ -30,7 +30,7 @@ namespace fibers {
class context;
struct sched_algorithm;
-struct BOOST_FIBERS_DECL fiber_manager {
+struct BOOST_FIBERS_DECL scheduler {
private:
typedef detail::waiting_queue wqueue_t;
typedef detail::terminated_queue tqueue_t;
@@ -46,12 +46,12 @@ private:
detail::spinlock_lock &);
public:
- fiber_manager() noexcept;
+ scheduler() noexcept;
- fiber_manager( fiber_manager const&) = delete;
- fiber_manager & operator=( fiber_manager const&) = delete;
+ scheduler( scheduler const&) = delete;
+ scheduler & operator=( scheduler const&) = delete;
- virtual ~fiber_manager() noexcept;
+ virtual ~scheduler() noexcept;
void spawn( context *);
diff --git a/src/context.cpp b/src/context.cpp
index a8c4a08b..59039d54 100644
--- a/src/context.cpp
+++ b/src/context.cpp
@@ -18,15 +18,15 @@
namespace boost {
namespace fibers {
-static context * main_fiber() {
- static thread_local context mf;
- static thread_local fiber_manager mgr;
- mf.manager( & mgr);
- return & mf;
+static context * main_context() {
+ static thread_local context mc;
+ static thread_local scheduler sched;
+ mc.set_scheduler( & sched);
+ return & mc;
}
thread_local context *
-context::active_ = main_fiber();
+context::active_ = main_context();
context *
context::active() noexcept {
@@ -148,69 +148,69 @@ context::set_properties( fiber_properties * props) {
void
context::do_spawn( fiber const& f_) {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
context * f( f_.impl_.get() );
- f->manager( mgr_);
- mgr_->spawn( f);
+ f->set_scheduler( scheduler_);
+ scheduler_->spawn( f);
}
void
context::do_schedule() {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
- mgr_->run();
+ scheduler_->run();
}
void
context::do_wait( detail::spinlock_lock & lk) {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
- mgr_->wait( lk);
+ scheduler_->wait( lk);
}
void
context::do_yield() {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
- mgr_->yield();
+ scheduler_->yield();
}
void
context::do_join( context * f) {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
BOOST_ASSERT( nullptr != f);
- mgr_->join( f);
+ scheduler_->join( f);
}
std::size_t
context::do_ready_fibers() const noexcept {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
- return mgr_->ready_fibers();
+ return scheduler_->ready_fibers();
}
void
context::do_set_sched_algo( std::unique_ptr< sched_algorithm > algo) {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
- mgr_->set_sched_algo( std::move( algo) );
+ scheduler_->set_sched_algo( std::move( algo) );
}
std::chrono::steady_clock::duration
context::do_wait_interval() noexcept {
- BOOST_ASSERT( nullptr != mgr_);
+ BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( this == active_);
- return mgr_->wait_interval();
+ return scheduler_->wait_interval();
}
}}
diff --git a/src/detail/spinlock.cpp b/src/detail/spinlock.cpp
index 92a6de8c..b7237e14 100644
--- a/src/detail/spinlock.cpp
+++ b/src/detail/spinlock.cpp
@@ -9,7 +9,7 @@
#include
#include "boost/fiber/context.hpp"
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
namespace boost {
namespace fibers {
diff --git a/src/interruption.cpp b/src/interruption.cpp
index fd6a42d4..20908b4f 100644
--- a/src/interruption.cpp
+++ b/src/interruption.cpp
@@ -9,7 +9,7 @@
#include "boost/fiber/interruption.hpp"
#include "boost/fiber/context.hpp"
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include "boost/fiber/exceptions.hpp"
#ifdef BOOST_HAS_ABI_HEADERS
diff --git a/src/mutex.cpp b/src/mutex.cpp
index 43b3c389..fd8a5877 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -10,7 +10,7 @@
#include
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include "boost/fiber/interruption.hpp"
#include "boost/fiber/operations.hpp"
diff --git a/src/properties.cpp b/src/properties.cpp
index 4324b880..30e500b2 100644
--- a/src/properties.cpp
+++ b/src/properties.cpp
@@ -8,7 +8,7 @@
#include
#include "boost/fiber/algorithm.hpp"
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include "boost/fiber/context.hpp"
#ifdef BOOST_HAS_ABI_HEADERS
diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp
index d77efe4b..0e5bc13e 100644
--- a/src/recursive_mutex.cpp
+++ b/src/recursive_mutex.cpp
@@ -10,7 +10,7 @@
#include
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include "boost/fiber/interruption.hpp"
#include "boost/fiber/operations.hpp"
diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp
index 7fcfaacd..82a3b724 100644
--- a/src/recursive_timed_mutex.cpp
+++ b/src/recursive_timed_mutex.cpp
@@ -10,7 +10,7 @@
#include
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include "boost/fiber/interruption.hpp"
#include "boost/fiber/operations.hpp"
diff --git a/src/fiber_manager.cpp b/src/scheduler.cpp
similarity index 86%
rename from src/fiber_manager.cpp
rename to src/scheduler.cpp
index 4a3967e7..7414bce0 100644
--- a/src/fiber_manager.cpp
+++ b/src/scheduler.cpp
@@ -4,7 +4,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include
#include // std::this_thread::sleep_until()
@@ -25,14 +25,14 @@
namespace boost {
namespace fibers {
-fiber_manager::fiber_manager() noexcept :
+scheduler::scheduler() noexcept :
sched_algo_( new round_robin() ),
wqueue_(),
tqueue_(),
wait_interval_( std::chrono::milliseconds( 10) ) {
}
-fiber_manager::~fiber_manager() noexcept {
+scheduler::~scheduler() noexcept {
// FIXME: test for main-fiber
for (;;) {
// NOTE: at this stage the fibers in the waiting-queue
@@ -46,8 +46,8 @@ fiber_manager::~fiber_manager() noexcept {
context * f( sched_algo_->pick_next() );
if ( f) {
BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue");
- // set fiber_manager
- f->manager( this);
+ // set scheduler
+ f->set_scheduler( this);
// add active-fiber to joinig-list of f
// fiber::join() should not fail because fiber f is in state_ready
// so main-fiber should be in the waiting-queue of fiber f
@@ -68,7 +68,7 @@ fiber_manager::~fiber_manager() noexcept {
}
void
-fiber_manager::resume_( context * f) {
+scheduler::resume_( context * f) {
BOOST_ASSERT( nullptr != f);
BOOST_ASSERT( f->is_ready() );
// set fiber to state running
@@ -78,10 +78,10 @@ fiber_manager::resume_( context * f) {
if ( f == context::active() ) {
return;
}
- // pass new fiber the fiber_manager of the current active fiber
+ // pass new fiber the scheduler of the current active fiber
// this might be necessary if the new fiber was miggrated from
// another thread
- f->manager( context::active()->manager() );
+ f->set_scheduler( context::active()->get_scheduler() );
// assign new fiber to active-fiber
context * old( context::active( f) );
// push terminated fibers to terminated-queue
@@ -93,7 +93,7 @@ fiber_manager::resume_( context * f) {
}
void
-fiber_manager::spawn( context * f) {
+scheduler::spawn( context * f) {
BOOST_ASSERT( nullptr != f);
BOOST_ASSERT( f->is_ready() );
BOOST_ASSERT( f != context::active() );
@@ -102,7 +102,7 @@ fiber_manager::spawn( context * f) {
}
void
-fiber_manager::run() {
+scheduler::run() {
for (;;) {
// destroy terminated fibers from terminated-queue
tqueue_.clear();
@@ -113,8 +113,6 @@ fiber_manager::run() {
context * f( sched_algo_->pick_next() );
if ( f) {
BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue");
- // set fiber_manager
- f->manager( this);
// resume fiber f
resume_( f);
return;
@@ -127,7 +125,7 @@ fiber_manager::run() {
}
void
-fiber_manager::wait( detail::spinlock_lock & lk) {
+scheduler::wait( detail::spinlock_lock & lk) {
wait_until(
std::chrono::steady_clock::time_point(
(std::chrono::steady_clock::duration::max)() ),
@@ -135,7 +133,7 @@ fiber_manager::wait( detail::spinlock_lock & lk) {
}
bool
-fiber_manager::wait_until_( std::chrono::steady_clock::time_point const& timeout_time,
+scheduler::wait_until_( std::chrono::steady_clock::time_point const& timeout_time,
detail::spinlock_lock & lk) {
BOOST_ASSERT( context::active()->is_running() );
// set active-fiber to state_waiting
@@ -155,7 +153,7 @@ fiber_manager::wait_until_( std::chrono::steady_clock::time_point const& timeout
}
void
-fiber_manager::yield() {
+scheduler::yield() {
BOOST_ASSERT( context::active()->is_running() );
// set active-fiber to state_waiting
context::active()->set_ready();
@@ -169,7 +167,7 @@ fiber_manager::yield() {
}
void
-fiber_manager::join( context * f) {
+scheduler::join( context * f) {
BOOST_ASSERT( nullptr != f);
BOOST_ASSERT( f != context::active() );
// set active-fiber to state_waiting
@@ -193,22 +191,22 @@ fiber_manager::join( context * f) {
}
void
-fiber_manager::set_sched_algo( std::unique_ptr< sched_algorithm > algo) {
+scheduler::set_sched_algo( std::unique_ptr< sched_algorithm > algo) {
sched_algo_ = std::move( algo);
}
void
-fiber_manager::wait_interval( std::chrono::steady_clock::duration const& wait_interval) noexcept {
+scheduler::wait_interval( std::chrono::steady_clock::duration const& wait_interval) noexcept {
wait_interval_ = wait_interval;
}
std::chrono::steady_clock::duration
-fiber_manager::wait_interval() noexcept {
+scheduler::wait_interval() noexcept {
return wait_interval_;
}
std::size_t
-fiber_manager::ready_fibers() const noexcept {
+scheduler::ready_fibers() const noexcept {
return sched_algo_->ready_fibers();
}
diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp
index 2393ed6a..835cbd82 100644
--- a/src/timed_mutex.cpp
+++ b/src/timed_mutex.cpp
@@ -10,7 +10,7 @@
#include
-#include "boost/fiber/fiber_manager.hpp"
+#include "boost/fiber/scheduler.hpp"
#include "boost/fiber/interruption.hpp"
#include "boost/fiber/operations.hpp"
| |