diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2013-11-03 15:43:35 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2013-11-03 15:43:35 +0000 |
commit | b1915875d09641045c8f48ce6210ec0481958647 (patch) | |
tree | 1789ddba1a1e022cc438a123d39fc1b432f1dd74 /libcxx/include/future | |
parent | dacddb0bab810aeb970271214a1879c98eef1b95 (diff) | |
download | bcm5719-llvm-b1915875d09641045c8f48ce6210ec0481958647.tar.gz bcm5719-llvm-b1915875d09641045c8f48ce6210ec0481958647.zip |
Fix LWG Issue 2078. Make std::async(policy,...) try multiple policies until one succeeds.
llvm-svn: 193960
Diffstat (limited to 'libcxx/include/future')
-rw-r--r-- | libcxx/include/future | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/libcxx/include/future b/libcxx/include/future index ff8e59b17a9..7561d190f41 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -2331,20 +2331,32 @@ private: } }; +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> |