mirror of
https://github.com/boostorg/thread.git
synced 2026-01-24 06:22:12 +00:00
refactor ::then(f) in function of ::then(launch_policy, f).
This commit is contained in:
@@ -1309,6 +1309,15 @@ namespace boost
|
||||
else return launch(launch::none);
|
||||
}
|
||||
|
||||
launch launch_policy() const
|
||||
{
|
||||
if ( future_ ) {
|
||||
boost::unique_lock<boost::mutex> 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 <typename F>
|
||||
inline BOOST_THREAD_FUTURE<typename boost::result_of<F(BOOST_THREAD_FUTURE<R>)>::type>
|
||||
BOOST_THREAD_FUTURE<R>::then(BOOST_THREAD_FWD_REF(F) func) {
|
||||
typedef typename boost::result_of<F(BOOST_THREAD_FUTURE<R>)>::type future_type;
|
||||
BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized());
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(this->future_->mutex);
|
||||
if (underlying_cast<int>(this->launch_policy(lock)) & int(launch::async)) {
|
||||
lock.unlock();
|
||||
return boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
);
|
||||
} else if (underlying_cast<int>(this->launch_policy(lock)) & int(launch::deferred)) {
|
||||
this->future_->wait_internal(lock);
|
||||
lock.unlock();
|
||||
return boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
);
|
||||
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
} else if (underlying_cast<int>(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<Ex, BOOST_THREAD_FUTURE<R>, future_type>(ex,
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
)));
|
||||
#endif
|
||||
} else {
|
||||
lock.unlock();
|
||||
return boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
);
|
||||
}
|
||||
return this->then(this->launch_policy(), boost::forward<F>(func));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -4996,37 +4976,7 @@ namespace detail {
|
||||
template <typename F>
|
||||
inline BOOST_THREAD_FUTURE<typename boost::result_of<F(BOOST_THREAD_FUTURE<BOOST_THREAD_FUTURE<R2> >)>::type>
|
||||
BOOST_THREAD_FUTURE<BOOST_THREAD_FUTURE<R2> >::then(BOOST_THREAD_FWD_REF(F) func) {
|
||||
typedef BOOST_THREAD_FUTURE<R2> R;
|
||||
typedef typename boost::result_of<F(BOOST_THREAD_FUTURE<R>)>::type future_type;
|
||||
BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized());
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(this->future_->mutex);
|
||||
if (underlying_cast<int>(this->launch_policy(lock)) & int(launch::async)) {
|
||||
lock.unlock();
|
||||
return boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
);
|
||||
} else if (underlying_cast<int>(this->launch_policy(lock)) & int(launch::deferred)) {
|
||||
this->future_->wait_internal(lock);
|
||||
lock.unlock();
|
||||
return boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
);
|
||||
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
} else if (underlying_cast<int>(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<Ex, BOOST_THREAD_FUTURE<R>, future_type>(ex,
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
)));
|
||||
#endif
|
||||
} else {
|
||||
lock.unlock();
|
||||
return boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
|
||||
lock, boost::move(*this), boost::forward<F>(func)
|
||||
);
|
||||
}
|
||||
return this->then(this->launch_policy(), boost::forward<F>(func));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -5098,34 +5048,9 @@ namespace detail {
|
||||
template <typename F>
|
||||
inline BOOST_THREAD_FUTURE<typename boost::result_of<F(shared_future<R>)>::type>
|
||||
shared_future<R>::then(BOOST_THREAD_FWD_REF(F) func) const {
|
||||
typedef typename boost::result_of<F(shared_future<R>)>::type future_type;
|
||||
|
||||
BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized());
|
||||
return this->then(this->launch_policy(), boost::forward<F>(func));
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(this->future_->mutex);
|
||||
if (underlying_cast<int>(this->launch_policy(lock)) & int(launch::async)) {
|
||||
lock.unlock();
|
||||
return boost::detail::make_shared_future_async_continuation_shared_state<shared_future<R>, future_type>(
|
||||
lock, *this, boost::forward<F>(func));
|
||||
} else if (underlying_cast<int>(this->launch_policy(lock)) & int(launch::deferred)) {
|
||||
this->future_->wait_internal(lock);
|
||||
lock.unlock();
|
||||
return boost::detail::make_shared_future_deferred_continuation_shared_state<shared_future<R>, future_type>(
|
||||
lock, *this, boost::forward<F>(func));
|
||||
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
} else if (underlying_cast<int>(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<Ex, shared_future<R>, future_type>(ex,
|
||||
lock, *this, boost::forward<F>(func)
|
||||
)));
|
||||
#endif
|
||||
} else {
|
||||
lock.unlock();
|
||||
return boost::detail::make_shared_future_async_continuation_shared_state<shared_future<R>, future_type>(
|
||||
lock, *this, boost::forward<F>(func));
|
||||
}
|
||||
}
|
||||
|
||||
namespace detail
|
||||
|
||||
Reference in New Issue
Block a user