From 765014daee4a290c566a44a9b90941aed36a7b78 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 11 May 2015 05:38:45 -0400 Subject: [PATCH] working our way through build errors --- build/Jamfile.v2 | 3 ++- include/boost/fiber/algorithm.hpp | 36 +++++++++++-------------- include/boost/fiber/fiber_context.hpp | 3 --- src/algorithm.cpp | 38 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 src/algorithm.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 352f5735..3f2c1657 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -25,7 +25,8 @@ project boost/fiber ; lib boost_fiber - : barrier.cpp + : algorithm.cpp + barrier.cpp condition.cpp detail/fifo.cpp detail/spinlock.cpp diff --git a/include/boost/fiber/algorithm.hpp b/include/boost/fiber/algorithm.hpp index 66178534..c9fce2e7 100644 --- a/include/boost/fiber/algorithm.hpp +++ b/include/boost/fiber/algorithm.hpp @@ -10,7 +10,6 @@ #include #include -#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -18,6 +17,7 @@ namespace boost { namespace fibers { +class fiber_context; struct BOOST_FIBERS_DECL sched_algorithm { virtual ~sched_algorithm() {} @@ -27,23 +27,22 @@ struct BOOST_FIBERS_DECL sched_algorithm { virtual fiber_context * pick_next() = 0; }; -namespace detail { -// support sched_algorithm_with_properties::properties(fiber::id) -inline -fiber_context* extract_context(fiber_context::id id) { return id.impl_; } -} // detail - -struct BOOST_FIBERS_DECL sched_algorithm_with_properties_base: public 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; + +protected: + static fiber_properties* get_properties(fiber_context* f) noexcept; + static void set_properties(fiber_context* f, fiber_properties* p) noexcept; }; template struct sched_algorithm_with_properties: public sched_algorithm_with_properties_base { - typedef sched_algorithm_with_properties super; + typedef sched_algorithm_with_properties_base super; // Mark this override 'final': sched_algorithm_with_properties subclasses // must override awakened_props() instead. Otherwise you'd have to @@ -51,19 +50,21 @@ struct sched_algorithm_with_properties: // sched_algorithm_with_properties::awakened(fb); virtual void awakened( fiber_context *f) final { - if (! f->get_properties()) + fiber_properties* props = super::get_properties(f); + if (! props) { // TODO: would be great if PROPS could be allocated on the new // fiber's stack somehow - f->set_properties(new PROPS(f)); + props = new PROPS(f); + super::set_properties(f, props); } // Set sched_algo_ again every time this fiber becomes READY. That // handles the case of a fiber migrating to a new thread with a new // sched_algorithm subclass instance. - f->get_properties()->set_sched_algorithm(this); + props->set_sched_algorithm(this); // Okay, now forward the call to subclass override. - awakened_props(fb); + awakened_props(f); } // subclasses override this method instead of the original awakened() @@ -72,14 +73,7 @@ struct sched_algorithm_with_properties: // used for all internal calls PROPS& properties(fiber_context* f) { - return static_cast(*f->get_properties()); - } - - // public-facing properties(fiber::id) method in case consumer retains a - // pointer to supplied sched_algorithm_with_properties subclass - PROPS& properties(fiber::id id) - { - return properties(detail::extract_context(id)); + return static_cast(*super::get_properties(f)); } // override this to be notified by PROPS::notify() diff --git a/include/boost/fiber/fiber_context.hpp b/include/boost/fiber/fiber_context.hpp index 6c0ec55f..8c9bfa47 100644 --- a/include/boost/fiber/fiber_context.hpp +++ b/include/boost/fiber/fiber_context.hpp @@ -153,9 +153,6 @@ public: private: fiber_context * impl_; - // support sched_algorithm_with_properties::properties(fiber::id) - friend fiber_context* detail::extract_base(id); - public: id() noexcept : impl_( nullptr) { diff --git a/src/algorithm.cpp b/src/algorithm.cpp new file mode 100644 index 00000000..4da29cea --- /dev/null +++ b/src/algorithm.cpp @@ -0,0 +1,38 @@ + +// Copyright Oliver Kowalke / Nat Goodspeed 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "boost/fiber/detail/algorithm.hpp" + +#include + +#include + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace boost { +namespace fibers { + +//static +fiber_properties* +sched_algorithm_with_properties_base::get_properties(fiber_context* f) noexcept +{ + return f->get_properties(); +} + +//static +void +sched_algorithm_with_properties_base::set_properties(fiber_context* f, fiber_properties* props) noexcept +{ + f->set_properties(props); +} + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif