diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-08-30 18:46:21 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-08-30 18:46:21 +0000 |
commit | 54da338f59b56e267dd6d1c0981e3c607c94c2b7 (patch) | |
tree | 90e23190ed3a4b395a2f215baea6267f2f905d87 /src/future.cpp | |
parent | 7158e5c38b300b7950ad908977b33d737cffb7ff (diff) |
[futures.task] and [futures.async]. Requires variadics and rvalue-ref support.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@112500 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'src/future.cpp')
-rw-r--r-- | src/future.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/future.cpp b/src/future.cpp index 82b9b60ee..a00827671 100644 --- a/src/future.cpp +++ b/src/future.cpp @@ -124,18 +124,39 @@ void __assoc_sub_state::copy() { unique_lock<mutex> __lk(__mut_); - while (!__is_ready()) - __cv_.wait(__lk); + __sub_wait(__lk); if (__exception_ != nullptr) rethrow_exception(__exception_); } void -__assoc_sub_state::wait() const +__assoc_sub_state::wait() { unique_lock<mutex> __lk(__mut_); - while (!__is_ready()) - __cv_.wait(__lk); + __sub_wait(__lk); +} + +void +__assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk) +{ + if (!__is_ready()) + { + if (__state_ & deferred) + { + __state_ &= ~deferred; + __lk.unlock(); + __execute(); + } + else + while (!__is_ready()) + __cv_.wait(__lk); + } +} + +void +__assoc_sub_state::__execute() +{ + throw future_error(make_error_code(future_errc::no_state)); } future<void>::future(__assoc_sub_state* __state) @@ -144,6 +165,7 @@ future<void>::future(__assoc_sub_state* __state) if (__state_->__has_future_attached()) throw future_error(make_error_code(future_errc::future_already_retrieved)); __state_->__add_shared(); + __state_->__set_future_attached(); } future<void>::~future() @@ -155,9 +177,10 @@ future<void>::~future() void future<void>::get() { + unique_ptr<__shared_count, __release_shared_count> __(__state_); __assoc_sub_state* __s = __state_; __state_ = nullptr; - return __s->copy(); + __s->copy(); } promise<void>::promise() |