From 6499bb07e7e95a77b1c6e653bb4479a1d88df849 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Mon, 7 Sep 2015 17:23:59 +0200 Subject: [PATCH] fiber_context renamed to context --- build/Jamfile.v2 | 2 +- doc/customization.qbk | 4 +- doc/fibers.xml | 122 +++++++++--------- doc/html/fiber/custom.html | 30 ++--- doc/html/fiber/scheduling.html | 90 ++++++------- doc/scheduling.qbk | 80 ++++++------ examples/priority.cpp | 28 ++-- examples/simple.cpp | 8 +- examples/work_sharing.cpp | 8 +- include/boost/fiber/algorithm.hpp | 26 ++-- include/boost/fiber/condition.hpp | 20 +-- .../fiber/{fiber_context.hpp => context.hpp} | 44 +++---- include/boost/fiber/detail/fifo.hpp | 12 +- .../boost/fiber/detail/terminated_queue.hpp | 10 +- include/boost/fiber/detail/waiting_queue.hpp | 10 +- include/boost/fiber/fiber.hpp | 31 ++--- include/boost/fiber/fiber_manager.hpp | 8 +- include/boost/fiber/fss.hpp | 12 +- include/boost/fiber/mutex.hpp | 6 +- include/boost/fiber/operations.hpp | 24 ++-- include/boost/fiber/properties.hpp | 10 +- include/boost/fiber/recursive_mutex.hpp | 6 +- include/boost/fiber/recursive_timed_mutex.hpp | 6 +- include/boost/fiber/round_robin.hpp | 6 +- include/boost/fiber/timed_mutex.hpp | 6 +- src/algorithm.cpp | 6 +- src/condition.cpp | 8 +- src/{fiber_context.cpp => context.cpp} | 58 ++++----- src/detail/fifo.cpp | 8 +- src/detail/spinlock.cpp | 4 +- src/detail/terminated_queue.cpp | 8 +- src/detail/waiting_queue.cpp | 18 +-- src/fiber.cpp | 6 +- src/fiber_manager.cpp | 52 ++++---- src/interruption.cpp | 18 +-- src/mutex.cpp | 8 +- src/properties.cpp | 2 +- src/recursive_mutex.cpp | 8 +- src/recursive_timed_mutex.cpp | 14 +- src/round_robin.cpp | 8 +- src/timed_mutex.cpp | 14 +- 41 files changed, 425 insertions(+), 424 deletions(-) rename include/boost/fiber/{fiber_context.hpp => context.hpp} (91%) rename src/{fiber_context.cpp => context.cpp} (75%) diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 8145bc95..b03b1335 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -30,12 +30,12 @@ lib boost_fiber : algorithm.cpp barrier.cpp condition.cpp + context.cpp detail/fifo.cpp detail/spinlock.cpp detail/terminated_queue.cpp detail/waiting_queue.cpp fiber.cpp - fiber_context.cpp fiber_manager.cpp future.cpp interruption.cpp diff --git a/doc/customization.qbk b/doc/customization.qbk index b8b52b4e..e0cdead3 100644 --- a/doc/customization.qbk +++ b/doc/customization.qbk @@ -72,9 +72,9 @@ Now we can derive a custom scheduler from [template_link sched_algorithm_with_properties], specifying our custom property class `priority_props` as the template parameter. -Your custom scheduler can track ready [^[class_link fiber_context]*]s using +Your custom scheduler can track ready [^[class_link context]*]s using whatever container tactic you prefer. In this example, we use -[data_member_link fiber_context..nxt] to hand-implement an intrusive +[data_member_link context..nxt] to hand-implement an intrusive singly-linked list. [priority_scheduler] diff --git a/doc/fibers.xml b/doc/fibers.xml index 1249a021..59a02bb6 100644 --- a/doc/fibers.xml +++ b/doc/fibers.xml @@ -2478,9 +2478,9 @@ by calling the fiber::get_id() struct sched_algorithm { virtual ~sched_algorithm() {} - virtual void awakened( fiber_context *) = 0; + virtual void awakened( context *) = 0; - virtual fiber_context * pick_next() = 0; + virtual context * pick_next() = 0; virtual std::size_t ready_fibers() const noexcept = 0; }; @@ -2492,7 +2492,7 @@ by calling the fiber::get_id() function awakened() -virtual void awakened( fiber_context * f) = 0; +virtual void awakened( context * f) = 0; @@ -2533,7 +2533,7 @@ by calling the fiber::get_id() function pick_next() -virtual fiber_context * pick_next() = 0; +virtual context * pick_next() = 0; @@ -2598,9 +2598,9 @@ by calling the fiber::get_id() #include <boost/fiber/round_robin.hpp> class round_robin : public sched_algorithm { - virtual void awakened( fiber_context *); + virtual void awakened( context *); - virtual fiber_context * pick_next(); + virtual context * pick_next(); virtual std::size_t ready_fibers() const noexcept; }; @@ -2612,7 +2612,7 @@ by calling the fiber::get_id() function awakened() -virtual void awakened( fiber_context * f); +virtual void awakened( context * f); @@ -2633,7 +2633,7 @@ by calling the fiber::get_id() function pick_next() -virtual fiber_context * pick_next(); +virtual context * pick_next(); @@ -2681,7 +2681,7 @@ by calling the fiber::get_id() A scheduler class directly derived from sched_algorithm can - use any information available from fiber_context to implement + 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. @@ -2704,7 +2704,7 @@ by calling the fiber::get_id() class fiber_properties { public: - fiber_properties( fiber_context* f); + fiber_properties( context* f); virtual ~fiber_properties() {} @@ -2715,7 +2715,7 @@ by calling the fiber::get_id() Constructor -fiber_properties( fiber_context* f); +fiber_properties( context* f); @@ -2731,7 +2731,7 @@ by calling the fiber::get_id() Note: - Your subclass constructor must accept a fiber_contextcontext* and pass it to the base-class fiber_properties constructor. @@ -2804,22 +2804,22 @@ by calling the fiber::get_id() template< typename PROPS > struct sched_algorithm_with_properties { // override this method instead of sched_algorithm::awakened() - virtual void awakened( fiber_context * f, PROPS & properties) = 0; + virtual void awakened( context * f, PROPS & properties) = 0; - virtual fiber_context * pick_next(); + virtual context * pick_next(); virtual std::size_t ready_fibers() const noexcept; // obtain f's associated PROPS instance - PROPS & properties( fiber_context * f); + PROPS & properties( context * f); // override this to be notified by PROPS::notify() - virtual void property_change( fiber_context * f, PROPS & properties); + virtual void property_change( context * f, PROPS & properties); // Override this to customize instantiation of PROPS, e.g. use a different // allocator. Each PROPS instance is associated with a particular - // fiber_context. - virtual fiber_properties * new_properties( fiber_context * f); + // context. + virtual fiber_properties * new_properties( context * f); }; @@ -2829,7 +2829,7 @@ by calling the fiber::get_id() function awakened() -virtual void awakened( fiber_context * f, PROPS & properties); +virtual void awakened( context * f, PROPS & properties); @@ -2864,7 +2864,7 @@ by calling the fiber::get_id() function pick_next() -virtual fiber_context * pick_next(); +virtual context * pick_next(); @@ -2921,7 +2921,7 @@ by calling the fiber::get_id() function properties() -PROPS& properties( fiber_context * f); +PROPS& properties( context * f); @@ -2942,9 +2942,9 @@ by calling the fiber::get_id() 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 fiber_context instances. + to track a collection of ready context instances. This method allows your custom scheduler to retrieve the fiber_properties subclass - instance for any fiber_context + instance for any context in its collection. @@ -2957,7 +2957,7 @@ by calling the fiber::get_id() function property_change() -virtual void property_change( fiber_context * f, PROPS & properties); +virtual void property_change( context * f, PROPS & properties); @@ -2989,7 +2989,7 @@ by calling the fiber::get_id() function new_properties() -virtual fiber_properties * new_properties( fiber_context * f); +virtual fiber_properties * new_properties( context * f); @@ -3021,38 +3021,38 @@ by calling the fiber::get_id() - - - Class fiber_context + + + Class context - While you are free to treat fiber_contextcontext* as an opaque token, certain fiber_context members may be useful to a + role="identifier">context members may be useful to a custom scheduler implementation. - (Most fiber_context members + (Most context members are implementation details; most of interest are implementations of fiber methods.) -#include <boost/fiber/fiber_context.hpp> +#include <boost/fiber/context.hpp> -class fiber_context { +class context { public: - fiber_context * nxt; + context * nxt; - static fiber_context * main_fiber(); + static context * main_fiber(); }; - - - Data member nxt + + + Data member nxt -fiber_context * nxt; +context * nxt; @@ -3062,9 +3062,9 @@ by calling the fiber::get_id() 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 - fiber_context is returned + context is returned by sched_algorithm::pick_next(), but between - the time the fiber manager passes this fiber_context + 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 @@ -3074,13 +3074,13 @@ by calling the fiber::get_id() - - - Static + + + Static member function main_fiber() -static fiber_context * main_fiber(); +static context * main_fiber(); @@ -3088,7 +3088,7 @@ by calling the fiber::get_id() Returns: - the fiber_context associated + the context associated with the "main" fiber of the thread: the one implicitly created by the thread itself, rather than one explicitly created by Boost.Fiber. @@ -11052,7 +11052,7 @@ to return that result class priority_props : public boost::fibers::fiber_properties { public: - priority_props( boost::fibers::fiber_context * p): + priority_props( boost::fibers::context * p): fiber_properties( p), priority_( 0) { } @@ -11086,7 +11086,7 @@ to return that result - Your subclass constructor must accept a fiber_context* + Your subclass constructor must accept a context* and pass it to the fiber_properties constructor. @@ -11119,8 +11119,8 @@ to return that result as the template parameter. - Your custom scheduler can track ready fiber_context*s - using whatever container tactic you prefer. In this example, we use fiber_context::nxt to + Your custom scheduler can track ready context*s + using whatever container tactic you prefer. In this example, we use context::nxt to hand-implement an intrusive singly-linked list. @@ -11129,7 +11129,7 @@ to return that result // Much as we would like, we don't use std::priority_queue because it // doesn't appear to provide any way to alter the priority (and hence // queue position) of a particular item. - boost::fibers::fiber_context * head_; + boost::fibers::context * head_; public: priority_scheduler() : @@ -11138,15 +11138,15 @@ to return that result // For a subclass of sched_algorithm_with_properties<>, it's important to // override the correct awakened() overload. - virtual void awakened( boost::fibers::fiber_context * f, priority_props & props) { + virtual void awakened( boost::fibers::context * f, priority_props & props) { int f_priority = props.get_priority(); // With this scheduler, fibers with higher priority values are // preferred over fibers with lower priority values. But fibers with // equal priority values are processed in round-robin fashion. So when - // we're handed a new fiber_context*, put it at the end of the fibers + // we're handed a new context*, put it at the end of the fibers // with that same priority. In other words: search for the first fiber // in the queue with LOWER priority, and insert before that one. - boost::fibers::fiber_context ** fp = & head_; + boost::fibers::context ** fp = & head_; for ( ; * fp; fp = & ( * fp)->nxt) { if ( properties( * fp).get_priority() < f_priority) { @@ -11159,13 +11159,13 @@ to return that result * fp = f; } - virtual boost::fibers::fiber_context * pick_next() { + virtual boost::fibers::context * pick_next() { // if ready queue is empty, just tell caller if ( ! head_) { return nullptr; } // Here we have at least one ready fiber. Unlink and return that. - boost::fibers::fiber_context * f = head_; + boost::fibers::context * f = head_; head_ = f->nxt; f->nxt = nullptr; @@ -11174,13 +11174,13 @@ to return that result virtual std::size_t ready_fibers() const noexcept { std::size_t count = 0; - for ( boost::fibers::fiber_context * f = head_; f; f = f->nxt) { + for ( boost::fibers::context * f = head_; f; f = f->nxt) { ++count; } return count; } - virtual void property_change( boost::fibers::fiber_context * f, priority_props & props) { + virtual void property_change( boost::fibers::context * f, priority_props & props) { // Although our priority_props class defines multiple properties, only // one of them (priority) actually calls notify() when changed. The // point of a property_change() override is to reshuffle the ready @@ -11189,7 +11189,7 @@ to return that result // Find 'f' in the queue. Note that it might not be in our queue at // all, if caller is changing the priority of (say) the running fiber. bool found = false; - for ( boost::fibers::fiber_context ** fp = & head_; * fp; fp = & ( * fp)->nxt) { + for ( boost::fibers::context ** fp = & head_; * fp; fp = & ( * fp)->nxt) { if ( * fp == f) { // found the passed fiber in our list -- unlink it found = true; @@ -11208,7 +11208,7 @@ to return that result } // Here we know that f was in our ready queue, but we've unlinked it. - // We happen to have a method that will (re-)add a fiber_context* to + // We happen to have a method that will (re-)add a context* to // the ready queue. awakened(f, props); } @@ -11239,7 +11239,7 @@ to return that result - Note use of the fiber_context::nxt member. + Note use of the context::nxt member. diff --git a/doc/html/fiber/custom.html b/doc/html/fiber/custom.html index 86264a33..af680fd0 100644 --- a/doc/html/fiber/custom.html +++ b/doc/html/fiber/custom.html @@ -98,7 +98,7 @@

