git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@135045 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2011-07-13 16:00:50 +00:00
parent 8d75632ad0
commit 22ba71b8ef
2 changed files with 58 additions and 0 deletions

View File

@ -585,8 +585,10 @@ __assoc_state<_R>::set_value(_Arg& __arg)
#endif #endif
{ {
unique_lock<mutex> __lk(this->__mut_); unique_lock<mutex> __lk(this->__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value()) if (this->__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
::new(&__value_) _R(_VSTD::forward<_Arg>(__arg)); ::new(&__value_) _R(_VSTD::forward<_Arg>(__arg));
this->__state_ |= base::__constructed | base::ready; this->__state_ |= base::__constructed | base::ready;
__lk.unlock(); __lk.unlock();
@ -603,8 +605,10 @@ __assoc_state<_R>::set_value_at_thread_exit(_Arg& __arg)
#endif #endif
{ {
unique_lock<mutex> __lk(this->__mut_); unique_lock<mutex> __lk(this->__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value()) if (this->__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
::new(&__value_) _R(_VSTD::forward<_Arg>(__arg)); ::new(&__value_) _R(_VSTD::forward<_Arg>(__arg));
this->__state_ |= base::__constructed; this->__state_ |= base::__constructed;
__thread_local_data()->__make_ready_at_thread_exit(this); __thread_local_data()->__make_ready_at_thread_exit(this);
@ -663,8 +667,10 @@ void
__assoc_state<_R&>::set_value(_R& __arg) __assoc_state<_R&>::set_value(_R& __arg)
{ {
unique_lock<mutex> __lk(this->__mut_); unique_lock<mutex> __lk(this->__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value()) if (this->__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__value_ = &__arg; __value_ = &__arg;
this->__state_ |= base::__constructed | base::ready; this->__state_ |= base::__constructed | base::ready;
__lk.unlock(); __lk.unlock();
@ -676,8 +682,10 @@ void
__assoc_state<_R&>::set_value_at_thread_exit(_R& __arg) __assoc_state<_R&>::set_value_at_thread_exit(_R& __arg)
{ {
unique_lock<mutex> __lk(this->__mut_); unique_lock<mutex> __lk(this->__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value()) if (this->__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__value_ = &__arg; __value_ = &__arg;
this->__state_ |= base::__constructed; this->__state_ |= base::__constructed;
__thread_local_data()->__make_ready_at_thread_exit(this); __thread_local_data()->__make_ready_at_thread_exit(this);
@ -1066,8 +1074,10 @@ template <class _R>
future<_R>::future(__assoc_state<_R>* __state) future<_R>::future(__assoc_state<_R>* __state)
: __state_(__state) : __state_(__state)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_->__has_future_attached()) if (__state_->__has_future_attached())
throw future_error(make_error_code(future_errc::future_already_retrieved)); throw future_error(make_error_code(future_errc::future_already_retrieved));
#endif
__state_->__add_shared(); __state_->__add_shared();
__state_->__set_future_attached(); __state_->__set_future_attached();
} }
@ -1168,8 +1178,10 @@ template <class _R>
future<_R&>::future(__assoc_state<_R&>* __state) future<_R&>::future(__assoc_state<_R&>* __state)
: __state_(__state) : __state_(__state)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_->__has_future_attached()) if (__state_->__has_future_attached())
throw future_error(make_error_code(future_errc::future_already_retrieved)); throw future_error(make_error_code(future_errc::future_already_retrieved));
#endif
__state_->__add_shared(); __state_->__add_shared();
__state_->__set_future_attached(); __state_->__set_future_attached();
} }
@ -1368,8 +1380,10 @@ template <class _R>
future<_R> future<_R>
promise<_R>::get_future() promise<_R>::get_future()
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
return future<_R>(__state_); return future<_R>(__state_);
} }
@ -1377,8 +1391,10 @@ template <class _R>
void void
promise<_R>::set_value(const _R& __r) promise<_R>::set_value(const _R& __r)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value(__r); __state_->set_value(__r);
} }
@ -1388,8 +1404,10 @@ template <class _R>
void void
promise<_R>::set_value(_R&& __r) promise<_R>::set_value(_R&& __r)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value(_VSTD::move(__r)); __state_->set_value(_VSTD::move(__r));
} }
@ -1399,8 +1417,10 @@ template <class _R>
void void
promise<_R>::set_exception(exception_ptr __p) promise<_R>::set_exception(exception_ptr __p)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception(__p); __state_->set_exception(__p);
} }
@ -1408,8 +1428,10 @@ template <class _R>
void void
promise<_R>::set_value_at_thread_exit(const _R& __r) promise<_R>::set_value_at_thread_exit(const _R& __r)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value_at_thread_exit(__r); __state_->set_value_at_thread_exit(__r);
} }
@ -1419,8 +1441,10 @@ template <class _R>
void void
promise<_R>::set_value_at_thread_exit(_R&& __r) promise<_R>::set_value_at_thread_exit(_R&& __r)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value_at_thread_exit(_VSTD::move(__r)); __state_->set_value_at_thread_exit(_VSTD::move(__r));
} }
@ -1430,8 +1454,10 @@ template <class _R>
void void
promise<_R>::set_exception_at_thread_exit(exception_ptr __p) promise<_R>::set_exception_at_thread_exit(exception_ptr __p)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception_at_thread_exit(__p); __state_->set_exception_at_thread_exit(__p);
} }
@ -1527,8 +1553,10 @@ template <class _R>
future<_R&> future<_R&>
promise<_R&>::get_future() promise<_R&>::get_future()
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
return future<_R&>(__state_); return future<_R&>(__state_);
} }
@ -1536,8 +1564,10 @@ template <class _R>
void void
promise<_R&>::set_value(_R& __r) promise<_R&>::set_value(_R& __r)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value(__r); __state_->set_value(__r);
} }
@ -1545,8 +1575,10 @@ template <class _R>
void void
promise<_R&>::set_exception(exception_ptr __p) promise<_R&>::set_exception(exception_ptr __p)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception(__p); __state_->set_exception(__p);
} }
@ -1554,8 +1586,10 @@ template <class _R>
void void
promise<_R&>::set_value_at_thread_exit(_R& __r) promise<_R&>::set_value_at_thread_exit(_R& __r)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value_at_thread_exit(__r); __state_->set_value_at_thread_exit(__r);
} }
@ -1563,8 +1597,10 @@ template <class _R>
void void
promise<_R&>::set_exception_at_thread_exit(exception_ptr __p) promise<_R&>::set_exception_at_thread_exit(exception_ptr __p)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception_at_thread_exit(__p); __state_->set_exception_at_thread_exit(__p);
} }

