diff options
Diffstat (limited to 'boost/thread/future.hpp')
-rw-r--r-- | boost/thread/future.hpp | 147 |
1 files changed, 125 insertions, 22 deletions
diff --git a/boost/thread/future.hpp b/boost/thread/future.hpp index 0ec484c2bf..6100c1606b 100644 --- a/boost/thread/future.hpp +++ b/boost/thread/future.hpp @@ -1434,6 +1434,10 @@ namespace boost template <class F, class Rp, class Fp> BOOST_THREAD_FUTURE<Rp> + make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); + + template <class F, class Rp, class Fp> + BOOST_THREAD_FUTURE<Rp> make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); template<typename F, typename Rp, typename Fp> @@ -1444,6 +1448,11 @@ namespace boost BOOST_THREAD_FUTURE<Rp> make_shared_future_async_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c); + template<typename F, typename Rp, typename Fp> + BOOST_THREAD_FUTURE<Rp> + make_shared_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c); + + #ifdef BOOST_THREAD_PROVIDES_EXECUTORS template<typename Ex, typename F, typename Rp, typename Fp> BOOST_THREAD_FUTURE<Rp> @@ -1518,6 +1527,10 @@ namespace boost template <class F, class Rp, class Fp> friend BOOST_THREAD_FUTURE<Rp> + detail::make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); + + template <class F, class Rp, class Fp> + friend BOOST_THREAD_FUTURE<Rp> detail::make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); template<typename F, typename Rp, typename Fp> @@ -1528,6 +1541,10 @@ namespace boost friend BOOST_THREAD_FUTURE<Rp> detail::make_shared_future_async_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c); + template<typename F, typename Rp, typename Fp> + friend BOOST_THREAD_FUTURE<Rp> + detail::make_shared_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c); + #ifdef BOOST_THREAD_PROVIDES_EXECUTORS template<typename Ex, typename F, typename Rp, typename Fp> friend BOOST_THREAD_FUTURE<Rp> @@ -1774,6 +1791,10 @@ namespace boost template <class F, class Rp, class Fp> friend BOOST_THREAD_FUTURE<Rp> + detail::make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); + + template <class F, class Rp, class Fp> + friend BOOST_THREAD_FUTURE<Rp> detail::make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); template<typename F, typename Rp, typename Fp> @@ -1784,6 +1805,10 @@ namespace boost friend BOOST_THREAD_FUTURE<Rp> detail::make_shared_future_async_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c); + template<typename F, typename Rp, typename Fp> + friend BOOST_THREAD_FUTURE<Rp> + detail::make_shared_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c); + #ifdef BOOST_THREAD_PROVIDES_EXECUTORS template<typename Ex, typename F, typename Rp, typename Fp> friend BOOST_THREAD_FUTURE<Rp> @@ -2007,6 +2032,10 @@ namespace boost template <class F, class Rp, class Fp> friend BOOST_THREAD_FUTURE<Rp> + detail::make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); + + template <class F, class Rp, class Fp> + friend BOOST_THREAD_FUTURE<Rp> detail::make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c); #endif #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK @@ -4210,12 +4239,6 @@ namespace detail { //////////////////////////////// #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION -#if defined BOOST_THREAD_CONTINUATION_SYNC -#define continuation_shared_state_base shared_state -#else -#define continuation_shared_state_base future_async_shared_state_base -#endif - namespace detail { ////////////////////// @@ -4345,27 +4368,44 @@ namespace detail ///////////////////////// template<typename F, typename Rp, typename Fp> - struct future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> > + struct future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> > { - typedef continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> > base_type; + typedef continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> > base_type; public: future_async_continuation_shared_state(BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c) : base_type(boost::move(f), boost::forward<Fp>(c)) { } void launch_continuation() { -#if defined BOOST_THREAD_CONTINUATION_SYNC - this->call(); -#elif defined BOOST_THREAD_FUTURE_BLOCKING +#if defined BOOST_THREAD_FUTURE_BLOCKING boost::lock_guard<boost::mutex> lk(this->mutex); this->thr_ = thread(&future_async_continuation_shared_state::run, static_shared_from_this(this)); #else - thread(&future_async_continuation_shared_state::run, static_shared_from_this(this)).detach(); + thread(&base_type::run, static_shared_from_this(this)).detach(); #endif } }; ///////////////////////// + /// future_sync_continuation_shared_state + ///////////////////////// + + template<typename F, typename Rp, typename Fp> + struct future_sync_continuation_shared_state: continuation_shared_state<F,Rp,Fp,shared_state<Rp> > + { + typedef continuation_shared_state<F,Rp,Fp,shared_state<Rp> > base_type; + public: + future_sync_continuation_shared_state(BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c) + : base_type(boost::move(f), boost::forward<Fp>(c)) + { } + + void launch_continuation() { + this->call(); + } + }; + + + ///////////////////////// /// future_executor_continuation_shared_state ///////////////////////// #ifdef BOOST_THREAD_PROVIDES_EXECUTORS @@ -4445,9 +4485,9 @@ namespace detail { ///////////////////////// template<typename F, typename Rp, typename Fp> - struct shared_future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> > + struct shared_future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> > { - typedef continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> > base_type; + typedef continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> > base_type; public: shared_future_async_continuation_shared_state(F f, BOOST_THREAD_FWD_REF(Fp) c) @@ -4456,19 +4496,36 @@ namespace detail { } void launch_continuation() { -#if defined BOOST_THREAD_CONTINUATION_SYNC - this->call(); -#elif defined BOOST_THREAD_FUTURE_BLOCKING +#if defined BOOST_THREAD_FUTURE_BLOCKING boost::lock_guard<boost::mutex> lk(this->mutex); - this->thr_ = thread(&shared_future_async_continuation_shared_state::run, static_shared_from_this(this)); + this->thr_ = thread(&base_type::run, static_shared_from_this(this)); #else - thread(&shared_future_async_continuation_shared_state::run, static_shared_from_this(this)).detach(); + thread(&base_type::run, static_shared_from_this(this)).detach(); #endif } + }; - ~shared_future_async_continuation_shared_state() {} + ///////////////////////// + /// shared_future_async_continuation_shared_state + ///////////////////////// + + template<typename F, typename Rp, typename Fp> + struct shared_future_sync_continuation_shared_state: continuation_shared_state<F,Rp,Fp,shared_state<Rp> > + { + typedef continuation_shared_state<F,Rp,Fp,shared_state<Rp> > base_type; + + public: + shared_future_sync_continuation_shared_state(F f, BOOST_THREAD_FWD_REF(Fp) c) + : base_type(boost::move(f), boost::forward<Fp>(c)) + { + } + + void launch_continuation() { + this->call(); + } }; + ///////////////////////// /// shared_future_executor_continuation_shared_state ///////////////////////// @@ -4577,6 +4634,21 @@ namespace detail { return BOOST_THREAD_FUTURE<Rp>(h); } + //////////////////////////////// + // make_future_sync_continuation_shared_state + //////////////////////////////// + template<typename F, typename Rp, typename Fp> + BOOST_THREAD_FUTURE<Rp> + make_future_sync_continuation_shared_state( + boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, + BOOST_THREAD_FWD_REF(Fp) c) { + typedef typename decay<Fp>::type Cont; + shared_ptr<future_sync_continuation_shared_state<F,Rp, Cont> > + h(new future_sync_continuation_shared_state<F,Rp, Cont>(boost::move(f), boost::forward<Fp>(c))); + h->init(lock); + + return BOOST_THREAD_FUTURE<Rp>(h); + } //////////////////////////////// // make_future_executor_continuation_shared_state @@ -4628,6 +4700,21 @@ namespace detail { return BOOST_THREAD_FUTURE<Rp>(h); } //////////////////////////////// + // make_shared_future_sync_continuation_shared_state + //////////////////////////////// + template<typename F, typename Rp, typename Fp> + BOOST_THREAD_FUTURE<Rp> + make_shared_future_sync_continuation_shared_state( + boost::unique_lock<boost::mutex> &lock, F f, + BOOST_THREAD_FWD_REF(Fp) c) { + typedef typename decay<Fp>::type Cont; + shared_ptr<shared_future_sync_continuation_shared_state<F,Rp, Cont> > + h(new shared_future_sync_continuation_shared_state<F,Rp, Cont>(f, boost::forward<Fp>(c))); + h->init(lock); + + return BOOST_THREAD_FUTURE<Rp>(h); + } + //////////////////////////////// // make_shared_future_executor_continuation_shared_state //////////////////////////////// #ifdef BOOST_THREAD_PROVIDES_EXECUTORS @@ -4787,6 +4874,10 @@ namespace detail { return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>( lock, boost::move(*this), boost::forward<F>(func) ))); + } else if (underlying_cast<int>(policy) & int(launch::sync)) { + return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_sync_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>(policy) & int(launch::executor)) { assert(this->future_->get_executor()); @@ -4807,6 +4898,10 @@ namespace detail { return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>( lock, boost::move(*this), boost::forward<F>(func) ))); + } else if (underlying_cast<int>(policy) & int(launch::sync)) { + return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_sync_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>(policy) & int(launch::executor)) { assert(this->future_->get_executor()); @@ -4878,7 +4973,7 @@ namespace detail { lock, boost::move(*this), boost::forward<F>(func) ))); } else { - return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>( + return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_sync_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>( lock, boost::move(*this), boost::forward<F>(func) ))); } @@ -4906,6 +5001,10 @@ namespace detail { return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_deferred_continuation_shared_state<shared_future<R>, future_type>( lock, *this, boost::forward<F>(func) ))); + } else if (underlying_cast<int>(policy) & int(launch::sync)) { + return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_sync_continuation_shared_state<shared_future<R>, future_type>( + lock, *this, boost::forward<F>(func) + ))); #ifdef BOOST_THREAD_PROVIDES_EXECUTORS } else if (underlying_cast<int>(policy) & int(launch::executor)) { typedef executor Ex; @@ -4925,6 +5024,10 @@ namespace detail { return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_deferred_continuation_shared_state<shared_future<R>, future_type>( lock, *this, boost::forward<F>(func) ))); + } else if (underlying_cast<int>(policy) & int(launch::sync)) { + return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_sync_continuation_shared_state<shared_future<R>, future_type>( + lock, *this, boost::forward<F>(func) + ))); #ifdef BOOST_THREAD_PROVIDES_EXECUTORS } else if (underlying_cast<int>(policy) & int(launch::executor)) { typedef executor Ex; @@ -4986,7 +5089,7 @@ namespace detail { lock, *this, boost::forward<F>(func) ))); } else { - return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_async_continuation_shared_state<shared_future<R>, future_type>( + return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_sync_continuation_shared_state<shared_future<R>, future_type>( lock, *this, boost::forward<F>(func) ))); } |