From cc309eef8d2ae2f107ee0331f3587ea8f79a4d35 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Thu, 15 Oct 2015 23:31:38 +0200 Subject: [PATCH] refactor ::then(f) in function of ::then(launch_policy, f). --- include/boost/thread/future.hpp | 99 ++++----------------------------- 1 file changed, 12 insertions(+), 87 deletions(-) diff --git a/include/boost/thread/future.hpp b/include/boost/thread/future.hpp index 159099b3..23b08651 100644 --- a/include/boost/thread/future.hpp +++ b/include/boost/thread/future.hpp @@ -1309,6 +1309,15 @@ namespace boost else return launch(launch::none); } + launch launch_policy() const + { + if ( future_ ) { + boost::unique_lock lk(this->future_->mutex); + return future_->launch_policy(lk); + } + else return launch(launch::none); + } + exception_ptr get_exception_ptr() { return future_ @@ -4896,36 +4905,7 @@ namespace detail { template inline BOOST_THREAD_FUTURE)>::type> BOOST_THREAD_FUTURE::then(BOOST_THREAD_FWD_REF(F) func) { - typedef typename boost::result_of)>::type future_type; - BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized()); - - boost::unique_lock lock(this->future_->mutex); - if (underlying_cast(this->launch_policy(lock)) & int(launch::async)) { - lock.unlock(); - return boost::detail::make_future_async_continuation_shared_state, future_type>( - lock, boost::move(*this), boost::forward(func) - ); - } else if (underlying_cast(this->launch_policy(lock)) & int(launch::deferred)) { - this->future_->wait_internal(lock); - lock.unlock(); - return boost::detail::make_future_deferred_continuation_shared_state, future_type>( - lock, boost::move(*this), boost::forward(func) - ); -#ifdef BOOST_THREAD_PROVIDES_EXECUTORS - } else if (underlying_cast(this->launch_policy(lock)) & int(launch::executor)) { - typedef executor Ex; - Ex& ex = *(this->future_->get_executor()); - lock.unlock(); - return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_executor_continuation_shared_state, future_type>(ex, - lock, boost::move(*this), boost::forward(func) - ))); -#endif - } else { - lock.unlock(); - return boost::detail::make_future_async_continuation_shared_state, future_type>( - lock, boost::move(*this), boost::forward(func) - ); - } + return this->then(this->launch_policy(), boost::forward(func)); } //////////////////////////////// @@ -4996,37 +4976,7 @@ namespace detail { template inline BOOST_THREAD_FUTURE >)>::type> BOOST_THREAD_FUTURE >::then(BOOST_THREAD_FWD_REF(F) func) { - typedef BOOST_THREAD_FUTURE R; - typedef typename boost::result_of)>::type future_type; - BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized()); - - boost::unique_lock lock(this->future_->mutex); - if (underlying_cast(this->launch_policy(lock)) & int(launch::async)) { - lock.unlock(); - return boost::detail::make_future_async_continuation_shared_state, future_type>( - lock, boost::move(*this), boost::forward(func) - ); - } else if (underlying_cast(this->launch_policy(lock)) & int(launch::deferred)) { - this->future_->wait_internal(lock); - lock.unlock(); - return boost::detail::make_future_deferred_continuation_shared_state, future_type>( - lock, boost::move(*this), boost::forward(func) - ); -#ifdef BOOST_THREAD_PROVIDES_EXECUTORS - } else if (underlying_cast(this->launch_policy(lock)) & int(launch::executor)) { - typedef executor Ex; - Ex& ex = *(this->future_->get_executor()); - lock.unlock(); - return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_executor_continuation_shared_state, future_type>(ex, - lock, boost::move(*this), boost::forward(func) - ))); -#endif - } else { - lock.unlock(); - return boost::detail::make_future_async_continuation_shared_state, future_type>( - lock, boost::move(*this), boost::forward(func) - ); - } + return this->then(this->launch_policy(), boost::forward(func)); } //////////////////////////////// @@ -5098,34 +5048,9 @@ namespace detail { template inline BOOST_THREAD_FUTURE)>::type> shared_future::then(BOOST_THREAD_FWD_REF(F) func) const { - typedef typename boost::result_of)>::type future_type; - BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized()); + return this->then(this->launch_policy(), boost::forward(func)); - boost::unique_lock lock(this->future_->mutex); - if (underlying_cast(this->launch_policy(lock)) & int(launch::async)) { - lock.unlock(); - return boost::detail::make_shared_future_async_continuation_shared_state, future_type>( - lock, *this, boost::forward(func)); - } else if (underlying_cast(this->launch_policy(lock)) & int(launch::deferred)) { - this->future_->wait_internal(lock); - lock.unlock(); - return boost::detail::make_shared_future_deferred_continuation_shared_state, future_type>( - lock, *this, boost::forward(func)); -#ifdef BOOST_THREAD_PROVIDES_EXECUTORS - } else if (underlying_cast(this->launch_policy(lock)) & int(launch::executor)) { - typedef executor Ex; - Ex& ex = *(this->future_->get_executor()); - lock.unlock(); - return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_executor_continuation_shared_state, future_type>(ex, - lock, *this, boost::forward(func) - ))); -#endif - } else { - lock.unlock(); - return boost::detail::make_shared_future_async_continuation_shared_state, future_type>( - lock, *this, boost::forward(func)); - } } namespace detail