diff options
Diffstat (limited to 'boost/fiber/future')
-rw-r--r-- | boost/fiber/future/async.hpp | 78 | ||||
-rw-r--r-- | boost/fiber/future/detail/shared_state.hpp | 47 | ||||
-rw-r--r-- | boost/fiber/future/detail/shared_state_object.hpp | 13 | ||||
-rw-r--r-- | boost/fiber/future/detail/task_base.hpp | 4 | ||||
-rw-r--r-- | boost/fiber/future/detail/task_object.hpp | 88 | ||||
-rw-r--r-- | boost/fiber/future/future.hpp | 233 | ||||
-rw-r--r-- | boost/fiber/future/packaged_task.hpp | 27 | ||||
-rw-r--r-- | boost/fiber/future/promise.hpp | 69 |
8 files changed, 305 insertions, 254 deletions
diff --git a/boost/fiber/future/async.hpp b/boost/fiber/future/async.hpp index d969d19ce3..e68b2c28fa 100644 --- a/boost/fiber/future/async.hpp +++ b/boost/fiber/future/async.hpp @@ -23,63 +23,85 @@ namespace fibers { template< typename Fn, typename ... Args > future< - typename std::result_of< - typename std::enable_if< - ! detail::is_launch_policy< typename std::decay< Fn >::type >::value, - typename std::decay< Fn >::type - >::type( typename std::decay< Args >::type ... ) - >::type + typename std::result_of< + typename std::enable_if< + ! detail::is_launch_policy< typename std::decay< Fn >::type >::value, + typename std::decay< Fn >::type + >::type( typename std::decay< Args >::type ... ) + >::type > async( Fn && fn, Args && ... args) { typedef typename std::result_of< typename std::decay< Fn >::type( typename std::decay< Args >::type ... ) - >::type result_t; + >::type result_type; - packaged_task< result_t( typename std::decay< Args >::type ... ) > pt{ + packaged_task< result_type( typename std::decay< Args >::type ... ) > pt{ std::forward< Fn >( fn) }; - future< result_t > f{ pt.get_future() }; + future< result_type > f{ pt.get_future() }; fiber{ std::move( pt), std::forward< Args >( args) ... }.detach(); return f; } template< typename Policy, typename Fn, typename ... Args > future< - typename std::result_of< - typename std::enable_if< - detail::is_launch_policy< Policy >::value, - typename std::decay< Fn >::type - >::type( typename std::decay< Args >::type ...) - >::type + typename std::result_of< + typename std::enable_if< + detail::is_launch_policy< Policy >::value, + typename std::decay< Fn >::type + >::type( typename std::decay< Args >::type ...) + >::type > async( Policy policy, Fn && fn, Args && ... args) { typedef typename std::result_of< typename std::decay< Fn >::type( typename std::decay< Args >::type ... ) - >::type result_t; + >::type result_type; - packaged_task< result_t( typename std::decay< Args >::type ... ) > pt{ + packaged_task< result_type( typename std::decay< Args >::type ... ) > pt{ std::forward< Fn >( fn) }; - future< result_t > f{ pt.get_future() }; + future< result_type > f{ pt.get_future() }; fiber{ policy, std::move( pt), std::forward< Args >( args) ... }.detach(); return f; } template< typename Policy, typename StackAllocator, typename Fn, typename ... Args > future< - typename std::result_of< - typename std::enable_if< - detail::is_launch_policy< Policy >::value, - typename std::decay< Fn >::type - >::type( typename std::decay< Args >::type ... ) - >::type + typename std::result_of< + typename std::enable_if< + detail::is_launch_policy< Policy >::value, + typename std::decay< Fn >::type + >::type( typename std::decay< Args >::type ... ) + >::type > async( Policy policy, std::allocator_arg_t, StackAllocator salloc, Fn && fn, Args && ... args) { typedef typename std::result_of< typename std::decay< Fn >::type( typename std::decay< Args >::type ... ) - >::type result_t; + >::type result_type; - packaged_task< result_t( typename std::decay< Args >::type ... ) > pt{ - std::allocator_arg, salloc, std::forward< Fn >( fn) }; - future< result_t > f{ pt.get_future() }; + packaged_task< result_type( typename std::decay< Args >::type ... ) > pt{ + std::forward< Fn >( fn) }; + future< result_type > f{ pt.get_future() }; + fiber{ policy, std::allocator_arg, salloc, + std::move( pt), std::forward< Args >( args) ... }.detach(); + return f; +} + +template< typename Policy, typename StackAllocator, typename Allocator, typename Fn, typename ... Args > +future< + typename std::result_of< + typename std::enable_if< + detail::is_launch_policy< Policy >::value, + typename std::decay< Fn >::type + >::type( typename std::decay< Args >::type ... ) + >::type +> +async( Policy policy, std::allocator_arg_t, StackAllocator salloc, Allocator alloc, Fn && fn, Args && ... args) { + typedef typename std::result_of< + typename std::decay< Fn >::type( typename std::decay< Args >::type ... ) + >::type result_type; + + packaged_task< result_type( typename std::decay< Args >::type ... ) > pt{ + std::allocator_arg, alloc, std::forward< Fn >( fn) }; + future< result_type > f{ pt.get_future() }; fiber{ policy, std::allocator_arg, salloc, std::move( pt), std::forward< Args >( args) ... }.detach(); return f; diff --git a/boost/fiber/future/detail/shared_state.hpp b/boost/fiber/future/detail/shared_state.hpp index 5ec6858cf3..898fdaffd4 100644 --- a/boost/fiber/future/detail/shared_state.hpp +++ b/boost/fiber/future/detail/shared_state.hpp @@ -109,46 +109,47 @@ public: shared_state_base & operator=( shared_state_base const&) = delete; void owner_destroyed() { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; owner_destroyed_( lk); } void set_exception( std::exception_ptr except) { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; set_exception_( except, lk); } std::exception_ptr get_exception_ptr() { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; return get_exception_ptr_( lk); } void wait() const { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; wait_( lk); } template< typename Rep, typename Period > future_status wait_for( std::chrono::duration< Rep, Period > const& timeout_duration) const { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; return wait_for_( lk, timeout_duration); } template< typename Clock, typename Duration > future_status wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time) const { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; return wait_until_( lk, timeout_time); } friend inline void intrusive_ptr_add_ref( shared_state_base * p) noexcept { - ++p->use_count_; + p->use_count_.fetch_add( 1, std::memory_order_relaxed); } friend inline void intrusive_ptr_release( shared_state_base * p) noexcept { - if ( 0 == --p->use_count_) { - p->deallocate_future(); + if ( 1 == p->use_count_.fetch_sub( 1, std::memory_order_release) ) { + std::atomic_thread_fence( std::memory_order_acquire); + p->deallocate_future(); } } }; @@ -161,18 +162,18 @@ private: void set_value_( R const& value, std::unique_lock< mutex > & lk) { BOOST_ASSERT( lk.owns_lock() ); if ( ready_) { - throw promise_already_satisfied(); + throw promise_already_satisfied{}; } - ::new ( static_cast< void * >( std::addressof( storage_) ) ) R( value); + ::new ( static_cast< void * >( std::addressof( storage_) ) ) R{ value }; mark_ready_and_notify_( lk); } void set_value_( R && value, std::unique_lock< mutex > & lk) { BOOST_ASSERT( lk.owns_lock() ); if ( ready_) { - throw promise_already_satisfied(); + throw promise_already_satisfied{}; } - ::new ( static_cast< void * >( std::addressof( storage_) ) ) R( std::move( value) ); + ::new ( static_cast< void * >( std::addressof( storage_) ) ) R{ std::move( value) }; mark_ready_and_notify_( lk); } @@ -186,7 +187,7 @@ private: } public: - typedef intrusive_ptr< shared_state > ptr_t; + typedef intrusive_ptr< shared_state > ptr_type; shared_state() = default; @@ -200,17 +201,17 @@ public: shared_state & operator=( shared_state const&) = delete; void set_value( R const& value) { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; set_value_( value, lk); } void set_value( R && value) { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; set_value_( std::move( value), lk); } R & get() { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; return get_( lk); } }; @@ -239,7 +240,7 @@ private: } public: - typedef intrusive_ptr< shared_state > ptr_t; + typedef intrusive_ptr< shared_state > ptr_type; shared_state() = default; @@ -249,12 +250,12 @@ public: shared_state & operator=( shared_state const&) = delete; void set_value( R & value) { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; set_value_( value, lk); } R & get() { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; return get_( lk); } }; @@ -281,7 +282,7 @@ private: } public: - typedef intrusive_ptr< shared_state > ptr_t; + typedef intrusive_ptr< shared_state > ptr_type; shared_state() = default; @@ -292,13 +293,13 @@ public: inline void set_value() { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; set_value_( lk); } inline void get() { - std::unique_lock< mutex > lk( mtx_); + std::unique_lock< mutex > lk{ mtx_ }; get_( lk); } }; diff --git a/boost/fiber/future/detail/shared_state_object.hpp b/boost/fiber/future/detail/shared_state_object.hpp index dcdafef65c..50e08a6393 100644 --- a/boost/fiber/future/detail/shared_state_object.hpp +++ b/boost/fiber/future/detail/shared_state_object.hpp @@ -27,10 +27,11 @@ class shared_state_object : public shared_state< R > { public: typedef typename std::allocator_traits< Allocator >::template rebind_alloc< shared_state_object - > allocator_t; + > allocator_type; - shared_state_object( allocator_t const& alloc) : - shared_state< R >(), alloc_( alloc) { + shared_state_object( allocator_type const& alloc) : + shared_state< R >{}, + alloc_{ alloc } { } protected: @@ -39,10 +40,10 @@ protected: } private: - allocator_t alloc_; + allocator_type alloc_; - static void destroy_( allocator_t const& alloc, shared_state_object * p) noexcept { - allocator_t a{ alloc }; + static void destroy_( allocator_type const& alloc, shared_state_object * p) noexcept { + allocator_type a{ alloc }; a.destroy( p); a.deallocate( p, 1); } diff --git a/boost/fiber/future/detail/task_base.hpp b/boost/fiber/future/detail/task_base.hpp index 907e820470..83abd7e5ab 100644 --- a/boost/fiber/future/detail/task_base.hpp +++ b/boost/fiber/future/detail/task_base.hpp @@ -22,14 +22,14 @@ namespace detail { template< typename R, typename ... Args > struct task_base : public shared_state< R > { - typedef intrusive_ptr< task_base > ptr_t; + typedef intrusive_ptr< task_base > ptr_type; virtual ~task_base() { } virtual void run( Args && ... args) = 0; - virtual ptr_t reset() = 0; + virtual ptr_type reset() = 0; }; }}} diff --git a/boost/fiber/future/detail/task_object.hpp b/boost/fiber/future/detail/task_object.hpp index 37bfd3fd11..3a48929a58 100644 --- a/boost/fiber/future/detail/task_object.hpp +++ b/boost/fiber/future/detail/task_object.hpp @@ -9,10 +9,13 @@ #include <exception> #include <memory> +#include <tuple> #include <utility> #include <boost/config.hpp> +#if defined(BOOST_NO_CXX17_STD_APPLY) #include <boost/context/detail/apply.hpp> +#endif #include <boost/fiber/detail/config.hpp> #include <boost/fiber/future/detail/task_base.hpp> @@ -28,43 +31,49 @@ namespace detail { template< typename Fn, typename Allocator, typename R, typename ... Args > class task_object : public task_base< R, Args ... > { private: - typedef task_base< R, Args ... > base_t; + typedef task_base< R, Args ... > base_type; public: typedef typename std::allocator_traits< Allocator >::template rebind_alloc< task_object - > allocator_t; + > allocator_type; - task_object( allocator_t const& alloc, Fn const& fn) : - base_t(), - fn_( fn), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn const& fn) : + base_type{}, + fn_{ fn }, + alloc_{ alloc } { } - task_object( allocator_t const& alloc, Fn && fn) : - base_t(), - fn_( std::move( fn) ), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn && fn) : + base_type{}, + fn_{ std::move( fn) }, + alloc_{ alloc } { } void run( Args && ... args) override final { try { this->set_value( +#if defined(BOOST_NO_CXX17_STD_APPLY) boost::context::detail::apply( - fn_, std::make_tuple( std::forward< Args >( args) ... ) ) ); + fn_, std::make_tuple( std::forward< Args >( args) ... ) ) +#else + std::apply( + fn_, std::make_tuple( std::forward< Args >( args) ... ) ) +#endif + ); } catch (...) { this->set_exception( std::current_exception() ); } } - typename base_t::ptr_t reset() override final { - typedef std::allocator_traits< allocator_t > traits_t; + typename base_type::ptr_type reset() override final { + typedef std::allocator_traits< allocator_type > traity_type; - typename traits_t::pointer ptr{ traits_t::allocate( alloc_, 1) }; + typename traity_type::pointer ptr{ traity_type::allocate( alloc_, 1) }; try { - traits_t::construct( alloc_, ptr, alloc_, std::move( fn_) ); + traity_type::construct( alloc_, ptr, alloc_, std::move( fn_) ); } catch (...) { - traits_t::deallocate( alloc_, ptr, 1); + traity_type::deallocate( alloc_, ptr, 1); throw; } return { convert( ptr) }; @@ -77,10 +86,10 @@ protected: private: Fn fn_; - allocator_t alloc_; + allocator_type alloc_; - static void destroy_( allocator_t const& alloc, task_object * p) noexcept { - allocator_t a{ alloc }; + static void destroy_( allocator_type const& alloc, task_object * p) noexcept { + allocator_type a{ alloc }; a.destroy( p); a.deallocate( p, 1); } @@ -89,43 +98,48 @@ private: template< typename Fn, typename Allocator, typename ... Args > class task_object< Fn, Allocator, void, Args ... > : public task_base< void, Args ... > { private: - typedef task_base< void, Args ... > base_t; + typedef task_base< void, Args ... > base_type; public: typedef typename Allocator::template rebind< task_object< Fn, Allocator, void, Args ... > - >::other allocator_t; + >::other allocator_type; - task_object( allocator_t const& alloc, Fn const& fn) : - base_t(), - fn_( fn), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn const& fn) : + base_type{}, + fn_{ fn }, + alloc_{ alloc } { } - task_object( allocator_t const& alloc, Fn && fn) : - base_t(), - fn_( std::move( fn) ), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn && fn) : + base_type{}, + fn_{ std::move( fn) }, + alloc_{ alloc } { } void run( Args && ... args) override final { try { +#if defined(BOOST_NO_CXX17_STD_APPLY) boost::context::detail::apply( fn_, std::make_tuple( std::forward< Args >( args) ... ) ); +#else + std::apply( + fn_, std::make_tuple( std::forward< Args >( args) ... ) ); +#endif this->set_value(); } catch (...) { this->set_exception( std::current_exception() ); } } - typename base_t::ptr_t reset() override final { - typedef std::allocator_traits< allocator_t > traits_t; + typename base_type::ptr_type reset() override final { + typedef std::allocator_traits< allocator_type > traity_type; - typename traits_t::pointer ptr{ traits_t::allocate( alloc_, 1) }; + typename traity_type::pointer ptr{ traity_type::allocate( alloc_, 1) }; try { - traits_t::construct( alloc_, ptr, alloc_, std::move( fn_) ); + traity_type::construct( alloc_, ptr, alloc_, std::move( fn_) ); } catch (...) { - traits_t::deallocate( alloc_, ptr, 1); + traity_type::deallocate( alloc_, ptr, 1); throw; } return { convert( ptr) }; @@ -138,10 +152,10 @@ protected: private: Fn fn_; - allocator_t alloc_; + allocator_type alloc_; - static void destroy_( allocator_t const& alloc, task_object * p) noexcept { - allocator_t a{ alloc }; + static void destroy_( allocator_type const& alloc, task_object * p) noexcept { + allocator_type a{ alloc }; a.destroy( p); a.deallocate( p, 1); } diff --git a/boost/fiber/future/future.hpp b/boost/fiber/future/future.hpp index d92820eb58..5d4ad78ab5 100644 --- a/boost/fiber/future/future.hpp +++ b/boost/fiber/future/future.hpp @@ -24,13 +24,13 @@ namespace detail { template< typename R > struct future_base { - typedef typename shared_state< R >::ptr_t ptr_t; + typedef typename shared_state< R >::ptr_type ptr_type; - ptr_t state_{}; + ptr_type state_{}; - future_base() noexcept = default; + future_base() = default; - explicit future_base( ptr_t const& p) noexcept : + explicit future_base( ptr_type const& p) noexcept : state_{ p } { } @@ -46,15 +46,17 @@ struct future_base { } future_base & operator=( future_base const& other) noexcept { - if ( this == & other) return * this; - state_ = other.state_; + if ( this != & other) { + state_ = other.state_; + } return * this; } future_base & operator=( future_base && other) noexcept { - if ( this == & other) return * this; - state_ = other.state_; - other.state_.reset(); + if ( this != & other) { + state_ = other.state_; + other.state_.reset(); + } return * this; } @@ -107,128 +109,131 @@ class packaged_task; template< typename R > class future : private detail::future_base< R > { private: - typedef detail::future_base< R > base_t; + typedef detail::future_base< R > base_type; friend struct detail::promise_base< R >; friend class shared_future< R >; template< typename Signature > friend class packaged_task; - explicit future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - future() noexcept = default; + future() = default; future( future const&) = delete; future & operator=( future const&) = delete; future( future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } future & operator=( future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future< R > share(); R get() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } - typename base_t::ptr_t tmp{}; - tmp.swap( base_t::state_); + typename base_type::ptr_type tmp{}; + tmp.swap( base_type::state_); return std::move( tmp->get() ); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > class future< R & > : private detail::future_base< R & > { private: - typedef detail::future_base< R & > base_t; + typedef detail::future_base< R & > base_type; friend struct detail::promise_base< R & >; friend class shared_future< R & >; template< typename Signature > friend class packaged_task; - explicit future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - future() noexcept = default; + future() = default; future( future const&) = delete; future & operator=( future const&) = delete; future( future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } future & operator=( future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future< R & > share(); R & get() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } - typename base_t::ptr_t tmp{}; - tmp.swap( base_t::state_); + typename base_type::ptr_type tmp{}; + tmp.swap( base_type::state_); return tmp->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template<> class future< void > : private detail::future_base< void > { private: - typedef detail::future_base< void > base_t; + typedef detail::future_base< void > base_type; friend struct detail::promise_base< void >; friend class shared_future< void >; template< typename Signature > friend class packaged_task; - explicit future( base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit future( base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - future() noexcept = default; + future() = default; future( future const&) = delete; future & operator=( future const&) = delete; inline future( future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } inline future & operator=( future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } @@ -236,62 +241,64 @@ public: inline void get() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } - base_t::ptr_t tmp{}; - tmp.swap( base_t::state_); + base_type::ptr_type tmp{}; + tmp.swap( base_type::state_); tmp->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > class shared_future : private detail::future_base< R > { private: - typedef detail::future_base< R > base_t; + typedef detail::future_base< R > base_type; - explicit shared_future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit shared_future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - shared_future() noexcept = default; + shared_future() = default; ~shared_future() = default; shared_future( shared_future const& other) : - base_t{ other } { + base_type{ other } { } shared_future( shared_future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future( future< R > && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future & operator=( shared_future const& other) noexcept { - if ( this == & other) return * this; - base_t::operator=( other); + if ( this != & other) { + base_type::operator=( other); + } return * this; } shared_future & operator=( shared_future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future & operator=( future< R > && other) noexcept { - base_t::operator=( std::move( other) ); + base_type::operator=( std::move( other) ); return * this; } @@ -299,56 +306,58 @@ public: if ( ! valid() ) { throw future_uninitialized{}; } - return base_t::state_->get(); + return base_type::state_->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > class shared_future< R & > : private detail::future_base< R & > { private: - typedef detail::future_base< R & > base_t; + typedef detail::future_base< R & > base_type; - explicit shared_future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit shared_future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - shared_future() noexcept = default; + shared_future() = default; ~shared_future() = default; shared_future( shared_future const& other) : - base_t{ other } { + base_type{ other } { } shared_future( shared_future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future( future< R & > && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future & operator=( shared_future const& other) noexcept { - if ( this == & other) return * this; - base_t::operator=( other); + if ( this != & other) { + base_type::operator=( other); + } return * this; } shared_future & operator=( shared_future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future & operator=( future< R & > && other) noexcept { - base_t::operator=( std::move( other) ); + base_type::operator=( std::move( other) ); return * this; } @@ -356,62 +365,64 @@ public: if ( ! valid() ) { throw future_uninitialized{}; } - return base_t::state_->get(); + return base_type::state_->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template<> class shared_future< void > : private detail::future_base< void > { private: - typedef detail::future_base< void > base_t; + typedef detail::future_base< void > base_type; - explicit shared_future( base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit shared_future( base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - shared_future() noexcept = default; + shared_future() = default; ~shared_future() = default; inline shared_future( shared_future const& other) : - base_t{ other } { + base_type{ other } { } inline shared_future( shared_future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } inline shared_future( future< void > && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } inline shared_future & operator=( shared_future const& other) noexcept { - if ( this == & other) return * this; - base_t::operator=( other); + if ( this != & other) { + base_type::operator=( other); + } return * this; } inline shared_future & operator=( shared_future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } inline shared_future & operator=( future< void > && other) noexcept { - base_t::operator=( std::move( other) ); + base_type::operator=( std::move( other) ); return * this; } @@ -420,21 +431,21 @@ public: if ( ! valid() ) { throw future_uninitialized{}; } - base_t::state_->get(); + base_type::state_->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > shared_future< R > future< R >::share() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } return shared_future< R >{ std::move( * this) }; @@ -443,7 +454,7 @@ future< R >::share() { template< typename R > shared_future< R & > future< R & >::share() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } return shared_future< R & >{ std::move( * this) }; @@ -452,7 +463,7 @@ future< R & >::share() { inline shared_future< void > future< void >::share() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } return shared_future< void >{ std::move( * this) }; diff --git a/boost/fiber/future/packaged_task.hpp b/boost/fiber/future/packaged_task.hpp index 7ea16bfee7..31838ee41f 100644 --- a/boost/fiber/future/packaged_task.hpp +++ b/boost/fiber/future/packaged_task.hpp @@ -30,13 +30,13 @@ class packaged_task; template< typename R, typename ... Args > class packaged_task< R( Args ... ) > { private: - typedef typename detail::task_base< R, Args ... >::ptr_t ptr_t; + typedef typename detail::task_base< R, Args ... >::ptr_type ptr_type; bool obtained_{ false }; - ptr_t task_{}; + ptr_type task_{}; public: - constexpr packaged_task() noexcept = default; + packaged_task() = default; template< typename Fn, typename = detail::disable_overload< packaged_task, Fn > @@ -53,17 +53,17 @@ public: explicit packaged_task( std::allocator_arg_t, Allocator const& alloc, Fn && fn) { typedef detail::task_object< typename std::decay< Fn >::type, Allocator, R, Args ... - > object_t; + > object_type; typedef std::allocator_traits< - typename object_t::allocator_t - > traits_t; + typename object_type::allocator_type + > traits_type; - typename object_t::allocator_t a{ alloc }; - typename traits_t::pointer ptr{ traits_t::allocate( a, 1) }; + typename object_type::allocator_type a{ alloc }; + typename traits_type::pointer ptr{ traits_type::allocate( a, 1) }; try { - traits_t::construct( a, ptr, a, std::forward< Fn >( fn) ); + traits_type::construct( a, ptr, a, std::forward< Fn >( fn) ); } catch (...) { - traits_t::deallocate( a, ptr, 1); + traits_type::deallocate( a, ptr, 1); throw; } task_.reset( convert( ptr) ); @@ -85,9 +85,10 @@ public: } packaged_task & operator=( packaged_task && other) noexcept { - if ( this == & other) return * this; - packaged_task tmp{ std::move( other) }; - swap( tmp); + if ( this != & other) { + packaged_task tmp{ std::move( other) }; + swap( tmp); + } return * this; } diff --git a/boost/fiber/future/promise.hpp b/boost/fiber/future/promise.hpp index 278c839700..83ba63fb23 100644 --- a/boost/fiber/future/promise.hpp +++ b/boost/fiber/future/promise.hpp @@ -25,10 +25,10 @@ namespace detail { template< typename R > struct promise_base { - typedef typename shared_state< R >::ptr_t ptr_t; + typedef typename shared_state< R >::ptr_type ptr_type; bool obtained_{ false }; - ptr_t future_{}; + ptr_type future_{}; promise_base() : promise_base{ std::allocator_arg, std::allocator< promise_base >{} } { @@ -36,15 +36,15 @@ struct promise_base { template< typename Allocator > promise_base( std::allocator_arg_t, Allocator alloc) { - typedef detail::shared_state_object< R, Allocator > object_t; - typedef std::allocator_traits< typename object_t::allocator_t > traits_t; - typename object_t::allocator_t a{ alloc }; - typename traits_t::pointer ptr{ traits_t::allocate( a, 1) }; + typedef detail::shared_state_object< R, Allocator > object_type; + typedef std::allocator_traits< typename object_type::allocator_type > traits_type; + typename object_type::allocator_type a{ alloc }; + typename traits_type::pointer ptr{ traits_type::allocate( a, 1) }; try { - traits_t::construct( a, ptr, a); + traits_type::construct( a, ptr, a); } catch (...) { - traits_t::deallocate( a, ptr, 1); + traits_type::deallocate( a, ptr, 1); throw; } future_.reset( convert( ptr) ); @@ -66,9 +66,10 @@ struct promise_base { } promise_base & operator=( promise_base && other) noexcept { - if ( this == & other) return * this; - promise_base tmp{ std::move( other) }; - swap( tmp); + if ( this != & other) { + promise_base tmp{ std::move( other) }; + swap( tmp); + } return * this; } @@ -101,14 +102,14 @@ struct promise_base { template< typename R > class promise : private detail::promise_base< R > { private: - typedef detail::promise_base< R > base_t; + typedef detail::promise_base< R > base_type; public: promise() = default; template< typename Allocator > promise( std::allocator_arg_t, Allocator alloc) : - base_t{ std::allocator_arg, alloc } { + base_type{ std::allocator_arg, alloc } { } promise( promise const&) = delete; @@ -118,38 +119,38 @@ public: promise & operator=( promise && other) = default; void set_value( R const& value) { - if ( ! base_t::future_) { + if ( ! base_type::future_) { throw promise_uninitialized{}; } - base_t::future_->set_value( value); + base_type::future_->set_value( value); } void set_value( R && value) { - if ( ! base_t::future_) { + if ( ! base_type::future_) { throw promise_uninitialized{}; } - base_t::future_->set_value( std::move( value) ); + base_type::future_->set_value( std::move( value) ); } void swap( promise & other) noexcept { - base_t::swap( other); + base_type::swap( other); } - using base_t::get_future; - using base_t::set_exception; + using base_type::get_future; + using base_type::set_exception; }; template< typename R > class promise< R & > : private detail::promise_base< R & > { private: - typedef detail::promise_base< R & > base_t; + typedef detail::promise_base< R & > base_type; public: promise() = default; template< typename Allocator > promise( std::allocator_arg_t, Allocator alloc) : - base_t{ std::allocator_arg, alloc } { + base_type{ std::allocator_arg, alloc } { } promise( promise const&) = delete; @@ -159,31 +160,31 @@ public: promise & operator=( promise && other) noexcept = default; void set_value( R & value) { - if ( ! base_t::future_) { + if ( ! base_type::future_) { throw promise_uninitialized{}; } - base_t::future_->set_value( value); + base_type::future_->set_value( value); } void swap( promise & other) noexcept { - base_t::swap( other); + base_type::swap( other); } - using base_t::get_future; - using base_t::set_exception; + using base_type::get_future; + using base_type::set_exception; }; template<> class promise< void > : private detail::promise_base< void > { private: - typedef detail::promise_base< void > base_t; + typedef detail::promise_base< void > base_type; public: promise() = default; template< typename Allocator > promise( std::allocator_arg_t, Allocator alloc) : - base_t{ std::allocator_arg, alloc } { + base_type{ std::allocator_arg, alloc } { } promise( promise const&) = delete; @@ -194,19 +195,19 @@ public: inline void set_value() { - if ( ! base_t::future_) { + if ( ! base_type::future_) { throw promise_uninitialized{}; } - base_t::future_->set_value(); + base_type::future_->set_value(); } inline void swap( promise & other) noexcept { - base_t::swap( other); + base_type::swap( other); } - using base_t::get_future; - using base_t::set_exception; + using base_type::get_future; + using base_type::set_exception; }; template< typename R > |