class priority_props : public boost::fibers::fiber_properties {
 public:
-    priority_props( boost::fibers::fiber_context * p):
+    priority_props( boost::fibers::context * p):
         fiber_properties( p), 1
         priority_( 0) {
     }
@@ -134,7 +134,7 @@
 
 

1

- Your subclass constructor must accept a fiber_context* + Your subclass constructor must accept a context* and pass it to the fiber_properties constructor.

@@ -171,8 +171,8 @@ as the template parameter.

- Your custom scheduler can track ready fiber_context*s - using whatever container tactic you prefer. In this example, we use fiber_context::nxt to + Your custom scheduler can track ready context*s + using whatever container tactic you prefer. In this example, we use context::nxt to hand-implement an intrusive singly-linked list.

@@ -182,7 +182,7 @@ // Much as we would like, we don't use std::priority_queue because it // doesn't appear to provide any way to alter the priority (and hence // queue position) of a particular item. - boost::fibers::fiber_context * head_; + boost::fibers::context * head_; public: priority_scheduler() : @@ -191,15 +191,15 @@ // For a subclass of sched_algorithm_with_properties<>, it's important to // override the correct awakened() overload. - 1virtual void awakened( boost::fibers::fiber_context * f, priority_props & props) { + 1virtual void awakened( boost::fibers::context * f, priority_props & props) { int f_priority = props.get_priority(); 2 // With this scheduler, fibers with higher priority values are // preferred over fibers with lower priority values. But fibers with // equal priority values are processed in round-robin fashion. So when - // we're handed a new fiber_context*, put it at the end of the fibers + // we're handed a new context*, put it at the end of the fibers // with that same priority. In other words: search for the first fiber // in the queue with LOWER priority, and insert before that one. - boost::fibers::fiber_context ** fp = & head_; + boost::fibers::context ** fp = & head_; for ( ; * fp; fp = & ( * fp)->nxt) { if ( properties( * fp).get_priority() < f_priority) { 3 @@ -212,13 +212,13 @@ * fp = f; } - 5virtual boost::fibers::fiber_context * pick_next() { + 5virtual boost::fibers::context * pick_next() { // if ready queue is empty, just tell caller if ( ! head_) { return nullptr; } // Here we have at least one ready fiber. Unlink and return that. - boost::fibers::fiber_context * f = head_; + boost::fibers::context * f = head_; head_ = f->nxt; f->nxt = nullptr; @@ -227,13 +227,13 @@ 6virtual std::size_t ready_fibers() const noexcept { std::size_t count = 0; - for ( boost::fibers::fiber_context * f = head_; f; f = f->nxt) { + for ( boost::fibers::context * f = head_; f; f = f->nxt) { ++count; } return count; } - 7virtual void property_change( boost::fibers::fiber_context * f, priority_props & props) { + 7virtual void property_change( boost::fibers::context * f, priority_props & props) { // Although our priority_props class defines multiple properties, only // one of them (priority) actually calls notify() when changed. The // point of a property_change() override is to reshuffle the ready @@ -242,7 +242,7 @@ // Find 'f' in the queue. Note that it might not be in our queue at // all, if caller is changing the priority of (say) the running fiber. bool found = false; - for ( boost::fibers::fiber_context ** fp = & head_; * fp; fp = & ( * fp)->nxt) { + for ( boost::fibers::context ** fp = & head_; * fp; fp = & ( * fp)->nxt) { if ( * fp == f) { // found the passed fiber in our list -- unlink it found = true; @@ -261,7 +261,7 @@ } // Here we know that f was in our ready queue, but we've unlinked it. - // We happen to have a method that will (re-)add a fiber_context* to + // We happen to have a method that will (re-)add a context* to // the ready queue. awakened(f, props); } @@ -297,7 +297,7 @@

4

- Note use of the fiber_context::nxt member. + Note use of the context::nxt member.

diff --git a/doc/html/fiber/scheduling.html b/doc/html/fiber/scheduling.html index 9aa642a9..e7cb2f98 100644 --- a/doc/html/fiber/scheduling.html +++ b/doc/html/fiber/scheduling.html @@ -74,9 +74,9 @@ struct sched_algorithm { virtual ~sched_algorithm() {} - virtual void awakened( fiber_context *) = 0; + virtual void awakened( context *) = 0; - virtual fiber_context * pick_next() = 0; + virtual context * pick_next() = 0; virtual std::size_t ready_fibers() const noexcept = 0; }; @@ -91,7 +91,7 @@

-
virtual void awakened( fiber_context * f) = 0;
+
virtual void awakened( context * f) = 0;
 

@@ -125,7 +125,7 @@

-
virtual fiber_context * pick_next() = 0;
+
virtual context * pick_next() = 0;
 

@@ -184,9 +184,9 @@
#include <boost/fiber/round_robin.hpp>
 
 class round_robin : public sched_algorithm {
-    virtual void awakened( fiber_context *);
+    virtual void awakened( context *);
 
-    virtual fiber_context * pick_next();
+    virtual context * pick_next();
 
