[libcxx] r246772 - Make a helper routine __throw_future_error, and encapsulate the #ifdef _LIBCPP_NO_EXCEPTIONS there, instead of duplicating it throughout the code. No functionality change
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 3 08:11:32 PDT 2015
Author: marshall
Date: Thu Sep 3 10:11:32 2015
New Revision: 246772
URL: http://llvm.org/viewvc/llvm-project?rev=246772&view=rev
Log:
Make a helper routine __throw_future_error, and encapsulate the #ifdef _LIBCPP_NO_EXCEPTIONS there, instead of duplicating it throughout the code. No functionality change
Modified:
libcxx/trunk/include/future
Modified: libcxx/trunk/include/future
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/future?rev=246772&r1=246771&r2=246772&view=diff
==============================================================================
--- libcxx/trunk/include/future (original)
+++ libcxx/trunk/include/future Thu Sep 3 10:11:32 2015
@@ -512,6 +512,17 @@ public:
virtual ~future_error() _NOEXCEPT;
};
+template <future_errc _Ev>
+_LIBCPP_ALWAYS_INLINE
+void __throw_future_error()
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ throw future_error(make_error_code(_Ev));
+#else
+ assert(!"future_error");
+#endif
+}
+
class _LIBCPP_TYPE_VIS __assoc_sub_state
: public __shared_count
{
@@ -645,10 +656,8 @@ __assoc_state<_Rp>::set_value(_Arg& __ar
#endif
{
unique_lock<mutex> __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+ __throw_future_error<future_errc::promise_already_satisfied>();
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
this->__state_ |= base::__constructed | base::ready;
__cv_.notify_all();
@@ -664,10 +673,8 @@ __assoc_state<_Rp>::set_value_at_thread_
#endif
{
unique_lock<mutex> __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+ __throw_future_error<future_errc::promise_already_satisfied>();
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
this->__state_ |= base::__constructed;
__thread_local_data()->__make_ready_at_thread_exit(this);
@@ -725,10 +732,8 @@ void
__assoc_state<_Rp&>::set_value(_Rp& __arg)
{
unique_lock<mutex> __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+ __throw_future_error<future_errc::promise_already_satisfied>();
__value_ = _VSTD::addressof(__arg);
this->__state_ |= base::__constructed | base::ready;
__cv_.notify_all();
@@ -739,10 +744,8 @@ void
__assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
{
unique_lock<mutex> __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (this->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+ __throw_future_error<future_errc::promise_already_satisfied>();
__value_ = _VSTD::addressof(__arg);
this->__state_ |= base::__constructed;
__thread_local_data()->__make_ready_at_thread_exit(this);
@@ -1138,10 +1141,8 @@ template <class _Rp>
future<_Rp>::future(__assoc_state<_Rp>* __state)
: __state_(__state)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_->__has_future_attached())
- throw future_error(make_error_code(future_errc::future_already_retrieved));
-#endif
+ __throw_future_error<future_errc::future_already_retrieved>();
__state_->__add_shared();
__state_->__set_future_attached();
}
@@ -1242,10 +1243,8 @@ template <class _Rp>
future<_Rp&>::future(__assoc_state<_Rp&>* __state)
: __state_(__state)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_->__has_future_attached())
- throw future_error(make_error_code(future_errc::future_already_retrieved));
-#endif
+ __throw_future_error<future_errc::future_already_retrieved>();
__state_->__add_shared();
__state_->__set_future_attached();
}
@@ -1445,10 +1444,8 @@ template <class _Rp>
future<_Rp>
promise<_Rp>::get_future()
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
return future<_Rp>(__state_);
}
@@ -1456,10 +1453,8 @@ template <class _Rp>
void
promise<_Rp>::set_value(const _Rp& __r)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_value(__r);
}
@@ -1469,10 +1464,8 @@ template <class _Rp>
void
promise<_Rp>::set_value(_Rp&& __r)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_value(_VSTD::move(__r));
}
@@ -1482,10 +1475,8 @@ template <class _Rp>
void
promise<_Rp>::set_exception(exception_ptr __p)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_exception(__p);
}
@@ -1493,10 +1484,8 @@ template <class _Rp>
void
promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_value_at_thread_exit(__r);
}
@@ -1506,10 +1495,8 @@ template <class _Rp>
void
promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_value_at_thread_exit(_VSTD::move(__r));
}
@@ -1519,10 +1506,8 @@ template <class _Rp>
void
promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_exception_at_thread_exit(__p);
}
@@ -1619,10 +1604,8 @@ template <class _Rp>
future<_Rp&>
promise<_Rp&>::get_future()
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
return future<_Rp&>(__state_);
}
@@ -1630,10 +1613,8 @@ template <class _Rp>
void
promise<_Rp&>::set_value(_Rp& __r)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_value(__r);
}
@@ -1641,10 +1622,8 @@ template <class _Rp>
void
promise<_Rp&>::set_exception(exception_ptr __p)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_exception(__p);
}
@@ -1652,10 +1631,8 @@ template <class _Rp>
void
promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_value_at_thread_exit(__r);
}
@@ -1663,10 +1640,8 @@ template <class _Rp>
void
promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
-#endif
+ __throw_future_error<future_errc::no_state>();
__state_->set_exception_at_thread_exit(__p);
}
@@ -2087,11 +2062,11 @@ template<class _Rp, class ..._ArgTypes>
void
packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__p_.__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
+ __throw_future_error<future_errc::no_state>();
if (__p_.__state_->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
+ __throw_future_error<future_errc::promise_already_satisfied>();
+#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -2109,11 +2084,11 @@ template<class _Rp, class ..._ArgTypes>
void
packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__p_.__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
+ __throw_future_error<future_errc::no_state>();
if (__p_.__state_->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
+ __throw_future_error<future_errc::promise_already_satisfied>();
+#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -2131,10 +2106,8 @@ template<class _Rp, class ..._ArgTypes>
void
packaged_task<_Rp(_ArgTypes...)>::reset()
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (!valid())
- throw future_error(make_error_code(future_errc::no_state));
-#endif // _LIBCPP_NO_EXCEPTIONS
+ __throw_future_error<future_errc::no_state>();
__p_ = promise<result_type>();
}
@@ -2218,11 +2191,11 @@ template<class ..._ArgTypes>
void
packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__p_.__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
+ __throw_future_error<future_errc::no_state>();
if (__p_.__state_->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
+ __throw_future_error<future_errc::promise_already_satisfied>();
+#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -2241,11 +2214,11 @@ template<class ..._ArgTypes>
void
packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (__p_.__state_ == nullptr)
- throw future_error(make_error_code(future_errc::no_state));
+ __throw_future_error<future_errc::no_state>();
if (__p_.__state_->__has_value())
- throw future_error(make_error_code(future_errc::promise_already_satisfied));
+ __throw_future_error<future_errc::promise_already_satisfied>();
+#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -2264,10 +2237,8 @@ template<class ..._ArgTypes>
void
packaged_task<void(_ArgTypes...)>::reset()
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
if (!valid())
- throw future_error(make_error_code(future_errc::no_state));
-#endif // _LIBCPP_NO_EXCEPTIONS
+ __throw_future_error<future_errc::no_state>();
__p_ = promise<result_type>();
}
More information about the cfe-commits
mailing list