View File

@ -73,8 +73,10 @@ void
__assoc_sub_state::set_value() __assoc_sub_state::set_value()
{ {
unique_lock<mutex> __lk(__mut_); unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value()) if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__state_ |= __constructed | ready; __state_ |= __constructed | ready;
__lk.unlock(); __lk.unlock();
__cv_.notify_all(); __cv_.notify_all();
@ -84,8 +86,10 @@ void
__assoc_sub_state::set_value_at_thread_exit() __assoc_sub_state::set_value_at_thread_exit()
{ {
unique_lock<mutex> __lk(__mut_); unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value()) if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__state_ |= __constructed; __state_ |= __constructed;
__thread_local_data()->__make_ready_at_thread_exit(this); __thread_local_data()->__make_ready_at_thread_exit(this);
__lk.unlock(); __lk.unlock();
@ -95,8 +99,10 @@ void
__assoc_sub_state::set_exception(exception_ptr __p) __assoc_sub_state::set_exception(exception_ptr __p)
{ {
unique_lock<mutex> __lk(__mut_); unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value()) if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__exception_ = __p; __exception_ = __p;
__state_ |= ready; __state_ |= ready;
__lk.unlock(); __lk.unlock();
@ -107,8 +113,10 @@ void
__assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p) __assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p)
{ {
unique_lock<mutex> __lk(__mut_); unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value()) if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied)); throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__exception_ = __p; __exception_ = __p;
__thread_local_data()->__make_ready_at_thread_exit(this); __thread_local_data()->__make_ready_at_thread_exit(this);
__lk.unlock(); __lk.unlock();
@ -159,14 +167,18 @@ __assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk)
void void
__assoc_sub_state::__execute() __assoc_sub_state::__execute()
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
} }
future<void>::future(__assoc_sub_state* __state) future<void>::future(__assoc_sub_state* __state)
: __state_(__state) : __state_(__state)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_->__has_future_attached()) if (__state_->__has_future_attached())
throw future_error(make_error_code(future_errc::future_already_retrieved)); throw future_error(make_error_code(future_errc::future_already_retrieved));
#endif
__state_->__add_shared(); __state_->__add_shared();
__state_->__set_future_attached(); __state_->__set_future_attached();
} }
@ -206,40 +218,50 @@ promise<void>::~promise()
future<void> future<void>
promise<void>::get_future() promise<void>::get_future()
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
return future<void>(__state_); return future<void>(__state_);
} }
void void
promise<void>::set_value() promise<void>::set_value()
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value(); __state_->set_value();
} }
void void
promise<void>::set_exception(exception_ptr __p) promise<void>::set_exception(exception_ptr __p)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception(__p); __state_->set_exception(__p);
} }
void void
promise<void>::set_value_at_thread_exit() promise<void>::set_value_at_thread_exit()
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value_at_thread_exit(); __state_->set_value_at_thread_exit();
} }
void void
promise<void>::set_exception_at_thread_exit(exception_ptr __p) promise<void>::set_exception_at_thread_exit(exception_ptr __p)
{ {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr) if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state)); throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception_at_thread_exit(__p); __state_->set_exception_at_thread_exit(__p);
} }