diff --git a/libcxx/include/future b/libcxx/include/future index be975f48841d..f51ccb90316f 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -27,9 +27,9 @@ enum class future_errc enum class launch { - any, - async, - sync + async = 1, + deferred = 2, + any = async | deferred }; enum class future_status @@ -470,9 +470,9 @@ struct _LIBCPP_VISIBLE is_error_code_enum : public true_type {}; struct _LIBCPP_VISIBLE launch { enum _ { - any, - async, - sync + async = 1, + deferred = 2, + any = async | deferred }; _ __v_; @@ -2111,16 +2111,16 @@ async(launch __policy, _F&& __f, _Args&&... __args) { typedef typename result_of<_F(_Args...)>::type _R; future<_R> __r; - if (__policy == launch::sync) - __r = _STD::__make_deferred_assoc_state<_R>(bind(_STD::forward<_F>(__f), - _STD::forward<_Args>(__args)...)); - else + if (__policy & launch::async) { packaged_task<_R()> __pk(bind(_STD::forward<_F>(__f), _STD::forward<_Args>(__args)...)); __r = __pk.get_future(); thread(_STD::move(__pk)).detach(); } + else if (__policy & launch::deferred) + __r = _STD::__make_deferred_assoc_state<_R>(bind(_STD::forward<_F>(__f), + _STD::forward<_Args>(__args)...)); return __r; } diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 7cfdbf388ad0..a1e00d542778 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -1395,7 +1395,7 @@ public: }; template -struct __result_of_mp; +struct __result_of_mp {}; // member function pointer diff --git a/libcxx/test/thread/futures/futures.async/async.pass.cpp b/libcxx/test/thread/futures/futures.async/async.pass.cpp index 16565e7e6055..697eb089c626 100644 --- a/libcxx/test/thread/futures/futures.async/async.pass.cpp +++ b/libcxx/test/thread/futures/futures.async/async.pass.cpp @@ -82,7 +82,7 @@ int main() assert(t1-t0 < ms(100)); } { - std::future f = std::async(std::launch::sync, f0); + std::future f = std::async(std::launch::deferred, f0); std::this_thread::sleep_for(ms(300)); Clock::time_point t0 = Clock::now(); assert(f.get() == 3); @@ -115,7 +115,7 @@ int main() assert(t1-t0 < ms(100)); } { - std::future f = std::async(std::launch::sync, f1); + std::future f = std::async(std::launch::deferred, f1); std::this_thread::sleep_for(ms(300)); Clock::time_point t0 = Clock::now(); assert(&f.get() == &i); @@ -148,7 +148,7 @@ int main() assert(t1-t0 < ms(100)); } { - std::future f = std::async(std::launch::sync, f2); + std::future f = std::async(std::launch::deferred, f2); std::this_thread::sleep_for(ms(300)); Clock::time_point t0 = Clock::now(); f.get(); diff --git a/libcxx/test/thread/futures/futures.overview/launch.pass.cpp b/libcxx/test/thread/futures/futures.overview/launch.pass.cpp index 1e6a92fc23df..63eebe9f2d7f 100644 --- a/libcxx/test/thread/futures/futures.overview/launch.pass.cpp +++ b/libcxx/test/thread/futures/futures.overview/launch.pass.cpp @@ -11,16 +11,16 @@ // enum class launch // { -// any, -// async, -// sync +// async = 1, +// deferred = 2, +// any = async | deferred // }; #include int main() { - static_assert(std::launch::any == 0, ""); + static_assert(std::launch::any == std::launch::async | std::launch::deferred, ""); static_assert(std::launch::async == 1, ""); - static_assert(std::launch::sync == 2, ""); + static_assert(std::launch::deferred == 2, ""); }