From 7de47902d08e6cd08977b573b134f21b5782fc4b Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 30 Nov 2010 20:23:32 +0000 Subject: [PATCH] Implemented N3194 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@120458 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/future | 316 ++---------------- src/future.cpp | 35 -- .../copy_assign.pass.cpp | 74 ---- .../futures.atomic_future/copy_ctor.pass.cpp | 66 ---- .../futures.atomic_future/default.pass.cpp | 33 -- .../futures.atomic_future/dtor.pass.cpp | 66 ---- .../futures.atomic_future/get.pass.cpp | 143 -------- .../futures.atomic_future/wait.pass.cpp | 86 ----- .../futures.atomic_future/wait_for.pass.cpp | 95 ------ .../futures.atomic_future/wait_until.pass.cpp | 95 ------ .../futures.task.members/assign_copy.fail.cpp | 8 +- .../futures.task.members/assign_move.pass.cpp | 8 +- .../futures.task.members/ctor_copy.fail.cpp | 8 +- .../ctor_default.pass.cpp | 2 +- .../futures.task.members/ctor_func.pass.cpp | 4 +- .../ctor_func_alloc.pass.cpp | 4 +- .../futures.task.members/ctor_move.pass.cpp | 8 +- .../futures.task.members/swap.pass.cpp | 8 +- .../futures.task.nonmembers/swap.pass.cpp | 8 +- .../share.pass.cpp} | 16 +- 20 files changed, 62 insertions(+), 1021 deletions(-) delete mode 100644 test/thread/futures/futures.atomic_future/copy_assign.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/copy_ctor.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/default.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/dtor.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/get.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/wait.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/wait_for.pass.cpp delete mode 100644 test/thread/futures/futures.atomic_future/wait_until.pass.cpp rename test/thread/futures/{futures.atomic_future/ctor_future.pass.cpp => futures.unique_future/share.pass.cpp} (76%) diff --git a/include/future b/include/future index f51ccb90..73a6391e 100644 --- a/include/future +++ b/include/future @@ -156,6 +156,7 @@ public: ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&); + shared_future share() &&; // retrieving the value R get(); @@ -182,6 +183,7 @@ public: ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&); + shared_future share() &&; // retrieving the value R& get(); @@ -208,6 +210,7 @@ public: ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&); + shared_future share() &&; // retrieving the value void get(); @@ -305,81 +308,6 @@ public: wait_until(const chrono::time_point& abs_time) const; }; -template -class atomic_future -{ -public: - atomic_future(); - atomic_future(const atomic_future& rhs); - atomic_future(future&&); - ~atomic_future(); - atomic_future& operator=(const atomic_future& rhs); - - // retrieving the value - const R& get() const; - - // functions to check state - bool valid() const; - - void wait() const; - template - future_status - wait_for(const chrono::duration& rel_time) const; - template - future_status - wait_until(const chrono::time_point& abs_time) const; -}; - -template -class atomic_future -{ -public: - atomic_future(); - atomic_future(const atomic_future& rhs); - atomic_future(future&&); - ~atomic_future(); - atomic_future& operator=(const atomic_future& rhs); - - // retrieving the value - R& get() const; - - // functions to check state - bool valid() const; - - void wait() const; - template - future_status - wait_for(const chrono::duration& rel_time) const; - template - future_status - wait_until(const chrono::time_point& abs_time) const; -}; - -template <> -class atomic_future -{ -public: - atomic_future(); - atomic_future(const atomic_future& rhs); - atomic_future(future&&); - ~atomic_future(); - atomic_future& operator=(const atomic_future& rhs); - - // retrieving the value - void get() const; - - // functions to check state - bool valid() const; - - void wait() const; - template - future_status - wait_for(const chrono::duration& rel_time) const; - template - future_status - wait_until(const chrono::time_point& abs_time) const; -}; - template future::type> async(F&& f, Args&&... args); @@ -413,7 +341,7 @@ public: packaged_task& operator=(packaged_task&& other); void swap(packaged_task& other); - explicit operator bool() const; + bool valid() const; // result retrieval future get_future(); @@ -986,6 +914,7 @@ private: public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); + shared_future<_R> share(); // retrieving the value _R get(); @@ -1083,6 +1012,7 @@ private: public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); + shared_future<_R&> share(); // retrieving the value _R& get(); @@ -1175,6 +1105,7 @@ private: public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); + shared_future share(); // retrieving the value void get(); @@ -1893,8 +1824,7 @@ public: } _LIBCPP_INLINE_VISIBILITY - //explicit - operator bool() const {return __p_.__state_ != nullptr;} + bool valid() const {return __p_.__state_ != nullptr;} // result retrieval _LIBCPP_INLINE_VISIBILITY @@ -1956,7 +1886,7 @@ void packaged_task<_R(_ArgTypes...)>::reset() { #ifndef _LIBCPP_NO_EXCEPTIONS - if (!(*this)) + if (!valid()) throw future_error(make_error_code(future_errc::no_state)); #endif // _LIBCPP_NO_EXCEPTIONS __p_ = promise(); @@ -2009,8 +1939,7 @@ public: } _LIBCPP_INLINE_VISIBILITY - //explicit - operator bool() const {return __p_.__state_ != nullptr;} + bool valid() const {return __p_.__state_ != nullptr;} // result retrieval _LIBCPP_INLINE_VISIBILITY @@ -2074,7 +2003,7 @@ void packaged_task::reset() { #ifndef _LIBCPP_NO_EXCEPTIONS - if (!(*this)) + if (!valid()) throw future_error(make_error_code(future_errc::no_state)); #endif // _LIBCPP_NO_EXCEPTIONS __p_ = promise(); @@ -2352,222 +2281,27 @@ swap(shared_future<_R>& __x, shared_future<_R>& __y) __x.swap(__y); } -// atomic_future - template -class _LIBCPP_VISIBLE atomic_future +inline _LIBCPP_INLINE_VISIBILITY +shared_future<_R> +future<_R>::share() { - __assoc_state<_R>* __state_; - mutable mutex __mut_; - -public: - _LIBCPP_INLINE_VISIBILITY - atomic_future() : __state_(nullptr) {} - _LIBCPP_INLINE_VISIBILITY - atomic_future(const atomic_future& __rhs) : __state_(__rhs.__state_) - {if (__state_) __state_->__add_shared();} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - atomic_future(future<_R>&& __f) : __state_(__f.__state_) - {__f.__state_ = nullptr;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - ~atomic_future(); - atomic_future& operator=(const atomic_future& __rhs); - - // retrieving the value - _LIBCPP_INLINE_VISIBILITY - const _R& get() const {return __state_->copy();} - - void swap(atomic_future& __rhs); - - // functions to check state - _LIBCPP_INLINE_VISIBILITY - bool valid() const {return __state_ != nullptr;} - - _LIBCPP_INLINE_VISIBILITY - void wait() const {__state_->wait();} - template - _LIBCPP_INLINE_VISIBILITY - future_status - wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const - {return __state_->wait_for(__rel_time);} - template - _LIBCPP_INLINE_VISIBILITY - future_status - wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const - {return __state_->wait_until(__abs_time);} -}; - -template -atomic_future<_R>::~atomic_future() -{ - if (__state_) - __state_->__release_shared(); + return shared_future<_R>(_STD::move(*this)); } -template -atomic_future<_R>& -atomic_future<_R>::operator=(const atomic_future& __rhs) -{ - if (this != &__rhs) - { - unique_lock __this(__mut_, defer_lock); - unique_lock __that(__rhs.__mut_, defer_lock); - _STD::lock(__this, __that); - if (__rhs.__state_) - __rhs.__state_->__add_shared(); - if (__state_) - __state_->__release_shared(); - __state_ = __rhs.__state_; - } - return *this; -} - -template -void -atomic_future<_R>::swap(atomic_future& __rhs) -{ - if (this != &__rhs) - { - unique_lock __this(__mut_, defer_lock); - unique_lock __that(__rhs.__mut_, defer_lock); - _STD::lock(__this, __that); - _STD::swap(__state_, __rhs.__state_); - } -} - -template -class _LIBCPP_VISIBLE atomic_future<_R&> -{ - __assoc_state<_R&>* __state_; - mutable mutex __mut_; - -public: - _LIBCPP_INLINE_VISIBILITY - atomic_future() : __state_(nullptr) {} - _LIBCPP_INLINE_VISIBILITY - atomic_future(const atomic_future& __rhs) : __state_(__rhs.__state_) - {if (__state_) __state_->__add_shared();} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - atomic_future(future<_R&>&& __f) : __state_(__f.__state_) - {__f.__state_ = nullptr;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - ~atomic_future(); - atomic_future& operator=(const atomic_future& __rhs); - - // retrieving the value - _LIBCPP_INLINE_VISIBILITY - _R& get() const {return __state_->copy();} - - void swap(atomic_future& __rhs); - - // functions to check state - _LIBCPP_INLINE_VISIBILITY - bool valid() const {return __state_ != nullptr;} - - _LIBCPP_INLINE_VISIBILITY - void wait() const {__state_->wait();} - template - _LIBCPP_INLINE_VISIBILITY - future_status - wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const - {return __state_->wait_for(__rel_time);} - template - _LIBCPP_INLINE_VISIBILITY - future_status - wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const - {return __state_->wait_until(__abs_time);} -}; - -template -atomic_future<_R&>::~atomic_future() -{ - if (__state_) - __state_->__release_shared(); -} - -template -atomic_future<_R&>& -atomic_future<_R&>::operator=(const atomic_future& __rhs) -{ - if (this != &__rhs) - { - unique_lock __this(__mut_, defer_lock); - unique_lock __that(__rhs.__mut_, defer_lock); - _STD::lock(__this, __that); - if (__rhs.__state_) - __rhs.__state_->__add_shared(); - if (__state_) - __state_->__release_shared(); - __state_ = __rhs.__state_; - } - return *this; -} - -template -void -atomic_future<_R&>::swap(atomic_future& __rhs) -{ - if (this != &__rhs) - { - unique_lock __this(__mut_, defer_lock); - unique_lock __that(__rhs.__mut_, defer_lock); - _STD::lock(__this, __that); - _STD::swap(__state_, __rhs.__state_); - } -} - -template <> -class _LIBCPP_VISIBLE atomic_future -{ - __assoc_sub_state* __state_; - mutable mutex __mut_; - -public: - _LIBCPP_INLINE_VISIBILITY - atomic_future() : __state_(nullptr) {} - _LIBCPP_INLINE_VISIBILITY - atomic_future(const atomic_future& __rhs) : __state_(__rhs.__state_) - {if (__state_) __state_->__add_shared();} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - atomic_future(future&& __f) : __state_(__f.__state_) - {__f.__state_ = nullptr;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - ~atomic_future(); - atomic_future& operator=(const atomic_future& __rhs); - - // retrieving the value - _LIBCPP_INLINE_VISIBILITY - void get() const {__state_->copy();} - - void swap(atomic_future& __rhs); - - // functions to check state - _LIBCPP_INLINE_VISIBILITY - bool valid() const {return __state_ != nullptr;} - - _LIBCPP_INLINE_VISIBILITY - void wait() const {__state_->wait();} - template - _LIBCPP_INLINE_VISIBILITY - future_status - wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const - {return __state_->wait_for(__rel_time);} - template - _LIBCPP_INLINE_VISIBILITY - future_status - wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const - {return __state_->wait_until(__abs_time);} -}; - template inline _LIBCPP_INLINE_VISIBILITY -void -swap(atomic_future<_R>& __x, atomic_future<_R>& __y) +shared_future<_R&> +future<_R&>::share() { - __x.swap(__y); + return shared_future<_R&>(_STD::move(*this)); +} + +inline _LIBCPP_INLINE_VISIBILITY +shared_future +future::share() +{ + return shared_future(_STD::move(*this)); } _LIBCPP_END_NAMESPACE_STD diff --git a/src/future.cpp b/src/future.cpp index 30228185..0b8628f3 100644 --- a/src/future.cpp +++ b/src/future.cpp @@ -256,39 +256,4 @@ shared_future::operator=(const shared_future& __rhs) return *this; } -atomic_future::~atomic_future() -{ - if (__state_) - __state_->__release_shared(); -} - -atomic_future& -atomic_future::operator=(const atomic_future& __rhs) -{ - if (this != &__rhs) - { - unique_lock __this(__mut_, defer_lock); - unique_lock __that(__rhs.__mut_, defer_lock); - _STD::lock(__this, __that); - if (__rhs.__state_) - __rhs.__state_->__add_shared(); - if (__state_) - __state_->__release_shared(); - __state_ = __rhs.__state_; - } - return *this; -} - -void -atomic_future::swap(atomic_future& __rhs) -{ - if (this != &__rhs) - { - unique_lock __this(__mut_, defer_lock); - unique_lock __that(__rhs.__mut_, defer_lock); - _STD::lock(__this, __that); - _STD::swap(__state_, __rhs.__state_); - } -} - _LIBCPP_END_NAMESPACE_STD diff --git a/test/thread/futures/futures.atomic_future/copy_assign.pass.cpp b/test/thread/futures/futures.atomic_future/copy_assign.pass.cpp deleted file mode 100644 index 8c3731c6..00000000 --- a/test/thread/futures/futures.atomic_future/copy_assign.pass.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// atomic_future& operator=(const atomic_future& rhs); - -#include -#include - -int main() -{ -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - { - typedef int T; - std::promise p; - std::atomic_future f0 = p.get_future(); - std::atomic_future f; - f = f0; - assert(f0.valid()); - assert(f.valid()); - } - { - typedef int T; - std::atomic_future f0; - std::atomic_future f; - f = f0; - assert(!f0.valid()); - assert(!f.valid()); - } - { - typedef int& T; - std::promise p; - std::atomic_future f0 = p.get_future(); - std::atomic_future f; - f = f0; - assert(f0.valid()); - assert(f.valid()); - } - { - typedef int& T; - std::atomic_future f0; - std::atomic_future f; - f = f0; - assert(!f0.valid()); - assert(!f.valid()); - } - { - typedef void T; - std::promise p; - std::atomic_future f0 = p.get_future(); - std::atomic_future f; - f = f0; - assert(f0.valid()); - assert(f.valid()); - } - { - typedef void T; - std::atomic_future f0; - std::atomic_future f; - f = f0; - assert(!f0.valid()); - assert(!f.valid()); - } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -} diff --git a/test/thread/futures/futures.atomic_future/copy_ctor.pass.cpp b/test/thread/futures/futures.atomic_future/copy_ctor.pass.cpp deleted file mode 100644 index c982153d..00000000 --- a/test/thread/futures/futures.atomic_future/copy_ctor.pass.cpp +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// atomic_future(const atomic_future& rhs); - -#include -#include - -int main() -{ - { - typedef int T; - std::promise p; - std::atomic_future f0 = p.get_future(); - std::atomic_future f = f0; - assert(f0.valid()); - assert(f.valid()); - } - { - typedef int T; - std::atomic_future f0; - std::atomic_future f = f0; - assert(!f0.valid()); - assert(!f.valid()); - } - { - typedef int& T; - std::promise p; - std::atomic_future f0 = p.get_future(); - std::atomic_future f = f0; - assert(f0.valid()); - assert(f.valid()); - } - { - typedef int& T; - std::atomic_future f0; - std::atomic_future f = std::move(f0); - assert(!f0.valid()); - assert(!f.valid()); - } - { - typedef void T; - std::promise p; - std::atomic_future f0 = p.get_future(); - std::atomic_future f = f0; - assert(f0.valid()); - assert(f.valid()); - } - { - typedef void T; - std::atomic_future f0; - std::atomic_future f = f0; - assert(!f0.valid()); - assert(!f.valid()); - } -} diff --git a/test/thread/futures/futures.atomic_future/default.pass.cpp b/test/thread/futures/futures.atomic_future/default.pass.cpp deleted file mode 100644 index 6eec60b0..00000000 --- a/test/thread/futures/futures.atomic_future/default.pass.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// atomic_future(); - -#include -#include - -int main() -{ - { - std::atomic_future f; - assert(!f.valid()); - } - { - std::atomic_future f; - assert(!f.valid()); - } - { - std::atomic_future f; - assert(!f.valid()); - } -} diff --git a/test/thread/futures/futures.atomic_future/dtor.pass.cpp b/test/thread/futures/futures.atomic_future/dtor.pass.cpp deleted file mode 100644 index ea4b5425..00000000 --- a/test/thread/futures/futures.atomic_future/dtor.pass.cpp +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// ~atomic_future(); - -#include -#include - -#include "../test_allocator.h" - -int main() -{ - assert(test_alloc_base::count == 0); - { - typedef int T; - std::atomic_future f; - { - std::promise p(std::allocator_arg, test_allocator()); - assert(test_alloc_base::count == 1); - f = p.get_future(); - assert(test_alloc_base::count == 1); - assert(f.valid()); - } - assert(test_alloc_base::count == 1); - assert(f.valid()); - } - assert(test_alloc_base::count == 0); - { - typedef int& T; - std::atomic_future f; - { - std::promise p(std::allocator_arg, test_allocator()); - assert(test_alloc_base::count == 1); - f = p.get_future(); - assert(test_alloc_base::count == 1); - assert(f.valid()); - } - assert(test_alloc_base::count == 1); - assert(f.valid()); - } - assert(test_alloc_base::count == 0); - { - typedef void T; - std::atomic_future f; - { - std::promise p(std::allocator_arg, test_allocator()); - assert(test_alloc_base::count == 1); - f = p.get_future(); - assert(test_alloc_base::count == 1); - assert(f.valid()); - } - assert(test_alloc_base::count == 1); - assert(f.valid()); - } - assert(test_alloc_base::count == 0); -} diff --git a/test/thread/futures/futures.atomic_future/get.pass.cpp b/test/thread/futures/futures.atomic_future/get.pass.cpp deleted file mode 100644 index 5ca5408f..00000000 --- a/test/thread/futures/futures.atomic_future/get.pass.cpp +++ /dev/null @@ -1,143 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// const R& atomic_future::get(); -// R& atomic_future::get(); -// void atomic_future::get(); - -#include -#include - -void func1(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_value(3); -} - -void func2(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_exception(std::make_exception_ptr(3)); -} - -int j = 0; - -void func3(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - j = 5; - p.set_value(j); -} - -void func4(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_exception(std::make_exception_ptr(3.5)); -} - -void func5(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_value(); -} - -void func6(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_exception(std::make_exception_ptr('c')); -} - -int main() -{ - { - typedef int T; - { - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func1, std::move(p)).detach(); - assert(f.valid()); - assert(f.get() == 3); - assert(f.valid()); - } - { - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func2, std::move(p)).detach(); - try - { - assert(f.valid()); - assert(f.get() == 3); - assert(false); - } - catch (int i) - { - assert(i == 3); - } - assert(f.valid()); - } - } - { - typedef int& T; - { - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func3, std::move(p)).detach(); - assert(f.valid()); - assert(f.get() == 5); - assert(f.valid()); - } - { - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func4, std::move(p)).detach(); - try - { - assert(f.valid()); - assert(f.get() == 3); - assert(false); - } - catch (double i) - { - assert(i == 3.5); - } - assert(f.valid()); - } - } - { - typedef void T; - { - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func5, std::move(p)).detach(); - assert(f.valid()); - f.get(); - assert(f.valid()); - } - { - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func6, std::move(p)).detach(); - try - { - assert(f.valid()); - f.get(); - assert(false); - } - catch (char i) - { - assert(i == 'c'); - } - assert(f.valid()); - } - } -} diff --git a/test/thread/futures/futures.atomic_future/wait.pass.cpp b/test/thread/futures/futures.atomic_future/wait.pass.cpp deleted file mode 100644 index a2e52885..00000000 --- a/test/thread/futures/futures.atomic_future/wait.pass.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// void wait() const; - -#include -#include - -void func1(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_value(3); -} - -int j = 0; - -void func3(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - j = 5; - p.set_value(j); -} - -void func5(std::promise& p) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - p.set_value(); -} - -int main() -{ - typedef std::chrono::high_resolution_clock Clock; - typedef std::chrono::duration ms; - { - typedef int T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func1, std::move(p)).detach(); - assert(f.valid()); - f.wait(); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } - { - typedef int& T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func3, std::move(p)).detach(); - assert(f.valid()); - f.wait(); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } - { - typedef void T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func5, std::move(p)).detach(); - assert(f.valid()); - f.wait(); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } -} diff --git a/test/thread/futures/futures.atomic_future/wait_for.pass.cpp b/test/thread/futures/futures.atomic_future/wait_for.pass.cpp deleted file mode 100644 index ce5407cb..00000000 --- a/test/thread/futures/futures.atomic_future/wait_for.pass.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// template -// future_status -// wait_for(const chrono::duration& rel_time) const; - -#include -#include - -typedef std::chrono::milliseconds ms; - -void func1(std::promise& p) -{ - std::this_thread::sleep_for(ms(500)); - p.set_value(3); -} - -int j = 0; - -void func3(std::promise& p) -{ - std::this_thread::sleep_for(ms(500)); - j = 5; - p.set_value(j); -} - -void func5(std::promise& p) -{ - std::this_thread::sleep_for(ms(500)); - p.set_value(); -} - -int main() -{ - typedef std::chrono::high_resolution_clock Clock; - { - typedef int T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func1, std::move(p)).detach(); - assert(f.valid()); - assert(f.wait_for(ms(300)) == std::future_status::timeout); - assert(f.valid()); - assert(f.wait_for(ms(300)) == std::future_status::ready); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } - { - typedef int& T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func3, std::move(p)).detach(); - assert(f.valid()); - assert(f.wait_for(ms(300)) == std::future_status::timeout); - assert(f.valid()); - assert(f.wait_for(ms(300)) == std::future_status::ready); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } - { - typedef void T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func5, std::move(p)).detach(); - assert(f.valid()); - assert(f.wait_for(ms(300)) == std::future_status::timeout); - assert(f.valid()); - assert(f.wait_for(ms(300)) == std::future_status::ready); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } -} diff --git a/test/thread/futures/futures.atomic_future/wait_until.pass.cpp b/test/thread/futures/futures.atomic_future/wait_until.pass.cpp deleted file mode 100644 index f6e3000a..00000000 --- a/test/thread/futures/futures.atomic_future/wait_until.pass.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class atomic_future - -// template -// future_status -// wait_until(const chrono::time_point& abs_time) const; - -#include -#include - -typedef std::chrono::milliseconds ms; - -void func1(std::promise& p) -{ - std::this_thread::sleep_for(ms(500)); - p.set_value(3); -} - -int j = 0; - -void func3(std::promise& p) -{ - std::this_thread::sleep_for(ms(500)); - j = 5; - p.set_value(j); -} - -void func5(std::promise& p) -{ - std::this_thread::sleep_for(ms(500)); - p.set_value(); -} - -int main() -{ - typedef std::chrono::high_resolution_clock Clock; - { - typedef int T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func1, std::move(p)).detach(); - assert(f.valid()); - assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::timeout); - assert(f.valid()); - assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::ready); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } - { - typedef int& T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func3, std::move(p)).detach(); - assert(f.valid()); - assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::timeout); - assert(f.valid()); - assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::ready); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } - { - typedef void T; - std::promise p; - std::atomic_future f = p.get_future(); - std::thread(func5, std::move(p)).detach(); - assert(f.valid()); - assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::timeout); - assert(f.valid()); - assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::ready); - assert(f.valid()); - Clock::time_point t0 = Clock::now(); - f.wait(); - Clock::time_point t1 = Clock::now(); - assert(f.valid()); - assert(t1-t0 < ms(5)); - } -} diff --git a/test/thread/futures/futures.tas/futures.task.members/assign_copy.fail.cpp b/test/thread/futures/futures.tas/futures.task.members/assign_copy.fail.cpp index 339017b0..70ea0ad3 100644 --- a/test/thread/futures/futures.tas/futures.task.members/assign_copy.fail.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/assign_copy.fail.cpp @@ -32,8 +32,8 @@ int main() std::packaged_task p0(A(5)); std::packaged_task p; p = p0; - assert(!p0); - assert(p); + assert(!p0.valid()); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -42,7 +42,7 @@ int main() std::packaged_task p0; std::packaged_task p; p = p0; - assert(!p0); - assert(!p); + assert(!p0.valid()); + assert(!p.valid()); } } diff --git a/test/thread/futures/futures.tas/futures.task.members/assign_move.pass.cpp b/test/thread/futures/futures.tas/futures.task.members/assign_move.pass.cpp index f3696e53..a0f711aa 100644 --- a/test/thread/futures/futures.tas/futures.task.members/assign_move.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/assign_move.pass.cpp @@ -32,8 +32,8 @@ int main() std::packaged_task p0(A(5)); std::packaged_task p; p = std::move(p0); - assert(!p0); - assert(p); + assert(!p0.valid()); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -42,7 +42,7 @@ int main() std::packaged_task p0; std::packaged_task p; p = std::move(p0); - assert(!p0); - assert(!p); + assert(!p0.valid()); + assert(!p.valid()); } } diff --git a/test/thread/futures/futures.tas/futures.task.members/ctor_copy.fail.cpp b/test/thread/futures/futures.tas/futures.task.members/ctor_copy.fail.cpp index 4ea0a062..9884c49a 100644 --- a/test/thread/futures/futures.tas/futures.task.members/ctor_copy.fail.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/ctor_copy.fail.cpp @@ -31,8 +31,8 @@ int main() { std::packaged_task p0(A(5)); std::packaged_task p(p0); - assert(!p0); - assert(p); + assert(!p0.valid()); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -40,7 +40,7 @@ int main() { std::packaged_task p0; std::packaged_task p(p0); - assert(!p0); - assert(!p); + assert(!p0.valid()); + assert(!p.valid()); } } diff --git a/test/thread/futures/futures.tas/futures.task.members/ctor_default.pass.cpp b/test/thread/futures/futures.tas/futures.task.members/ctor_default.pass.cpp index f78ec85c..f53b26e2 100644 --- a/test/thread/futures/futures.tas/futures.task.members/ctor_default.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/ctor_default.pass.cpp @@ -21,5 +21,5 @@ struct A {}; int main() { std::packaged_task p; - assert(!p); + assert(!p.valid()); } diff --git a/test/thread/futures/futures.tas/futures.task.members/ctor_func.pass.cpp b/test/thread/futures/futures.tas/futures.task.members/ctor_func.pass.cpp index f30cd7b9..8ae59216 100644 --- a/test/thread/futures/futures.tas/futures.task.members/ctor_func.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/ctor_func.pass.cpp @@ -39,7 +39,7 @@ int main() { { std::packaged_task p(A(5)); - assert(p); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -51,7 +51,7 @@ int main() { A a(5); std::packaged_task p(a); - assert(p); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); diff --git a/test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp b/test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp index 2465d83a..63042e8c 100644 --- a/test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp @@ -43,7 +43,7 @@ int main() std::packaged_task p(std::allocator_arg, test_allocator(), A(5)); assert(test_alloc_base::count > 0); - assert(p); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -58,7 +58,7 @@ int main() std::packaged_task p(std::allocator_arg, test_allocator(), a); assert(test_alloc_base::count > 0); - assert(p); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); diff --git a/test/thread/futures/futures.tas/futures.task.members/ctor_move.pass.cpp b/test/thread/futures/futures.tas/futures.task.members/ctor_move.pass.cpp index 62b515ae..c668a678 100644 --- a/test/thread/futures/futures.tas/futures.task.members/ctor_move.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/ctor_move.pass.cpp @@ -31,8 +31,8 @@ int main() { std::packaged_task p0(A(5)); std::packaged_task p = std::move(p0); - assert(!p0); - assert(p); + assert(!p0.valid()); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -40,7 +40,7 @@ int main() { std::packaged_task p0; std::packaged_task p = std::move(p0); - assert(!p0); - assert(!p); + assert(!p0.valid()); + assert(!p.valid()); } } diff --git a/test/thread/futures/futures.tas/futures.task.members/swap.pass.cpp b/test/thread/futures/futures.tas/futures.task.members/swap.pass.cpp index 11378a35..9f549aa3 100644 --- a/test/thread/futures/futures.tas/futures.task.members/swap.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.members/swap.pass.cpp @@ -32,8 +32,8 @@ int main() std::packaged_task p0(A(5)); std::packaged_task p; p.swap(p0); - assert(!p0); - assert(p); + assert(!p0.valid()); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -42,7 +42,7 @@ int main() std::packaged_task p0; std::packaged_task p; p.swap(p0); - assert(!p0); - assert(!p); + assert(!p0.valid()); + assert(!p.valid()); } } diff --git a/test/thread/futures/futures.tas/futures.task.nonmembers/swap.pass.cpp b/test/thread/futures/futures.tas/futures.task.nonmembers/swap.pass.cpp index ae994740..ef99f615 100644 --- a/test/thread/futures/futures.tas/futures.task.nonmembers/swap.pass.cpp +++ b/test/thread/futures/futures.tas/futures.task.nonmembers/swap.pass.cpp @@ -34,8 +34,8 @@ int main() std::packaged_task p0(A(5)); std::packaged_task p; swap(p, p0); - assert(!p0); - assert(p); + assert(!p0.valid()); + assert(p.valid()); std::future f = p.get_future(); p(3, 'a'); assert(f.get() == 105.0); @@ -44,7 +44,7 @@ int main() std::packaged_task p0; std::packaged_task p; swap(p, p0); - assert(!p0); - assert(!p); + assert(!p0.valid()); + assert(!p.valid()); } } diff --git a/test/thread/futures/futures.atomic_future/ctor_future.pass.cpp b/test/thread/futures/futures.unique_future/share.pass.cpp similarity index 76% rename from test/thread/futures/futures.atomic_future/ctor_future.pass.cpp rename to test/thread/futures/futures.unique_future/share.pass.cpp index 443ff755..a19ce2e3 100644 --- a/test/thread/futures/futures.atomic_future/ctor_future.pass.cpp +++ b/test/thread/futures/futures.unique_future/share.pass.cpp @@ -9,9 +9,9 @@ // -// class atomic_future +// class future -// atomic_future(future&& rhs); +// shared_future share() &&; #include #include @@ -22,14 +22,14 @@ int main() typedef int T; std::promise p; std::future f0 = p.get_future(); - std::atomic_future f = std::move(f0); + std::shared_future f = std::move(f0.share()); assert(!f0.valid()); assert(f.valid()); } { typedef int T; std::future f0; - std::atomic_future f = std::move(f0); + std::shared_future f = std::move(f0.share()); assert(!f0.valid()); assert(!f.valid()); } @@ -37,14 +37,14 @@ int main() typedef int& T; std::promise p; std::future f0 = p.get_future(); - std::atomic_future f = std::move(f0); + std::shared_future f = std::move(f0.share()); assert(!f0.valid()); assert(f.valid()); } { typedef int& T; std::future f0; - std::atomic_future f = std::move(f0); + std::shared_future f = std::move(f0.share()); assert(!f0.valid()); assert(!f.valid()); } @@ -52,14 +52,14 @@ int main() typedef void T; std::promise p; std::future f0 = p.get_future(); - std::atomic_future f = std::move(f0); + std::shared_future f = std::move(f0.share()); assert(!f0.valid()); assert(f.valid()); } { typedef void T; std::future f0; - std::atomic_future f = std::move(f0); + std::shared_future f = std::move(f0.share()); assert(!f0.valid()); assert(!f.valid()); }