From e22c7fb1cbe3bcad2c78fe946520b78b7f57df4c Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Fri, 22 May 2015 09:50:39 +0200 Subject: [PATCH] some formating --- include/boost/fiber/algorithm.hpp | 44 ++++++++----------- include/boost/fiber/fiber.hpp | 7 ++- .../future/detail/shared_state_object.hpp | 3 +- include/boost/fiber/operations.hpp | 7 ++- include/boost/fiber/properties.hpp | 19 ++++---- include/boost/fiber/recursive_timed_mutex.hpp | 3 +- src/algorithm.cpp | 10 ++--- src/fiber_context.cpp | 3 +- src/properties.cpp | 12 +++-- 9 files changed, 46 insertions(+), 62 deletions(-) diff --git a/include/boost/fiber/algorithm.hpp b/include/boost/fiber/algorithm.hpp index bf1188e7..045267de 100644 --- a/include/boost/fiber/algorithm.hpp +++ b/include/boost/fiber/algorithm.hpp @@ -28,62 +28,56 @@ struct BOOST_FIBERS_DECL sched_algorithm { virtual fiber_context * pick_next() = 0; }; -class 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; + 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; + 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 -{ +template< typename PROPS > +struct sched_algorithm_with_properties : public sched_algorithm_with_properties_base { 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 // remember to start every subclass awakened() override with: // sched_algorithm_with_properties::awakened(fb); - virtual void awakened( fiber_context *f) final - { - fiber_properties* props = super::get_properties(f); - if (! props) - { + virtual void awakened( fiber_context * f) final { + 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 - props = new PROPS(f); - super::set_properties(f, props); + 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. - props->set_sched_algorithm(this); + props->set_sched_algorithm( this); // Okay, now forward the call to subclass override. - awakened_props(f); + awakened_props( f); } // subclasses override this method instead of the original awakened() virtual void awakened_props( fiber_context *) = 0; // used for all internal calls - PROPS& properties(fiber_context* f) - { - return static_cast(*super::get_properties(f)); + PROPS& properties( fiber_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( fiber_context * f, PROPS & props) { + } // implementation for sched_algorithm_with_properties_base method - void property_change_( fiber_context *f, fiber_properties* props ) final - { - property_change(f, *static_cast(props)); + void property_change_( fiber_context * f, fiber_properties * props ) final { + property_change( f, * static_cast< PROPS * >( props) ); } }; diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index c4f78635..44aaafee 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -122,10 +122,9 @@ public: void interrupt() noexcept; - template - PROPS& properties() - { - return dynamic_cast(*impl_->get_properties()); + template< typename PROPS > + PROPS & properties() { + return dynamic_cast< PROPS & >( * impl_->get_properties() ); } }; diff --git a/include/boost/fiber/future/detail/shared_state_object.hpp b/include/boost/fiber/future/detail/shared_state_object.hpp index c272ddd1..8def4ed7 100644 --- a/include/boost/fiber/future/detail/shared_state_object.hpp +++ b/include/boost/fiber/future/detail/shared_state_object.hpp @@ -21,8 +21,7 @@ namespace fibers { namespace detail { template< typename R, typename Allocator > -class shared_state_object : public shared_state< R > -{ +class shared_state_object : public shared_state< R > { public: typedef typename Allocator::template rebind< shared_state_object< R, Allocator > diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 95f0e73b..f79a8236 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -49,10 +49,9 @@ void sleep_for( std::chrono::duration< Rep, Period > const& timeout_duration) { sleep_until( std::chrono::high_resolution_clock::now() + timeout_duration); } -template < class PROPS > -PROPS& properties() -{ - return dynamic_cast(*fibers::detail::scheduler::instance()->active()->get_properties()); +template< typename PROPS > +PROPS & properties() { + return dynamic_cast< PROPS & >( * fibers::detail::scheduler::instance()->active()->get_properties() ); } } // this_fiber diff --git a/include/boost/fiber/properties.hpp b/include/boost/fiber/properties.hpp index c1e556e0..964afb02 100644 --- a/include/boost/fiber/properties.hpp +++ b/include/boost/fiber/properties.hpp @@ -27,13 +27,12 @@ namespace fibers { struct sched_algorithm; class fiber_context; -class fiber_properties -{ +class fiber_properties { protected: // initialized by constructor - fiber_context* fiber_; + fiber_context * fiber_; // set every time this fiber becomes READY - sched_algorithm* sched_algo_; + sched_algorithm * sched_algo_; // Inform the relevant sched_algorithm instance that something important // has changed, so it can (presumably) adjust its data structures @@ -43,12 +42,13 @@ protected: public: // fiber_properties, and by implication every subclass, must accept a back // pointer to its fiber_context. - typedef fiber_context* back_ptr; + typedef fiber_context * back_ptr; + // Any specific property setter method, after updating the relevant // instance variable, can/should call notify(). - fiber_properties(back_ptr f): - fiber_(f), - sched_algo_(nullptr) + fiber_properties( back_ptr f): + fiber_( f), + sched_algo_( nullptr) {} // We need a virtual destructor (hence a vtable) because fiber_properties @@ -58,8 +58,7 @@ public: // not really intended for public use, but sched_algorithm_with_properties // must be able to call this - void set_sched_algorithm(sched_algorithm* algo) - { + void set_sched_algorithm( sched_algorithm * algo) { sched_algo_ = algo; } }; diff --git a/include/boost/fiber/recursive_timed_mutex.hpp b/include/boost/fiber/recursive_timed_mutex.hpp index eaf50daf..6214c96e 100644 --- a/include/boost/fiber/recursive_timed_mutex.hpp +++ b/include/boost/fiber/recursive_timed_mutex.hpp @@ -27,8 +27,7 @@ namespace boost { namespace fibers { -class BOOST_FIBERS_DECL recursive_timed_mutex -{ +class BOOST_FIBERS_DECL recursive_timed_mutex { private: enum class mutex_status { locked = 0, diff --git a/src/algorithm.cpp b/src/algorithm.cpp index 609dcc6d..2f5c4535 100644 --- a/src/algorithm.cpp +++ b/src/algorithm.cpp @@ -18,17 +18,15 @@ namespace boost { namespace fibers { //static -fiber_properties* -sched_algorithm_with_properties_base::get_properties(fiber_context* f) noexcept -{ +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); +sched_algorithm_with_properties_base::set_properties( fiber_context * f, fiber_properties * props) noexcept { + f->set_properties( props); } }} diff --git a/src/fiber_context.cpp b/src/fiber_context.cpp index 42d329ff..9fb6d35d 100644 --- a/src/fiber_context.cpp +++ b/src/fiber_context.cpp @@ -125,8 +125,7 @@ fiber_context::set_fss_data( void const * vp, } void -fiber_context::set_properties( fiber_properties* props) -{ +fiber_context::set_properties( fiber_properties * props) { delete properties_; properties_ = props; } diff --git a/src/properties.cpp b/src/properties.cpp index e40b1ecc..e0b345e7 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -16,19 +16,17 @@ namespace boost { namespace fibers { -void fiber_properties::notify() -{ - BOOST_ASSERT(sched_algo_); +void fiber_properties::notify() { + BOOST_ASSERT( sched_algo_); // Application code might change an important property for any fiber at // any time. The fiber in question might be ready, running or waiting. // Significantly, only a fiber which is ready but not actually running is // in the sched_algorithm's ready queue. Don't bother the sched_algorithm // with a change to a fiber it's not currently tracking: it will do the // right thing next time the fiber is passed to its awakened() method. - if (fiber_->is_ready()) - { - static_cast(sched_algo_)-> - property_change_(fiber_, this); + if ( fiber_->is_ready() ) { + static_cast< sched_algorithm_with_properties_base * >( sched_algo_)-> + property_change_( fiber_, this); } }