diff options
Diffstat (limited to 'system/include/libcxx/future')
-rw-r--r-- | system/include/libcxx/future | 122 |
1 files changed, 83 insertions, 39 deletions
diff --git a/system/include/libcxx/future b/system/include/libcxx/future index dae1a4b8..73d5456d 100644 --- a/system/include/libcxx/future +++ b/system/include/libcxx/future @@ -19,10 +19,10 @@ namespace std enum class future_errc { - broken_promise, - future_already_retrieved, + future_already_retrieved = 1, promise_already_satisfied, - no_state + no_state, + broken_promise }; enum class launch @@ -309,11 +309,11 @@ public: }; template <class F, class... Args> - future<typename result_of<F(Args...)>::type> + future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> async(F&& f, Args&&... args); template <class F, class... Args> - future<typename result_of<F(Args...)>::type> + future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> async(launch policy, F&& f, Args&&... args); template <class> class packaged_task; // undefined @@ -379,19 +379,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD //enum class future_errc _LIBCPP_DECLARE_STRONG_ENUM(future_errc) { - broken_promise, - future_already_retrieved, + future_already_retrieved = 1, promise_already_satisfied, - no_state + no_state, + broken_promise }; _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc) template <> -struct _LIBCPP_TYPE_VIS is_error_code_enum<future_errc> : public true_type {}; +struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc> : public true_type {}; #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS template <> -struct _LIBCPP_TYPE_VIS is_error_code_enum<future_errc::__lx> : public true_type { }; +struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc::__lx> : public true_type { }; #endif //enum class launch @@ -508,7 +508,7 @@ public: virtual ~future_error() _NOEXCEPT; }; -class __assoc_sub_state +class _LIBCPP_TYPE_VIS __assoc_sub_state : public __shared_count { protected: @@ -542,14 +542,14 @@ public: __state_ |= __future_attached; } _LIBCPP_INLINE_VISIBILITY - bool __has_future_attached() const {return __state_ & __future_attached;} + bool __has_future_attached() const {return (__state_ & __future_attached) != 0;} _LIBCPP_INLINE_VISIBILITY void __set_deferred() {__state_ |= deferred;} void __make_ready(); _LIBCPP_INLINE_VISIBILITY - bool __is_ready() const {return __state_ & ready;} + bool __is_ready() const {return (__state_ & ready) != 0;} void set_value(); void set_value_at_thread_exit(); @@ -727,7 +727,7 @@ __assoc_state<_Rp&>::set_value(_Rp& __arg) if (this->__has_value()) throw future_error(make_error_code(future_errc::promise_already_satisfied)); #endif - __value_ = &__arg; + __value_ = _VSTD::addressof(__arg); this->__state_ |= base::__constructed | base::ready; __lk.unlock(); __cv_.notify_all(); @@ -742,7 +742,7 @@ __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg) if (this->__has_value()) throw future_error(make_error_code(future_errc::promise_already_satisfied)); #endif - __value_ = &__arg; + __value_ = _VSTD::addressof(__arg); this->__state_ |= base::__constructed; __thread_local_data()->__make_ready_at_thread_exit(this); __lk.unlock(); @@ -778,7 +778,7 @@ void __assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT { if (this->__state_ & base::__constructed) - reinterpret_cast<_Rp*>(&this->__value_)->~_Rp(); + reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp(); typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_); this->~__assoc_state_alloc(); __a.deallocate(this, 1); @@ -1032,12 +1032,12 @@ __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT base::__on_zero_shared(); } -template <class _Rp> class _LIBCPP_TYPE_VIS promise; -template <class _Rp> class _LIBCPP_TYPE_VIS shared_future; +template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY promise; +template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY shared_future; // future -template <class _Rp> class _LIBCPP_TYPE_VIS future; +template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY future; template <class _Rp, class _Fp> future<_Rp> @@ -1056,7 +1056,7 @@ __make_async_assoc_state(_Fp __f); #endif template <class _Rp> -class _LIBCPP_TYPE_VIS future +class _LIBCPP_TYPE_VIS_ONLY future { __assoc_state<_Rp>* __state_; @@ -1160,7 +1160,7 @@ future<_Rp>::get() } template <class _Rp> -class _LIBCPP_TYPE_VIS future<_Rp&> +class _LIBCPP_TYPE_VIS_ONLY future<_Rp&> { __assoc_state<_Rp&>* __state_; @@ -1341,7 +1341,7 @@ swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT template <class _Callable> class packaged_task; template <class _Rp> -class _LIBCPP_TYPE_VIS promise +class _LIBCPP_TYPE_VIS_ONLY promise { __assoc_state<_Rp>* __state_; @@ -1519,7 +1519,7 @@ promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) // promise<R&> template <class _Rp> -class _LIBCPP_TYPE_VIS promise<_Rp&> +class _LIBCPP_TYPE_VIS_ONLY promise<_Rp&> { __assoc_state<_Rp&>* __state_; @@ -1736,7 +1736,7 @@ swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT } template <class _Rp, class _Alloc> - struct _LIBCPP_TYPE_VIS uses_allocator<promise<_Rp>, _Alloc> + struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<promise<_Rp>, _Alloc> : public true_type {}; #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -2000,7 +2000,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) cons } template<class _Rp, class ..._ArgTypes> -class _LIBCPP_TYPE_VIS packaged_task<_Rp(_ArgTypes...)> +class _LIBCPP_TYPE_VIS_ONLY packaged_task<_Rp(_ArgTypes...)> { public: typedef _Rp result_type; @@ -2013,10 +2013,26 @@ public: // construction and destruction _LIBCPP_INLINE_VISIBILITY packaged_task() _NOEXCEPT : __p_(nullptr) {} - template <class _Fp> + template <class _Fp, + class = typename enable_if + < + !is_same< + typename decay<_Fp>::type, + packaged_task + >::value + >::type + > _LIBCPP_INLINE_VISIBILITY explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} - template <class _Fp, class _Allocator> + template <class _Fp, class _Allocator, + class = typename enable_if + < + !is_same< + typename decay<_Fp>::type, + packaged_task + >::value + >::type + > _LIBCPP_INLINE_VISIBILITY explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), @@ -2115,7 +2131,7 @@ packaged_task<_Rp(_ArgTypes...)>::reset() } template<class ..._ArgTypes> -class _LIBCPP_TYPE_VIS packaged_task<void(_ArgTypes...)> +class _LIBCPP_TYPE_VIS_ONLY packaged_task<void(_ArgTypes...)> { public: typedef void result_type; @@ -2128,10 +2144,26 @@ public: // construction and destruction _LIBCPP_INLINE_VISIBILITY packaged_task() _NOEXCEPT : __p_(nullptr) {} - template <class _Fp> + template <class _Fp, + class = typename enable_if + < + !is_same< + typename decay<_Fp>::type, + packaged_task + >::value + >::type + > _LIBCPP_INLINE_VISIBILITY explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} - template <class _Fp, class _Allocator> + template <class _Fp, class _Allocator, + class = typename enable_if + < + !is_same< + typename decay<_Fp>::type, + packaged_task + >::value + >::type + > _LIBCPP_INLINE_VISIBILITY explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), @@ -2240,7 +2272,7 @@ swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT } template <class _Callable, class _Alloc> -struct _LIBCPP_TYPE_VIS uses_allocator<packaged_task<_Callable>, _Alloc> +struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<packaged_task<_Callable>, _Alloc> : public true_type {}; template <class _Rp, class _Fp> @@ -2299,20 +2331,32 @@ private: } }; +inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value ) +{ return (int(__policy) & int(__value)) != 0; } + template <class _Fp, class... _Args> future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> async(launch __policy, _Fp&& __f, _Args&&... __args) { typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF; typedef typename _BF::_Rp _Rp; - future<_Rp> __r; - if (int(__policy) & int(launch::async)) - __r = _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), + +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + if (__does_policy_contain(__policy, launch::async)) + return _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), __decay_copy(_VSTD::forward<_Args>(__args))...)); - else if (int(__policy) & int(launch::deferred)) - __r = _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch ( ... ) { if (__policy == launch::async) throw ; } +#endif + + if (__does_policy_contain(__policy, launch::deferred)) + return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), __decay_copy(_VSTD::forward<_Args>(__args))...)); - return __r; + return future<_Rp>{}; } template <class _Fp, class... _Args> @@ -2329,7 +2373,7 @@ async(_Fp&& __f, _Args&&... __args) // shared_future template <class _Rp> -class _LIBCPP_TYPE_VIS shared_future +class _LIBCPP_TYPE_VIS_ONLY shared_future { __assoc_state<_Rp>* __state_; @@ -2403,7 +2447,7 @@ shared_future<_Rp>::operator=(const shared_future& __rhs) } template <class _Rp> -class _LIBCPP_TYPE_VIS shared_future<_Rp&> +class _LIBCPP_TYPE_VIS_ONLY shared_future<_Rp&> { __assoc_state<_Rp&>* __state_; |