     virtual std::size_t ready_fibers() const noexcept;
 };
@@ -201,7 +201,7 @@
 
 

-
virtual void awakened( fiber_context * f);
+
virtual void awakened( context * f);
 

@@ -223,7 +223,7 @@

-
virtual fiber_context * pick_next();
+
virtual context * pick_next();
 

@@ -267,7 +267,7 @@

A scheduler class directly derived from sched_algorithm can - use any information available from fiber_context to implement + 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. @@ -293,7 +293,7 @@ class fiber_properties { public: - fiber_properties( fiber_context* f); + fiber_properties( context* f); virtual ~fiber_properties() {} @@ -305,7 +305,7 @@ Constructor -

fiber_properties( fiber_context* f);
+
fiber_properties( context* f);
 

@@ -316,7 +316,7 @@

Note:

- Your subclass constructor must accept a fiber_context* and pass it to the base-class fiber_properties constructor. + Your subclass constructor must accept a context* and pass it to the base-class fiber_properties constructor.

@@ -379,22 +379,22 @@ template< typename PROPS > struct sched_algorithm_with_properties { // override this method instead of sched_algorithm::awakened() - virtual void awakened( fiber_context * f, PROPS & properties) = 0; + virtual void awakened( context * f, PROPS & properties) = 0; - virtual fiber_context * pick_next(); + virtual context * pick_next(); virtual std::size_t ready_fibers() const noexcept; // obtain f's associated PROPS instance - PROPS & properties( fiber_context * f); + PROPS & properties( context * f); // override this to be notified by PROPS::notify() - virtual void property_change( fiber_context * f, PROPS & properties); + virtual void property_change( context * f, PROPS & properties); // Override this to customize instantiation of PROPS, e.g. use a different // allocator. Each PROPS instance is associated with a particular - // fiber_context. - virtual fiber_properties * new_properties( fiber_context * f); + // context. + virtual fiber_properties * new_properties( context * f); };

@@ -407,7 +407,7 @@

-
virtual void awakened( fiber_context * f, PROPS & properties);
+
virtual void awakened( context * f, PROPS & properties);
 

@@ -436,7 +436,7 @@

-
virtual fiber_context * pick_next();
+
virtual context * pick_next();
 

@@ -487,7 +487,7 @@

-
PROPS& properties( fiber_context * f);
+
PROPS& properties( context * f);
 

@@ -503,9 +503,9 @@ 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 fiber_context instances. + to track a collection of ready context instances. This method allows your custom scheduler to retrieve the fiber_properties subclass - instance for any fiber_context + instance for any context in its collection.

@@ -520,7 +520,7 @@

-
virtual void property_change( fiber_context * f, PROPS & properties);
+
virtual void property_change( context * f, PROPS & properties);
 

@@ -549,7 +549,7 @@

-
virtual fiber_properties * new_properties( fiber_context * f);
+
virtual fiber_properties * new_properties( context * f);
 

@@ -573,40 +573,40 @@

- - - Class fiber_context + + + Class context

- While you are free to treat fiber_context* as an opaque token, certain fiber_context members may be useful to a + While you are free to treat context* as an opaque token, certain context members may be useful to a custom scheduler implementation.

- (Most fiber_context members + (Most context members are implementation details; most of interest are implementations of fiber methods.)

-
#include <boost/fiber/fiber_context.hpp>
+
#include <boost/fiber/context.hpp>
 
-class fiber_context {
+class context {
 public:
-    fiber_context   *   nxt;
+    context   *   nxt;
 
-    static fiber_context * main_fiber();
+    static context * main_fiber();
 
 };
 

- - - Data member nxt + + + Data member nxt

-
fiber_context   *   nxt;
+
context   *   nxt;
 

@@ -615,9 +615,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 - fiber_context is returned + context is returned by sched_algorithm::pick_next(), but between - the time the fiber manager passes this fiber_context + 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. @@ -627,21 +627,21 @@

- - - Static + + + Static member function main_fiber()

-
static fiber_context * main_fiber();
+
static context * main_fiber();
 

Returns:

- the fiber_context associated + the context associated with the "main" fiber of the thread: the one implicitly created by the thread itself, rather than one explicitly created by Boost.Fiber.

diff --git a/doc/scheduling.qbk b/doc/scheduling.qbk index dc772689..f76c486e 100644 --- a/doc/scheduling.qbk +++ b/doc/scheduling.qbk @@ -43,16 +43,16 @@ fiber scheduler must implement. struct sched_algorithm { virtual ~sched_algorithm() {} - virtual void awakened( fiber_context *) = 0; + virtual void awakened( context *) = 0; - virtual fiber_context * pick_next() = 0; + virtual context * pick_next() = 0; virtual std::size_t ready_fibers() const noexcept = 0; }; [member_heading sched_algorithm..awakened] - virtual void awakened( fiber_context * f) = 0; + virtual void awakened( context * f) = 0; [variablelist [[Effects:] [Informs the scheduler that fiber `f` is ready to run. Fiber `f` @@ -66,7 +66,7 @@ queue.]] [member_heading sched_algorithm..pick_next] - virtual fiber_context * pick_next() = 0; + virtual context * pick_next() = 0; [variablelist [[Returns:] [the fiber which is to be resumed next, or `nullptr` if there is no @@ -93,16 +93,16 @@ This class implements __algo__, scheduling fibers in round-robin fashion. #include class round_robin : public sched_algorithm { - virtual void awakened( fiber_context *); + virtual void awakened( context *); - virtual fiber_context * pick_next(); + virtual context * pick_next(); virtual std::size_t ready_fibers() const noexcept; }; [member_heading round_robin..awakened] - virtual void awakened( fiber_context * f); + virtual void awakened( context * f); [variablelist [[Effects:] [Enqueues fiber `f` onto a ready queue.]] @@ -110,7 +110,7 @@ This class implements __algo__, scheduling fibers in round-robin fashion. [member_heading round_robin..pick_next] - virtual fiber_context * pick_next(); + virtual context * pick_next(); [variablelist [[Returns:] [the fiber at the head of the ready queue, or 0 if the queue is @@ -131,7 +131,7 @@ of that queue, shares the thread between ready fibers in round-robin fashion.]] [heading Custom Scheduler Fiber Properties] A scheduler class directly derived from __algo__ can use any information -available from [class_link fiber_context] to implement the `sched_algorithm` +available from [class_link 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. @@ -147,7 +147,7 @@ A custom fiber properties class must be derived from `fiber_properties`. class fiber_properties { public: - fiber_properties( fiber_context* f); + fiber_properties( context* f); virtual ~fiber_properties() {} @@ -157,11 +157,11 @@ A custom fiber properties class must be derived from `fiber_properties`. [heading Constructor] - fiber_properties( fiber_context* f); + fiber_properties( context* f); [variablelist [[Effects:] [Constructs base-class component of custom subclass.]] -[[Note:] [Your subclass constructor must accept a `fiber_context*` and pass it +[[Note:] [Your subclass constructor must accept a `context*` and pass it to the base-class `fiber_properties` constructor.]] ] @@ -201,27 +201,27 @@ derived from [class_link fiber_properties]. template< typename PROPS > struct sched_algorithm_with_properties { // override this method instead of sched_algorithm::awakened() - virtual void awakened( fiber_context * f, PROPS & properties) = 0; + virtual void awakened( context * f, PROPS & properties) = 0; - virtual fiber_context * pick_next(); + virtual context * pick_next(); virtual std::size_t ready_fibers() const noexcept; // obtain f's associated PROPS instance - PROPS & properties( fiber_context * f); + PROPS & properties( context * f); // override this to be notified by PROPS::notify() - virtual void property_change( fiber_context * f, PROPS & properties); + virtual void property_change( context * f, PROPS & properties); // Override this to customize instantiation of PROPS, e.g. use a different // allocator. Each PROPS instance is associated with a particular - // fiber_context. - virtual fiber_properties * new_properties( fiber_context * f); + // context. + virtual fiber_properties * new_properties( context * f); }; [member_heading sched_algorithm_with_properties..awakened] - virtual void awakened( fiber_context * f, PROPS & properties); + virtual void awakened( context * f, PROPS & properties); [variablelist [[Effects:] [Informs the scheduler that fiber `f` is ready to run, like @@ -233,7 +233,7 @@ method instead of `sched_algorithm::awakened()`.]] [member_heading sched_algorithm_with_properties..pick_next] - virtual fiber_context * pick_next(); + virtual context * pick_next(); [variablelist [[Returns:] [the fiber which is to be resumed next, or `nullptr` if there is no @@ -252,7 +252,7 @@ ready fiber.]] [member_heading sched_algorithm_with_properties..properties] - PROPS& properties( fiber_context * f); + PROPS& properties( context * f); [variablelist [[Returns:] [the `PROPS` instance associated with fiber `f`.]] @@ -260,14 +260,14 @@ ready fiber.]] [member_link sched_algorithm_with_properties..awakened] and [member_link sched_algorithm_with_properties..property_change]. However, every [class_link sched_algorithm] subclass is expected to track a collection of ready -[class_link fiber_context] instances. This method allows your custom scheduler +[class_link context] instances. This method allows your custom scheduler to retrieve the [class_link fiber_properties] subclass instance for any -`fiber_context` in its collection.]] +`context` in its collection.]] ] [member_heading sched_algorithm_with_properties..property_change] - virtual void property_change( fiber_context * f, PROPS & properties); + virtual void property_change( context * f, PROPS & properties); [variablelist [[Effects:] [Notify the custom scheduler of a possibly-relevant change to a @@ -280,7 +280,7 @@ fiber_properties..notify].]] [member_heading sched_algorithm_with_properties..new_properties] - virtual fiber_properties * new_properties( fiber_context * f); + virtual fiber_properties * new_properties( context * f); [variablelist [[Returns:] [A new instance of [class_link fiber_properties] subclass @@ -292,45 +292,45 @@ Override this method to allocate `PROPS` some other way. The returned with fiber `f`.]] ] -[class_heading fiber_context] +[class_heading context] -While you are free to treat `fiber_context*` as an opaque token, certain -`fiber_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 `fiber_context` members are implementation details; most of interest are +(Most `context` members are implementation details; most of interest are implementations of [class_link fiber] methods.) - #include + #include - class fiber_context { + class context { public: - fiber_context * nxt; + context * nxt; - static fiber_context * main_fiber(); + static context * main_fiber(); }; -[data_member_heading fiber_context..nxt] +[data_member_heading context..nxt] - fiber_context * nxt; + context * nxt; [variablelist [[Note:] [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 -`fiber_context` is returned by [member_link sched_algorithm..pick_next], but -between the time the fiber manager passes this `fiber_context` to [member_link +`context` is returned by [member_link sched_algorithm..pick_next], but +between the time the fiber manager passes this `context` to [member_link sched_algorithm..awakened] (or [member_link 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.]] ] -[static_member_heading fiber_context..main_fiber] +[static_member_heading context..main_fiber] - static fiber_context * main_fiber(); + static context * main_fiber(); [variablelist -[[Returns:] [the `fiber_context` associated with the "main" fiber of the +[[Returns:] [the `context` associated with the "main" fiber of the thread: the one implicitly created by the thread itself, rather than one explicitly created by __boost_fiber__.]] ] diff --git a/examples/priority.cpp b/examples/priority.cpp index 5a82d66b..5e81b122 100644 --- a/examples/priority.cpp +++ b/examples/priority.cpp @@ -27,9 +27,9 @@ private: //[priority_props class priority_props : public boost::fibers::fiber_properties { public: - priority_props( boost::fibers::fiber_context * p): + priority_props( boost::fibers::context * p): fiber_properties( p), /*< Your subclass constructor must accept a - [^[class_link fiber_context]*] and pass it to + [^[class_link context]*] and pass it to the `fiber_properties` constructor. >*/ priority_( 0) { } @@ -71,7 +71,7 @@ private: // Much as we would like, we don't use std::priority_queue because it // doesn't appear to provide any way to alter the priority (and hence // queue position) of a particular item. - boost::fibers::fiber_context * head_; + boost::fibers::context * head_; public: priority_scheduler() : @@ -83,17 +83,17 @@ public: /*<< You must override the [member_link sched_algorithm_with_properties..awakened] method. This is how your scheduler receives notification of a fiber that has become ready to run. >>*/ - virtual void awakened( boost::fibers::fiber_context * f, priority_props & props) { + virtual void awakened( boost::fibers::context * f, priority_props & props) { int f_priority = props.get_priority(); /*< `props` is the instance of priority_props associated with the passed fiber `f`. >*/ // With this scheduler, fibers with higher priority values are // preferred over fibers with lower priority values. But fibers with // equal priority values are processed in round-robin fashion. So when - // we're handed a new fiber_context*, put it at the end of the fibers + // we're handed a new context*, put it at the end of the fibers // with that same priority. In other words: search for the first fiber // in the queue with LOWER priority, and insert before that one. - boost::fibers::fiber_context ** fp = & head_; + boost::fibers::context ** fp = & head_; for ( ; * fp; fp = & ( * fp)->nxt) { if ( properties( * fp).get_priority() < f_priority) { /*< Use the @@ -104,7 +104,7 @@ public: } // It doesn't matter whether we hit the end of the list or found // another fiber with lower priority. Either way, insert f here. - f->nxt = * fp; /*< Note use of the [data_member_link fiber_context..nxt] member. >*/ + f->nxt = * fp; /*< Note use of the [data_member_link context..nxt] member. >*/ * fp = f; //<- @@ -116,13 +116,13 @@ public: /*<< You must override the [member_link sched_algorithm_with_properties..pick_next] method. This is how your scheduler actually advises the fiber manager of the next fiber to run. >>*/ - virtual boost::fibers::fiber_context * pick_next() { + virtual boost::fibers::context * pick_next() { // if ready queue is empty, just tell caller if ( ! head_) { return nullptr; } // Here we have at least one ready fiber. Unlink and return that. - boost::fibers::fiber_context * f = head_; + boost::fibers::context * f = head_; head_ = f->nxt; f->nxt = nullptr; @@ -137,7 +137,7 @@ public: to inform the fiber manager of the size of your ready queue. >>*/ virtual std::size_t ready_fibers() const noexcept { std::size_t count = 0; - for ( boost::fibers::fiber_context * f = head_; f; f = f->nxt) { + for ( boost::fibers::context * f = head_; f; f = f->nxt) { ++count; } return count; @@ -147,7 +147,7 @@ public: is optional. This override handles the case in which the running fiber changes the priority of another ready fiber: a fiber already in our queue. In that case, move the updated fiber within the queue. >>*/ - virtual void property_change( boost::fibers::fiber_context * f, priority_props & props) { + virtual void property_change( boost::fibers::context * f, priority_props & props) { // Although our priority_props class defines multiple properties, only // one of them (priority) actually calls notify() when changed. The // point of a property_change() override is to reshuffle the ready @@ -160,7 +160,7 @@ public: // Find 'f' in the queue. Note that it might not be in our queue at // all, if caller is changing the priority of (say) the running fiber. bool found = false; - for ( boost::fibers::fiber_context ** fp = & head_; * fp; fp = & ( * fp)->nxt) { + for ( boost::fibers::context ** fp = & head_; * fp; fp = & ( * fp)->nxt) { if ( * fp == f) { // found the passed fiber in our list -- unlink it found = true; @@ -188,7 +188,7 @@ public: } // Here we know that f was in our ready queue, but we've unlinked it. - // We happen to have a method that will (re-)add a fiber_context* to + // We happen to have a method that will (re-)add a context* to // the ready queue. awakened(f, props); } @@ -199,7 +199,7 @@ public: std::cout << "[empty]"; } else { const char * delim = ""; - for ( boost::fibers::fiber_context * f = head_; f; f = f->nxt) { + for ( boost::fibers::context * f = head_; f; f = f->nxt) { priority_props & props( properties( f) ); std::cout << delim << props.name << '(' << props.get_priority() << ')'; delim = ", "; diff --git a/examples/simple.cpp b/examples/simple.cpp index bff3a496..4190203e 100644 --- a/examples/simple.cpp +++ b/examples/simple.cpp @@ -22,7 +22,7 @@ // other Boost.Fiber operation. class shared_ready_queue : public boost::fibers::sched_algorithm { private: - typedef std::queue rqueue_t; + typedef std::queue rqueue_t; // The important point about this ready queue is that it's a class static, // common to all instances of shared_ready_queue. static rqueue_t rqueue_; @@ -32,16 +32,16 @@ private: typedef std::unique_lock lock_t; public: - virtual void awakened( boost::fibers::fiber_context * f) { + virtual void awakened( boost::fibers::context * f) { BOOST_ASSERT( nullptr != f); lock_t lock(mutex_); rqueue_.push( f); } - virtual boost::fibers::fiber_context * pick_next() { + virtual boost::fibers::context * pick_next() { lock_t lock(mutex_); - boost::fibers::fiber_context * victim( nullptr); + boost::fibers::context * victim( nullptr); if ( ! rqueue_.empty() ) { victim = rqueue_.front(); rqueue_.pop(); diff --git a/examples/work_sharing.cpp b/examples/work_sharing.cpp index 0b837c96..73429435 100644 --- a/examples/work_sharing.cpp +++ b/examples/work_sharing.cpp @@ -22,7 +22,7 @@ // other Boost.Fiber operation. class shared_ready_queue : public boost::fibers::sched_algorithm { private: - typedef std::queue rqueue_t; + typedef std::queue rqueue_t; // The important point about this ready queue is that it's a class static, // common to all instances of shared_ready_queue. static rqueue_t rqueue_; @@ -32,16 +32,16 @@ private: typedef std::unique_lock lock_t; public: - virtual void awakened( boost::fibers::fiber_context * f) { + virtual void awakened( boost::fibers::context * f) { BOOST_ASSERT( nullptr != f); lock_t lock(mutex_); rqueue_.push( f); } - virtual boost::fibers::fiber_context * pick_next() { + virtual boost::fibers::context * pick_next() { lock_t lock(mutex_); - boost::fibers::fiber_context * victim( nullptr); + boost::fibers::context * victim( nullptr); if ( ! rqueue_.empty() ) { victim = rqueue_.front(); rqueue_.pop(); diff --git a/include/boost/fiber/algorithm.hpp b/include/boost/fiber/algorithm.hpp index f6cd8980..871219d0 100644 --- a/include/boost/fiber/algorithm.hpp +++ b/include/boost/fiber/algorithm.hpp @@ -21,14 +21,14 @@ namespace boost { namespace fibers { -class fiber_context; +class context; struct BOOST_FIBERS_DECL sched_algorithm { virtual ~sched_algorithm() {} - virtual void awakened( fiber_context *) = 0; + virtual void awakened( context *) = 0; - virtual fiber_context * pick_next() = 0; + virtual context * pick_next() = 0; virtual std::size_t ready_fibers() const noexcept = 0; }; @@ -36,11 +36,11 @@ struct BOOST_FIBERS_DECL sched_algorithm { class BOOST_FIBERS_DECL sched_algorithm_with_properties_base : public sched_algorithm { public: // called by fiber_properties::notify() -- don't directly call - virtual void property_change_( fiber_context * f, fiber_properties * props) = 0; + virtual void property_change_( context * f, fiber_properties * props) = 0; protected: - static fiber_properties* get_properties( fiber_context * f) noexcept; - static void set_properties( fiber_context * f, fiber_properties * p) noexcept; + static fiber_properties* get_properties( context * f) noexcept; + static void set_properties( context * f, fiber_properties * p) noexcept; }; template< typename PROPS > @@ -51,7 +51,7 @@ struct sched_algorithm_with_properties : public sched_algorithm_with_properties_ // must override awakened() with properties parameter instead. Otherwise // you'd have to remember to start every subclass awakened() override // with: sched_algorithm_with_properties::awakened(fb); - virtual void awakened( fiber_context * f) final { + virtual void awakened( context * f) final { fiber_properties * props = super::get_properties( f); if ( ! props) { // TODO: would be great if PROPS could be allocated on the new @@ -74,26 +74,26 @@ struct sched_algorithm_with_properties : public sched_algorithm_with_properties_ } // subclasses override this method instead of the original awakened() - virtual void awakened( fiber_context *, PROPS& ) = 0; + virtual void awakened( context *, PROPS& ) = 0; // used for all internal calls - PROPS& properties( fiber_context * f) { + PROPS& properties( context * f) { return static_cast< PROPS & >( * super::get_properties( f) ); } // override this to be notified by PROPS::notify() - virtual void property_change( fiber_context * f, PROPS & props) { + virtual void property_change( context * f, PROPS & props) { } // implementation for sched_algorithm_with_properties_base method - void property_change_( fiber_context * f, fiber_properties * props ) final { + void property_change_( context * f, fiber_properties * props ) final { property_change( f, * static_cast< PROPS * >( props) ); } // Override this to customize instantiation of PROPS, e.g. use a different // allocator. Each PROPS instance is associated with a particular - // fiber_context. - virtual fiber_properties * new_properties( fiber_context * f) { + // context. + virtual fiber_properties * new_properties( context * f) { return new PROPS( f); } }; diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index a0c61014..144398f6 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,7 +30,7 @@ namespace boost { namespace fibers { -class fiber_context; +class context; enum class cv_status { no_timeout = 1, @@ -40,7 +40,7 @@ enum class cv_status { class BOOST_FIBERS_DECL condition { private: detail::spinlock splk_; - std::deque< fiber_context * > waiting_; + std::deque< context * > waiting_; public: condition(); @@ -63,7 +63,7 @@ public: template< typename LockType > void wait( LockType & lt) { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); try { // lock spinlock detail::spinlock_lock lk( splk_); @@ -79,13 +79,13 @@ public: // suspend this fiber // locked spinlock will be released if this fiber // was stored inside manager's waiting-queue - fiber_context::active()->do_wait( lk); + context::active()->do_wait( lk); // lock external again before returning lt.lock(); } catch (...) { detail::spinlock_lock lk( splk_); - std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); + std::deque< context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) { // remove fiber from waiting-list waiting_.erase( i); @@ -98,7 +98,7 @@ public: cv_status wait_until( LockType & lt, std::chrono::time_point< Clock, Duration > const& timeout_time) { cv_status status = cv_status::no_timeout; - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); try { // lock spinlock detail::spinlock_lock lk( splk_); @@ -113,11 +113,11 @@ public: // suspend this fiber // locked spinlock will be released if this fiber // was stored inside manager's waiting-queue - if ( ! fiber_context::active()->do_wait_until( timeout_time, lk) ) { + if ( ! context::active()->do_wait_until( timeout_time, lk) ) { // this fiber was not notified before timeout // lock spinlock again detail::spinlock_lock lk( splk_); - std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); + std::deque< context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) { // remove fiber from waiting-list waiting_.erase( i); @@ -130,7 +130,7 @@ public: lt.lock(); } catch (...) { detail::spinlock_lock lk( splk_); - std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); + std::deque< context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) { // remove fiber from waiting-list waiting_.erase( i); diff --git a/include/boost/fiber/fiber_context.hpp b/include/boost/fiber/context.hpp similarity index 91% rename from include/boost/fiber/fiber_context.hpp rename to include/boost/fiber/context.hpp index 1b05d01a..44efc5a2 100644 --- a/include/boost/fiber/fiber_context.hpp +++ b/include/boost/fiber/context.hpp @@ -4,8 +4,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_FIBERS_FIBER_CONTEXT_H -#define BOOST_FIBERS_FIBER_CONTEXT_H +#ifndef BOOST_FIBERS_CONTEXT_H +#define BOOST_FIBERS_CONTEXT_H #include #include @@ -40,7 +40,7 @@ namespace fibers { class fiber; class fiber_properties; -class BOOST_FIBERS_DECL fiber_context { +class BOOST_FIBERS_DECL context { private: enum class fiber_status { ready = 0, @@ -79,7 +79,7 @@ private: typedef std::map< uintptr_t, fss_data > fss_data_t; - static thread_local fiber_context * active_; + static thread_local context * active_; #if ! defined(BOOST_FIBERS_NO_ATOMICS) std::atomic< std::size_t > use_count_; @@ -92,9 +92,9 @@ private: #endif detail::spinlock splk_; fiber_manager * mgr_; - context::execution_context ctx_; + boost::context::execution_context ctx_; fss_data_t fss_data_; - std::vector< fiber_context * > waiting_; + std::vector< context * > waiting_; std::exception_ptr except_; std::chrono::steady_clock::time_point tp_; fiber_properties * properties_; @@ -106,14 +106,14 @@ protected: public: class id { private: - fiber_context * impl_; + context * impl_; public: id() noexcept : impl_( nullptr) { } - explicit id( fiber_context * impl) noexcept : + explicit id( context * impl) noexcept : impl_( impl) { } @@ -160,20 +160,20 @@ public: } }; - static fiber_context * active() noexcept; + static context * active() noexcept; - static fiber_context * active( fiber_context * active) noexcept; + static context * active( context * active) noexcept; - fiber_context * nxt; + context * nxt; // main fiber - fiber_context() : + context() : use_count_( 1), // allocated on stack state_( fiber_status::running), flags_( flag_main_fiber), splk_(), mgr_( nullptr), - ctx_( context::execution_context::current() ), + ctx_( boost::context::execution_context::current() ), fss_data_(), waiting_(), except_(), @@ -184,7 +184,7 @@ public: // worker fiber template< typename StackAlloc, typename Fn, typename ... Args > - fiber_context( context::preallocated palloc, + context( boost::context::preallocated palloc, StackAlloc salloc, Fn && fn, Args && ... args) : @@ -227,7 +227,7 @@ public: nxt( nullptr) { } - virtual ~fiber_context(); + virtual ~context(); void manager( fiber_manager * mgr) { BOOST_ASSERT( nullptr != mgr); @@ -239,10 +239,10 @@ public: } id get_id() const noexcept { - return id( const_cast< fiber_context * >( this) ); + return id( const_cast< context * >( this) ); } - bool join( fiber_context *); + bool join( context *); bool interruption_blocked() const noexcept { return 0 != ( flags_ & flag_interruption_blocked); @@ -382,7 +382,7 @@ public: void do_yield(); - void do_join( fiber_context *); + void do_join( context *); std::size_t do_ready_fibers() const noexcept; @@ -395,16 +395,16 @@ public: std::chrono::steady_clock::duration do_wait_interval() noexcept; - friend void intrusive_ptr_add_ref( fiber_context * f) { + friend void intrusive_ptr_add_ref( context * f) { BOOST_ASSERT( nullptr != f); ++f->use_count_; } - friend void intrusive_ptr_release( fiber_context * f) { + friend void intrusive_ptr_release( context * f) { BOOST_ASSERT( nullptr != f); if ( 0 == --f->use_count_) { BOOST_ASSERT( f->is_terminated() ); - f->~fiber_context(); + f->~context(); } } }; @@ -415,4 +415,4 @@ public: # include BOOST_ABI_SUFFIX #endif -#endif // BOOST_FIBERS_FIBER_CONTEXT_H +#endif // BOOST_FIBERS_CONTEXT_H diff --git a/include/boost/fiber/detail/fifo.hpp b/include/boost/fiber/detail/fifo.hpp index e6ba3722..eb18bc3b 100644 --- a/include/boost/fiber/detail/fifo.hpp +++ b/include/boost/fiber/detail/fifo.hpp @@ -21,7 +21,7 @@ namespace boost { namespace fibers { -class fiber_context; +class context; namespace detail { @@ -44,9 +44,9 @@ public: return size_; } - void push( fiber_context * item) noexcept; + void push( context * item) noexcept; - fiber_context * pop() noexcept; + context * pop() noexcept; void swap( fifo & other) { std::swap( head_, other.head_); @@ -55,12 +55,12 @@ public: private: std::size_t size_; - fiber_context * head_; + context * head_; // tail_ points to the nxt field that contains the null that marks the end // of the fifo. When the fifo is empty, tail_ points to head_. tail_ must - // never be null: it always points to a real fiber_context*. However, in + // never be null: it always points to a real context*. However, in // normal use, (*tail_) is always null. - fiber_context ** tail_; + context ** tail_; }; }}} diff --git a/include/boost/fiber/detail/terminated_queue.hpp b/include/boost/fiber/detail/terminated_queue.hpp index 537853dd..358b26a5 100644 --- a/include/boost/fiber/detail/terminated_queue.hpp +++ b/include/boost/fiber/detail/terminated_queue.hpp @@ -21,7 +21,7 @@ namespace boost { namespace fibers { -class fiber_context; +class context; namespace detail { @@ -39,7 +39,7 @@ public: terminated_queue( terminated_queue const&) = delete; terminated_queue & operator=( terminated_queue const&) = delete; - void push( fiber_context * item) noexcept; + void push( context * item) noexcept; void clear() noexcept; @@ -49,12 +49,12 @@ public: } private: - fiber_context * head_; + context * head_; // tail_ points to the nxt field that contains the null that marks the end // of the terminated_queue. When the terminated_queue is empty, tail_ points to head_. tail_ must - // never be null: it always points to a real fiber_context*. However, in + // never be null: it always points to a real context*. However, in // normal use, (*tail_) is always null. - fiber_context ** tail_; + context ** tail_; }; }}} diff --git a/include/boost/fiber/detail/waiting_queue.hpp b/include/boost/fiber/detail/waiting_queue.hpp index 51d2be9a..0c489185 100644 --- a/include/boost/fiber/detail/waiting_queue.hpp +++ b/include/boost/fiber/detail/waiting_queue.hpp @@ -21,7 +21,7 @@ namespace boost { namespace fibers { -class fiber_context; +class context; struct sched_algorithm; namespace detail { @@ -40,9 +40,9 @@ public: return nullptr == head_; } - void push( fiber_context * item) noexcept; + void push( context * item) noexcept; - fiber_context * top() const noexcept { + context * top() const noexcept { BOOST_ASSERT( ! empty() ); return head_; @@ -58,8 +58,8 @@ public: } private: - fiber_context * head_; - fiber_context * tail_; + context * head_; + context * tail_; }; }}} diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index 78dd0e7a..f8cae57d 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -29,13 +29,13 @@ namespace boost { namespace fibers { -class fiber_context; +class context; class BOOST_FIBERS_DECL fiber { private: - friend class fiber_context; + friend class context; - typedef intrusive_ptr< fiber_context > ptr_t; + typedef intrusive_ptr< context > ptr_t; ptr_t impl_; @@ -43,14 +43,14 @@ private: template< typename StackAlloc, typename Fn, typename ... Args > static ptr_t create( StackAlloc salloc, Fn && fn, Args && ... args) { - context::stack_context sctx( salloc.allocate() ); + boost::context::stack_context sctx( salloc.allocate() ); #if defined(BOOST_NO_CXX14_CONSTEXPR) || defined(BOOST_NO_CXX11_STD_ALIGN) // reserve space for control structure - std::size_t size = sctx.size - sizeof( fiber_context); - void * sp = static_cast< char * >( sctx.sp) - sizeof( fiber_context); + std::size_t size = sctx.size - sizeof( context); + void * sp = static_cast< char * >( sctx.sp) - sizeof( context); #else - constexpr std::size_t func_alignment = 64; // alignof( fiber_context); - constexpr std::size_t func_size = sizeof( fiber_context); + constexpr std::size_t func_alignment = 64; // alignof( context); + constexpr std::size_t func_size = sizeof( context); // reserve space on stack void * sp = static_cast< char * >( sctx.sp) - func_size - func_alignment; // align sp pointer @@ -60,16 +60,17 @@ private: // calculate remaining size std::size_t size = sctx.size - ( static_cast< char * >( sctx.sp) - static_cast< char * >( sp) ); #endif - // placement new of fiber_context on top of fiber's stack + // placement new of context on top of fiber's stack return ptr_t( - new ( sp) fiber_context( context::preallocated( sp, size, sctx), - salloc, - std::forward< Fn >( fn), - std::forward< Args >( args) ... ) ); + new ( sp) context( + boost::context::preallocated( sp, size, sctx), + salloc, + std::forward< Fn >( fn), + std::forward< Args >( args) ... ) ); } public: - typedef fiber_context::id id; + typedef context::id id; fiber() noexcept : impl_() { diff --git a/include/boost/fiber/fiber_manager.hpp b/include/boost/fiber/fiber_manager.hpp index 1c7471cf..efcbfabb 100644 --- a/include/boost/fiber/fiber_manager.hpp +++ b/include/boost/fiber/fiber_manager.hpp @@ -27,7 +27,7 @@ namespace boost { namespace fibers { -class fiber_context; +class context; struct sched_algorithm; struct BOOST_FIBERS_DECL fiber_manager { @@ -40,7 +40,7 @@ private: tqueue_t tqueue_; std::chrono::steady_clock::duration wait_interval_; - void resume_( fiber_context *); + void resume_( context *); bool wait_until_( std::chrono::steady_clock::time_point const&, detail::spinlock_lock &); @@ -53,7 +53,7 @@ public: virtual ~fiber_manager() noexcept; - void spawn( fiber_context *); + void spawn( context *); void run(); @@ -76,7 +76,7 @@ public: void yield(); - void join( fiber_context *); + void join( context *); std::size_t ready_fibers() const noexcept; diff --git a/include/boost/fiber/fss.hpp b/include/boost/fiber/fss.hpp index 3395a74e..b3f4c8f3 100644 --- a/include/boost/fiber/fss.hpp +++ b/include/boost/fiber/fss.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -62,7 +62,7 @@ public: } ~fiber_specific_ptr() { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); if ( nullptr != f) { f->set_fss_data( this, cleanup_fn_, nullptr, true); @@ -73,9 +73,9 @@ public: fiber_specific_ptr & operator=( fiber_specific_ptr const&) = delete; T * get() const { - BOOST_ASSERT( fiber_context::active() ); + BOOST_ASSERT( context::active() ); - void * vp( fiber_context::active()->get_fss_data( this) ); + void * vp( context::active()->get_fss_data( this) ); return static_cast< T * >( vp); } @@ -89,7 +89,7 @@ public: T * release() { T * tmp = get(); - fiber_context::active()->set_fss_data( + context::active()->set_fss_data( this, cleanup_fn_, nullptr, false); return tmp; } @@ -97,7 +97,7 @@ public: void reset( T * t) { T * c = get(); if ( c != t) { - fiber_context::active()->set_fss_data( + context::active()->set_fss_data( this, cleanup_fn_, t, true); } } diff --git a/include/boost/fiber/mutex.hpp b/include/boost/fiber/mutex.hpp index 1c449a53..83794a87 100644 --- a/include/boost/fiber/mutex.hpp +++ b/include/boost/fiber/mutex.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -31,8 +31,8 @@ private: detail::spinlock splk_; mutex_status state_; - fiber_context::id owner_; - std::deque< fiber_context * > waiting_; + context::id owner_; + std::deque< context * > waiting_; bool lock_if_unlocked_(); diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 8d90ba11..20aaa699 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -29,19 +29,19 @@ namespace this_fiber { inline fibers::fiber::id get_id() noexcept { - return fibers::fiber_context::active()->get_id(); + return fibers::context::active()->get_id(); } inline void yield() { - fibers::fiber_context::active()->do_yield(); + fibers::context::active()->do_yield(); } template< typename Clock, typename Duration > void sleep_until( std::chrono::time_point< Clock, Duration > const& sleep_time) { fibers::detail::spinlock splk; std::unique_lock< fibers::detail::spinlock > lk( splk); - fibers::fiber_context::active()->do_wait_until( sleep_time, lk); + fibers::context::active()->do_wait_until( sleep_time, lk); // check if fiber was interrupted interruption_point(); @@ -55,7 +55,7 @@ void sleep_for( std::chrono::duration< Rep, Period > const& timeout_duration) { template< typename PROPS > PROPS & properties() { fibers::fiber_properties * props = - fibers::fiber_context::active()->get_properties(); + fibers::context::active()->get_properties(); if ( ! props) { // props could be nullptr if the thread's main fiber has not yet // yielded (not yet passed through sched_algorithm_with_properties:: @@ -64,7 +64,7 @@ PROPS & properties() { // Try again to obtain the fiber_properties subclass instance ptr. // Walk through the whole chain again because who knows WHAT might // have happened while we were yielding! - props = fibers::fiber_context::active()->get_properties(); + props = fibers::context::active()->get_properties(); // Could still be hosed if the running manager isn't a subclass of // sched_algorithm_with_properties. BOOST_ASSERT_MSG(props, "this_fiber::properties not set"); @@ -78,33 +78,33 @@ namespace fibers { inline void migrate( fiber const& f) { - fiber_context::active()->do_spawn( f); + context::active()->do_spawn( f); } template< typename SchedAlgo, typename ... Args > void use_scheduling_algorithm( Args && ... args) { - fiber_context::active()->do_set_sched_algo( + context::active()->do_set_sched_algo( std::make_unique< SchedAlgo >( std::forward< Args >( args) ... ) ); } template< typename Rep, typename Period > void wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { - fiber_context::active()->do_wait_interval( wait_interval); + context::active()->do_wait_interval( wait_interval); } inline std::chrono::steady_clock::duration wait_interval() noexcept { - return fiber_context::active()->do_wait_interval(); + return context::active()->do_wait_interval(); } template< typename Rep, typename Period > std::chrono::duration< Rep, Period > wait_interval() noexcept { - return fiber_context::active()->do_wait_interval< Rep, Period >(); + return context::active()->do_wait_interval< Rep, Period >(); } inline std::size_t ready_fibers() { - return fiber_context::active()->do_ready_fibers(); + return context::active()->do_ready_fibers(); } }} diff --git a/include/boost/fiber/properties.hpp b/include/boost/fiber/properties.hpp index d8ebdf7c..254a027d 100644 --- a/include/boost/fiber/properties.hpp +++ b/include/boost/fiber/properties.hpp @@ -25,12 +25,12 @@ namespace boost { namespace fibers { struct sched_algorithm; -class fiber_context; +class context; class BOOST_FIBERS_DECL fiber_properties { protected: // initialized by constructor - fiber_context * fiber_; + context * fiber_; // set every time this fiber becomes READY sched_algorithm * sched_algo_; @@ -44,14 +44,14 @@ public: // instance variable, can/should call notify(). // fiber_properties, and by implication every subclass, must accept a back - // pointer to its fiber_context. - fiber_properties( fiber_context* f): + // pointer to its context. + fiber_properties( context* f): fiber_( f), sched_algo_( nullptr) {} // We need a virtual destructor (hence a vtable) because fiber_properties - // is stored polymorphically (as fiber_properties*) in fiber_context, and + // is stored polymorphically (as fiber_properties*) in context, and // destroyed via that pointer. virtual ~fiber_properties() {} diff --git a/include/boost/fiber/recursive_mutex.hpp b/include/boost/fiber/recursive_mutex.hpp index e658ee1f..5b99e80d 100644 --- a/include/boost/fiber/recursive_mutex.hpp +++ b/include/boost/fiber/recursive_mutex.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -34,9 +34,9 @@ private: detail::spinlock splk_; mutex_status state_; - fiber_context::id owner_; + context::id owner_; std::size_t count_; - std::deque< fiber_context * > waiting_; + std::deque< context * > waiting_; bool lock_if_unlocked_(); diff --git a/include/boost/fiber/recursive_timed_mutex.hpp b/include/boost/fiber/recursive_timed_mutex.hpp index 15c1e7dd..11fb8632 100644 --- a/include/boost/fiber/recursive_timed_mutex.hpp +++ b/include/boost/fiber/recursive_timed_mutex.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -36,9 +36,9 @@ private: detail::spinlock splk_; mutex_status state_; - fiber_context::id owner_; + context::id owner_; std::size_t count_; - std::deque< fiber_context * > waiting_; + std::deque< context * > waiting_; bool lock_if_unlocked_(); diff --git a/include/boost/fiber/round_robin.hpp b/include/boost/fiber/round_robin.hpp index a3d79bc5..36f83651 100644 --- a/include/boost/fiber/round_robin.hpp +++ b/include/boost/fiber/round_robin.hpp @@ -21,7 +21,7 @@ namespace boost { namespace fibers { -class fiber_context; +class context; class BOOST_FIBERS_DECL round_robin : public sched_algorithm { private: @@ -30,9 +30,9 @@ private: rqueue_t rqueue_; public: - virtual void awakened( fiber_context *); + virtual void awakened( context *); - virtual fiber_context * pick_next(); + virtual context * pick_next(); virtual std::size_t ready_fibers() const noexcept; }; diff --git a/include/boost/fiber/timed_mutex.hpp b/include/boost/fiber/timed_mutex.hpp index f30bbe20..282e00b4 100644 --- a/include/boost/fiber/timed_mutex.hpp +++ b/include/boost/fiber/timed_mutex.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -33,8 +33,8 @@ private: detail::spinlock splk_; mutex_status state_; - fiber_context::id owner_; - std::deque< fiber_context * > waiting_; + context::id owner_; + std::deque< context * > waiting_; bool lock_if_unlocked_(); diff --git a/src/algorithm.cpp b/src/algorithm.cpp index 863bf484..ea157ded 100644 --- a/src/algorithm.cpp +++ b/src/algorithm.cpp @@ -6,7 +6,7 @@ #include "boost/fiber/algorithm.hpp" -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -17,13 +17,13 @@ namespace fibers { //static fiber_properties * -sched_algorithm_with_properties_base::get_properties( fiber_context * f) noexcept { +sched_algorithm_with_properties_base::get_properties( context * f) noexcept { return f->get_properties(); } //static void -sched_algorithm_with_properties_base::set_properties( fiber_context * f, fiber_properties * props) noexcept { +sched_algorithm_with_properties_base::set_properties( context * f, fiber_properties * props) noexcept { f->set_properties( props); } diff --git a/src/condition.cpp b/src/condition.cpp index 348303d2..edf73ceb 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -6,7 +6,7 @@ #include "boost/fiber/condition.hpp" -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -26,7 +26,7 @@ condition::~condition() { void condition::notify_one() { - fiber_context * f( nullptr); + context * f( nullptr); detail::spinlock_lock lk( splk_); // get one waiting fiber @@ -44,7 +44,7 @@ condition::notify_one() { void condition::notify_all() { - std::deque< fiber_context * > waiting; + std::deque< context * > waiting; detail::spinlock_lock lk( splk_); // get all waiting fibers @@ -53,7 +53,7 @@ condition::notify_all() { // notify all waiting fibers while ( ! waiting.empty() ) { - fiber_context * f( waiting.front() ); + context * f( waiting.front() ); waiting.pop_front(); BOOST_ASSERT( nullptr != f); f->set_ready(); diff --git a/src/fiber_context.cpp b/src/context.cpp similarity index 75% rename from src/fiber_context.cpp rename to src/context.cpp index 7d837799..a8c4a08b 100644 --- a/src/fiber_context.cpp +++ b/src/context.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_context.hpp" +#include "boost/fiber/context.hpp" #include "boost/fiber/algorithm.hpp" #include "boost/fiber/exceptions.hpp" @@ -18,39 +18,39 @@ namespace boost { namespace fibers { -static fiber_context * main_fiber() { - static thread_local fiber_context mf; +static context * main_fiber() { + static thread_local context mf; static thread_local fiber_manager mgr; mf.manager( & mgr); return & mf; } -thread_local fiber_context * -fiber_context::active_ = main_fiber(); +thread_local context * +context::active_ = main_fiber(); -fiber_context * -fiber_context::active() noexcept { +context * +context::active() noexcept { return active_; } -fiber_context * -fiber_context::active( fiber_context * active) noexcept { +context * +context::active( context * active) noexcept { BOOST_ASSERT( nullptr != active); - fiber_context * old( active_); + context * old( active_); active_ = active; return old; } -fiber_context::~fiber_context() { +context::~context() { BOOST_ASSERT( waiting_.empty() ); delete properties_; } void -fiber_context::release() { +context::release() { BOOST_ASSERT( is_terminated() ); - std::vector< fiber_context * > waiting; + std::vector< context * > waiting; // get all waiting fibers splk_.lock(); @@ -58,7 +58,7 @@ fiber_context::release() { splk_.unlock(); // notify all waiting fibers - for ( fiber_context * f : waiting) { + for ( context * f : waiting) { BOOST_ASSERT( nullptr != f); BOOST_ASSERT( ! f->is_terminated() ); f->set_ready(); @@ -72,7 +72,7 @@ fiber_context::release() { } bool -fiber_context::join( fiber_context * f) { +context::join( context * f) { BOOST_ASSERT( nullptr != f); detail::spinlock_lock lk( splk_); @@ -84,7 +84,7 @@ fiber_context::join( fiber_context * f) { } void -fiber_context::interruption_blocked( bool blck) noexcept { +context::interruption_blocked( bool blck) noexcept { if ( blck) { flags_ |= flag_interruption_blocked; } else { @@ -93,7 +93,7 @@ fiber_context::interruption_blocked( bool blck) noexcept { } void -fiber_context::request_interruption( bool req) noexcept { +context::request_interruption( bool req) noexcept { if ( req) { flags_ |= flag_interruption_requested; } else { @@ -102,7 +102,7 @@ fiber_context::request_interruption( bool req) noexcept { } void * -fiber_context::get_fss_data( void const * vp) const { +context::get_fss_data( void const * vp) const { uintptr_t key( reinterpret_cast< uintptr_t >( vp) ); fss_data_t::const_iterator i( fss_data_.find( key) ); @@ -110,7 +110,7 @@ fiber_context::get_fss_data( void const * vp) const { } void -fiber_context::set_fss_data( void const * vp, +context::set_fss_data( void const * vp, detail::fss_cleanup_function::ptr_t const& cleanup_fn, void * data, bool cleanup_existing) { @@ -141,23 +141,23 @@ fiber_context::set_fss_data( void const * vp, } void -fiber_context::set_properties( fiber_properties * props) { +context::set_properties( fiber_properties * props) { delete properties_; properties_ = props; } void -fiber_context::do_spawn( fiber const& f_) { +context::do_spawn( fiber const& f_) { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); - fiber_context * f( f_.impl_.get() ); + context * f( f_.impl_.get() ); f->manager( mgr_); mgr_->spawn( f); } void -fiber_context::do_schedule() { +context::do_schedule() { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); @@ -165,7 +165,7 @@ fiber_context::do_schedule() { } void -fiber_context::do_wait( detail::spinlock_lock & lk) { +context::do_wait( detail::spinlock_lock & lk) { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); @@ -173,7 +173,7 @@ fiber_context::do_wait( detail::spinlock_lock & lk) { } void -fiber_context::do_yield() { +context::do_yield() { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); @@ -181,7 +181,7 @@ fiber_context::do_yield() { } void -fiber_context::do_join( fiber_context * f) { +context::do_join( context * f) { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); BOOST_ASSERT( nullptr != f); @@ -190,7 +190,7 @@ fiber_context::do_join( fiber_context * f) { } std::size_t -fiber_context::do_ready_fibers() const noexcept { +context::do_ready_fibers() const noexcept { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); @@ -198,7 +198,7 @@ fiber_context::do_ready_fibers() const noexcept { } void -fiber_context::do_set_sched_algo( std::unique_ptr< sched_algorithm > algo) { +context::do_set_sched_algo( std::unique_ptr< sched_algorithm > algo) { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); @@ -206,7 +206,7 @@ fiber_context::do_set_sched_algo( std::unique_ptr< sched_algorithm > algo) { } std::chrono::steady_clock::duration -fiber_context::do_wait_interval() noexcept { +context::do_wait_interval() noexcept { BOOST_ASSERT( nullptr != mgr_); BOOST_ASSERT( this == active_); diff --git a/src/detail/fifo.cpp b/src/detail/fifo.cpp index e06dd45a..68f8411f 100644 --- a/src/detail/fifo.cpp +++ b/src/detail/fifo.cpp @@ -8,7 +8,7 @@ #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -19,7 +19,7 @@ namespace fibers { namespace detail { void -fifo::push( fiber_context * item) noexcept { +fifo::push( context * item) noexcept { BOOST_ASSERT( nullptr != item); BOOST_ASSERT( nullptr == item->nxt); @@ -31,11 +31,11 @@ fifo::push( fiber_context * item) noexcept { ++size_; } -fiber_context * +context * fifo::pop() noexcept { BOOST_ASSERT( ! empty() ); - fiber_context * item( head_); + context * item( head_); head_ = head_->nxt; if ( nullptr == head_) { tail_ = & head_; diff --git a/src/detail/spinlock.cpp b/src/detail/spinlock.cpp index ad666c2e..92a6de8c 100644 --- a/src/detail/spinlock.cpp +++ b/src/detail/spinlock.cpp @@ -8,7 +8,7 @@ #include -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #include "boost/fiber/fiber_manager.hpp" namespace boost { @@ -27,7 +27,7 @@ atomic_spinlock::lock() { // sucessive acccess to state_ -> cache hit while ( atomic_spinlock_status::locked == state_.load( std::memory_order_relaxed) ) { // busy-wait - fiber_context::active()->do_yield(); + context::active()->do_yield(); } // state_ was released by other fiber // cached copies are invalidated -> cache miss diff --git a/src/detail/terminated_queue.cpp b/src/detail/terminated_queue.cpp index 2711c65f..ab3681a2 100644 --- a/src/detail/terminated_queue.cpp +++ b/src/detail/terminated_queue.cpp @@ -8,7 +8,7 @@ #include -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -19,7 +19,7 @@ namespace fibers { namespace detail { void -terminated_queue::push( fiber_context * item) noexcept { +terminated_queue::push( context * item) noexcept { BOOST_ASSERT( nullptr != item); BOOST_ASSERT( nullptr == item->nxt); @@ -33,12 +33,12 @@ terminated_queue::push( fiber_context * item) noexcept { void terminated_queue::clear() noexcept { while ( nullptr != head_) { - fiber_context * item( head_); + context * item( head_); head_ = head_->nxt; if ( nullptr == head_) { tail_ = & head_; } - // should call ~fiber_context() + // should call ~context() intrusive_ptr_release( item); } } diff --git a/src/detail/waiting_queue.cpp b/src/detail/waiting_queue.cpp index 445d8293..b14ad1d8 100644 --- a/src/detail/waiting_queue.cpp +++ b/src/detail/waiting_queue.cpp @@ -16,7 +16,7 @@ #include "boost/fiber/algorithm.hpp" #include "boost/fiber/detail/config.hpp" -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -27,7 +27,7 @@ namespace fibers { namespace detail { void -waiting_queue::push( fiber_context * item) noexcept { +waiting_queue::push( context * item) noexcept { BOOST_ASSERT( nullptr != item); BOOST_ASSERT( nullptr == item->nxt); @@ -46,8 +46,8 @@ waiting_queue::move_to( sched_algorithm * sched_algo) { std::chrono::steady_clock::time_point now( std::chrono::steady_clock::now() ); - fiber_context * prev = head_; - for ( fiber_context * f( head_); nullptr != f;) { + context * prev = head_; + for ( context * f( head_); nullptr != f;) { BOOST_ASSERT( ! f->is_running() ); BOOST_ASSERT( ! f->is_terminated() ); @@ -64,13 +64,13 @@ waiting_queue::move_to( sched_algorithm * sched_algo) { if ( head_ == f) { head_ = f->nxt; prev = head_; - fiber_context * item = f; + context * item = f; f = head_; if ( nullptr == head_) { tail_ = head_; } item->nxt = nullptr; - // Pass the newly-unlinked fiber_context* to sched_algo. + // Pass the newly-unlinked context* to sched_algo. item->time_point_reset(); sched_algo->awakened( item); } else { @@ -78,10 +78,10 @@ waiting_queue::move_to( sched_algorithm * sched_algo) { if ( nullptr == prev->nxt) { tail_ = prev; } - fiber_context * item = f; + context * item = f; f = f->nxt; item->nxt = nullptr; - // Pass the newly-unlinked fiber_context* to sched_algo. + // Pass the newly-unlinked context* to sched_algo. item->time_point_reset(); sched_algo->awakened( item); } @@ -91,7 +91,7 @@ waiting_queue::move_to( sched_algorithm * sched_algo) { void waiting_queue::interrupt_all() noexcept { - for ( fiber_context * f( head_); nullptr != f; f = f->nxt) { + for ( context * f( head_); nullptr != f; f = f->nxt) { f->request_interruption( true); } } diff --git a/src/fiber.cpp b/src/fiber.cpp index 75e7b948..30e0b22b 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -10,7 +10,7 @@ #include -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #include "boost/fiber/exceptions.hpp" #include "boost/fiber/operations.hpp" @@ -24,7 +24,7 @@ namespace fibers { void fiber::start_() { impl_->set_ready(); - fiber_context::active()->do_spawn( * this); + context::active()->do_spawn( * this); } void @@ -41,7 +41,7 @@ fiber::join() { "boost fiber: fiber not joinable"); } - fiber_context::active()->do_join( impl_.get() ); + context::active()->do_join( impl_.get() ); // check if joined fiber was interrupted std::exception_ptr except( impl_->get_exception() ); diff --git a/src/fiber_manager.cpp b/src/fiber_manager.cpp index 4ca9640b..4a3967e7 100644 --- a/src/fiber_manager.cpp +++ b/src/fiber_manager.cpp @@ -14,7 +14,7 @@ #include "boost/fiber/algorithm.hpp" #include "boost/fiber/exceptions.hpp" -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #include "boost/fiber/interruption.hpp" #include "boost/fiber/round_robin.hpp" @@ -43,7 +43,7 @@ fiber_manager::~fiber_manager() noexcept { // from waiting-queue to the runnable-queue wqueue_.move_to( sched_algo_.get() ); // pop new fiber from ready-queue - fiber_context * f( sched_algo_->pick_next() ); + context * f( sched_algo_->pick_next() ); if ( f) { BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); // set fiber_manager @@ -51,11 +51,11 @@ fiber_manager::~fiber_manager() noexcept { // 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 - f->join( fiber_context::active() ); + f->join( context::active() ); // set main-fiber to state_waiting - fiber_context::active()->set_waiting(); + context::active()->set_waiting(); // push main-fiber to waiting-queue - wqueue_.push( fiber_context::active() ); + wqueue_.push( context::active() ); // resume fiber f resume_( f); } else if ( wqueue_.empty() ) { @@ -68,35 +68,35 @@ fiber_manager::~fiber_manager() noexcept { } void -fiber_manager::resume_( fiber_context * f) { +fiber_manager::resume_( context * f) { BOOST_ASSERT( nullptr != f); BOOST_ASSERT( f->is_ready() ); // set fiber to state running f->set_running(); // fiber next-to-run is same as current active-fiber // this might happen in context of this_fiber::yield() - if ( f == fiber_context::active() ) { + if ( f == context::active() ) { return; } // pass new fiber the fiber_manager of the current active fiber // this might be necessary if the new fiber was miggrated from // another thread - f->manager( fiber_context::active()->manager() ); + f->manager( context::active()->manager() ); // assign new fiber to active-fiber - fiber_context * old( fiber_context::active( f) ); + context * old( context::active( f) ); // push terminated fibers to terminated-queue if ( old->is_terminated() ) { tqueue_.push( old); } // resume active-fiber == start or yield to - fiber_context::active()->resume(); + context::active()->resume(); } void -fiber_manager::spawn( fiber_context * f) { +fiber_manager::spawn( context * f) { BOOST_ASSERT( nullptr != f); BOOST_ASSERT( f->is_ready() ); - BOOST_ASSERT( f != fiber_context::active() ); + BOOST_ASSERT( f != context::active() ); // add new fiber to the scheduler sched_algo_->awakened( f); } @@ -110,7 +110,7 @@ fiber_manager::run() { // from waiting-queue to the runnable-queue wqueue_.move_to( sched_algo_.get() ); // pop new fiber from ready-queue - fiber_context * f( sched_algo_->pick_next() ); + context * f( sched_algo_->pick_next() ); if ( f) { BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); // set fiber_manager @@ -137,14 +137,14 @@ fiber_manager::wait( detail::spinlock_lock & lk) { bool fiber_manager::wait_until_( std::chrono::steady_clock::time_point const& timeout_time, detail::spinlock_lock & lk) { - BOOST_ASSERT( fiber_context::active()->is_running() ); + BOOST_ASSERT( context::active()->is_running() ); // set active-fiber to state_waiting - fiber_context::active()->set_waiting(); + context::active()->set_waiting(); // release lock lk.unlock(); // push active-fiber to waiting-queue - fiber_context::active()->time_point( timeout_time); - wqueue_.push( fiber_context::active() ); + context::active()->time_point( timeout_time); + wqueue_.push( context::active() ); // switch to another fiber run(); // fiber has been resumed @@ -156,11 +156,11 @@ fiber_manager::wait_until_( std::chrono::steady_clock::time_point const& timeout void fiber_manager::yield() { - BOOST_ASSERT( fiber_context::active()->is_running() ); + BOOST_ASSERT( context::active()->is_running() ); // set active-fiber to state_waiting - fiber_context::active()->set_ready(); + context::active()->set_ready(); // push active-fiber to wqueue_ - wqueue_.push( fiber_context::active() ); + wqueue_.push( context::active() ); // switch to another fiber run(); // fiber has been resumed @@ -169,19 +169,19 @@ fiber_manager::yield() { } void -fiber_manager::join( fiber_context * f) { +fiber_manager::join( context * f) { BOOST_ASSERT( nullptr != f); - BOOST_ASSERT( f != fiber_context::active() ); + BOOST_ASSERT( f != context::active() ); // set active-fiber to state_waiting - fiber_context::active()->set_waiting(); + context::active()->set_waiting(); // push active-fiber to waiting-queue - wqueue_.push( fiber_context::active() ); + wqueue_.push( context::active() ); // add active-fiber to joinig-list of f - if ( ! f->join( fiber_context::active() ) ) { + if ( ! f->join( context::active() ) ) { // f must be already terminated therefore we set // active-fiber to state_ready // FIXME: better state_running and no suspend - fiber_context::active()->set_ready(); + context::active()->set_ready(); } // switch to another fiber run(); diff --git a/src/interruption.cpp b/src/interruption.cpp index d8b7c76b..fd6a42d4 100644 --- a/src/interruption.cpp +++ b/src/interruption.cpp @@ -8,7 +8,7 @@ #include "boost/fiber/interruption.hpp" -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #include "boost/fiber/fiber_manager.hpp" #include "boost/fiber/exceptions.hpp" @@ -20,45 +20,45 @@ namespace boost { namespace this_fiber { disable_interruption::disable_interruption() noexcept : - set_( ( fibers::fiber_context::active()->interruption_blocked() ) ) { + set_( ( fibers::context::active()->interruption_blocked() ) ) { if ( ! set_) { - fibers::fiber_context::active()->interruption_blocked( true); + fibers::context::active()->interruption_blocked( true); } } disable_interruption::~disable_interruption() noexcept { if ( ! set_) { - fibers::fiber_context::active()->interruption_blocked( false); + fibers::context::active()->interruption_blocked( false); } } restore_interruption::restore_interruption( disable_interruption & disabler) noexcept : disabler_( disabler) { if ( ! disabler_.set_) { - fibers::fiber_context::active()->interruption_blocked( false); + fibers::context::active()->interruption_blocked( false); } } restore_interruption::~restore_interruption() noexcept { if ( ! disabler_.set_) { - fibers::fiber_context::active()->interruption_blocked( true); + fibers::context::active()->interruption_blocked( true); } } BOOST_FIBERS_DECL bool interruption_enabled() noexcept { - return ! fibers::fiber_context::active()->interruption_blocked(); + return ! fibers::context::active()->interruption_blocked(); } BOOST_FIBERS_DECL bool interruption_requested() noexcept { - return fibers::fiber_context::active()->interruption_requested(); + return fibers::context::active()->interruption_requested(); } BOOST_FIBERS_DECL void interruption_point() { if ( interruption_requested() && interruption_enabled() ) { - fibers::fiber_context::active()->request_interruption( false); + fibers::context::active()->request_interruption( false); throw fibers::fiber_interrupted(); } } diff --git a/src/mutex.cpp b/src/mutex.cpp index 56bddd12..43b3c389 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -47,7 +47,7 @@ mutex::~mutex() { void mutex::lock() { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); BOOST_ASSERT( nullptr != f); for (;;) { detail::spinlock_lock lk( splk_); @@ -61,7 +61,7 @@ mutex::lock() { waiting_.push_back( f); // suspend this fiber - fiber_context::active()->do_wait( lk); + context::active()->do_wait( lk); } } @@ -86,13 +86,13 @@ mutex::unlock() { BOOST_ASSERT( this_fiber::get_id() == owner_); detail::spinlock_lock lk( splk_); - fiber_context * f( nullptr); + context * f( nullptr); if ( ! waiting_.empty() ) { f = waiting_.front(); waiting_.pop_front(); BOOST_ASSERT( nullptr != f); } - owner_ = fiber_context::id(); + owner_ = context::id(); state_ = mutex_status::unlocked; lk.unlock(); diff --git a/src/properties.cpp b/src/properties.cpp index c1877d44..4324b880 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -9,7 +9,7 @@ #include "boost/fiber/algorithm.hpp" #include "boost/fiber/fiber_manager.hpp" -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp index 06241dad..d77efe4b 100644 --- a/src/recursive_mutex.cpp +++ b/src/recursive_mutex.cpp @@ -53,7 +53,7 @@ recursive_mutex::~recursive_mutex() { void recursive_mutex::lock() { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); BOOST_ASSERT( nullptr != f); for (;;) { detail::spinlock_lock lk( splk_); @@ -67,7 +67,7 @@ recursive_mutex::lock() { waiting_.push_back( f); // suspend this fiber - fiber_context::active()->do_wait( lk); + context::active()->do_wait( lk); } } @@ -92,14 +92,14 @@ recursive_mutex::unlock() { BOOST_ASSERT( this_fiber::get_id() == owner_); detail::spinlock_lock lk( splk_); - fiber_context * f( nullptr); + context * f( nullptr); if ( 0 == --count_) { if ( ! waiting_.empty() ) { f = waiting_.front(); waiting_.pop_front(); BOOST_ASSERT( nullptr != f); } - owner_ = fiber_context::id(); + owner_ = context::id(); state_ = mutex_status::unlocked; lk.unlock(); diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp index ac7594c0..7fcfaacd 100644 --- a/src/recursive_timed_mutex.cpp +++ b/src/recursive_timed_mutex.cpp @@ -53,7 +53,7 @@ recursive_timed_mutex::~recursive_timed_mutex() { void recursive_timed_mutex::lock() { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); BOOST_ASSERT( nullptr != f); for (;;) { detail::spinlock_lock lk( splk_); @@ -67,7 +67,7 @@ recursive_timed_mutex::lock() { waiting_.push_back( f); // suspend this fiber - fiber_context::active()->do_wait( lk); + context::active()->do_wait( lk); } } @@ -88,7 +88,7 @@ recursive_timed_mutex::try_lock() { bool recursive_timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeout_time) { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); BOOST_ASSERT( nullptr != f); for (;;) { detail::spinlock_lock lk( splk_); @@ -106,9 +106,9 @@ recursive_timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point co waiting_.push_back( f); // suspend this fiber until notified or timed-out - if ( ! fiber_context::active()->do_wait_until( timeout_time, lk) ) { + if ( ! context::active()->do_wait_until( timeout_time, lk) ) { lk.lock(); - std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); + std::deque< context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) { // remove fiber from waiting-list waiting_.erase( i); @@ -125,14 +125,14 @@ recursive_timed_mutex::unlock() { BOOST_ASSERT( this_fiber::get_id() == owner_); detail::spinlock_lock lk( splk_); - fiber_context * f( nullptr); + context * f( nullptr); if ( 0 == --count_) { if ( ! waiting_.empty() ) { f = waiting_.front(); waiting_.pop_front(); BOOST_ASSERT( nullptr != f); } - owner_ = fiber_context::id(); + owner_ = context::id(); state_ = mutex_status::unlocked; lk.unlock(); diff --git a/src/round_robin.cpp b/src/round_robin.cpp index 6cee13d3..cb1f3dc6 100644 --- a/src/round_robin.cpp +++ b/src/round_robin.cpp @@ -8,7 +8,7 @@ #include -#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/context.hpp" #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -18,15 +18,15 @@ namespace boost { namespace fibers { void -round_robin::awakened( fiber_context * f) { +round_robin::awakened( context * f) { BOOST_ASSERT( nullptr != f); rqueue_.push( f); } -fiber_context * +context * round_robin::pick_next() { - fiber_context * victim( nullptr); + context * victim( nullptr); if ( ! rqueue_.empty() ) { victim = rqueue_.pop(); BOOST_ASSERT( nullptr != victim); diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp index 9ab1cb8d..2393ed6a 100644 --- a/src/timed_mutex.cpp +++ b/src/timed_mutex.cpp @@ -47,7 +47,7 @@ timed_mutex::~timed_mutex() { void timed_mutex::lock() { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); BOOST_ASSERT( nullptr != f); for (;;) { detail::spinlock_lock lk( splk_); @@ -61,7 +61,7 @@ timed_mutex::lock() { waiting_.push_back( f); // suspend this fiber - fiber_context::active()->do_wait( lk); + context::active()->do_wait( lk); } } @@ -82,7 +82,7 @@ timed_mutex::try_lock() { bool timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeout_time) { - fiber_context * f( fiber_context::active() ); + context * f( context::active() ); BOOST_ASSERT( nullptr != f); for (;;) { detail::spinlock_lock lk( splk_); @@ -100,9 +100,9 @@ timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeo waiting_.push_back( f); // suspend this fiber until notified or timed-out - if ( ! fiber_context::active()->do_wait_until( timeout_time, lk) ) { + if ( ! context::active()->do_wait_until( timeout_time, lk) ) { lk.lock(); - std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); + std::deque< context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) { // remove fiber from waiting-list waiting_.erase( i); @@ -119,13 +119,13 @@ timed_mutex::unlock() { BOOST_ASSERT( this_fiber::get_id() == owner_); detail::spinlock_lock lk( splk_); - fiber_context * f( nullptr); + context * f( nullptr); if ( ! waiting_.empty() ) { f = waiting_.front(); waiting_.pop_front(); BOOST_ASSERT( nullptr != f); } - owner_ = fiber_context::id(); + owner_ = context::id(); state_ = mutex_status::unlocked; lk.unlock();