N3188 - Revision to N3113: Async Launch Policies (CH 36)

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@120027 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2010-11-23 18:33:54 +00:00
parent f8f852138f
commit 6689564040
4 changed files with 19 additions and 19 deletions

View File

@@ -27,9 +27,9 @@ enum class future_errc
enum class launch enum class launch
{ {
any, async = 1,
async, deferred = 2,
sync any = async | deferred
}; };
enum class future_status enum class future_status
@@ -470,9 +470,9 @@ struct _LIBCPP_VISIBLE is_error_code_enum<future_errc> : public true_type {};
struct _LIBCPP_VISIBLE launch struct _LIBCPP_VISIBLE launch
{ {
enum _ { enum _ {
any, async = 1,
async, deferred = 2,
sync any = async | deferred
}; };
_ __v_; _ __v_;
@@ -2111,16 +2111,16 @@ async(launch __policy, _F&& __f, _Args&&... __args)
{ {
typedef typename result_of<_F(_Args...)>::type _R; typedef typename result_of<_F(_Args...)>::type _R;
future<_R> __r; future<_R> __r;
if (__policy == launch::sync) if (__policy & launch::async)
__r = _STD::__make_deferred_assoc_state<_R>(bind(_STD::forward<_F>(__f),
_STD::forward<_Args>(__args)...));
else
{ {
packaged_task<_R()> __pk(bind(_STD::forward<_F>(__f), packaged_task<_R()> __pk(bind(_STD::forward<_F>(__f),
_STD::forward<_Args>(__args)...)); _STD::forward<_Args>(__args)...));
__r = __pk.get_future(); __r = __pk.get_future();
thread(_STD::move(__pk)).detach(); 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; return __r;
} }

View File

@@ -1395,7 +1395,7 @@ public:
}; };
template <class _MP, class _Tp, class ..._Args> template <class _MP, class _Tp, class ..._Args>
struct __result_of_mp; struct __result_of_mp {};
// member function pointer // member function pointer

View File

@@ -82,7 +82,7 @@ int main()
assert(t1-t0 < ms(100)); assert(t1-t0 < ms(100));
} }
{ {
std::future<int> f = std::async(std::launch::sync, f0); std::future<int> f = std::async(std::launch::deferred, f0);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now(); Clock::time_point t0 = Clock::now();
assert(f.get() == 3); assert(f.get() == 3);
@@ -115,7 +115,7 @@ int main()
assert(t1-t0 < ms(100)); assert(t1-t0 < ms(100));
} }
{ {
std::future<int&> f = std::async(std::launch::sync, f1); std::future<int&> f = std::async(std::launch::deferred, f1);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now(); Clock::time_point t0 = Clock::now();
assert(&f.get() == &i); assert(&f.get() == &i);
@@ -148,7 +148,7 @@ int main()
assert(t1-t0 < ms(100)); assert(t1-t0 < ms(100));
} }
{ {
std::future<void> f = std::async(std::launch::sync, f2); std::future<void> f = std::async(std::launch::deferred, f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now(); Clock::time_point t0 = Clock::now();
f.get(); f.get();

View File

@@ -11,16 +11,16 @@
// enum class launch // enum class launch
// { // {
// any, // async = 1,
// async, // deferred = 2,
// sync // any = async | deferred
// }; // };
#include <future> #include <future>
int main() 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::async == 1, "");
static_assert(std::launch::sync == 2, ""); static_assert(std::launch::deferred == 2, "");
} }