29 #ifndef _GLIBCXX_FUTURE 30 #define _GLIBCXX_FUTURE 1 32 #pragma GCC system_header 34 #if __cplusplus < 201103L 47 #include <bits/shared_ptr.h> 48 #include <bits/std_function.h> 49 #include <bits/uses_allocator.h> 53 namespace std _GLIBCXX_VISIBILITY(default)
55 _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 future_already_retrieved = 1,
69 promise_already_satisfied,
84 make_error_code(future_errc __errc) noexcept
89 make_error_condition(future_errc __errc) noexcept
107 what()
const noexcept;
110 code()
const noexcept {
return _M_code; }
115 :
logic_error(
"std::future_error: " + __ec.message()), _M_code(__ec)
118 friend void __throw_future_error(
int);
124 template<
typename _Res>
127 template<
typename _Res>
130 template<
typename _Signature>
133 template<
typename _Res>
145 return static_cast<launch>(
146 static_cast<int>(__x) & static_cast<int>(__y));
151 return static_cast<launch>(
152 static_cast<int>(__x) | static_cast<int>(__y));
157 return static_cast<launch>(
158 static_cast<int>(__x) ^ static_cast<int>(__y));
162 {
return static_cast<launch>(~static_cast<
int>(__x)); }
165 {
return __x = __x & __y; }
168 {
return __x = __x | __y; }
171 {
return __x = __x ^ __y; }
183 template<
typename _Fn,
typename... _Args>
184 using __async_result_of =
typename result_of<
185 typename decay<_Fn>::type(
typename decay<_Args>::type...)>::type;
187 template<
typename _Fn,
typename... _Args>
188 future<__async_result_of<_Fn, _Args...>>
189 async(
launch __policy, _Fn&& __fn, _Args&&... __args);
191 template<
typename _Fn,
typename... _Args>
192 future<__async_result_of<_Fn, _Args...>>
193 async(_Fn&& __fn, _Args&&... __args);
195 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ 196 && (ATOMIC_INT_LOCK_FREE > 1) 210 virtual void _M_destroy() = 0;
214 void operator()(
_Result_base* __fr)
const { __fr->_M_destroy(); }
223 template<
typename _Res>
227 template<
typename _Res>
231 __gnu_cxx::__aligned_buffer<_Res> _M_storage;
235 typedef _Res result_type;
237 _Result() noexcept : _M_initialized() { }
247 _M_value() noexcept {
return *_M_storage._M_ptr(); }
250 _M_set(
const _Res& __res)
252 ::new (_M_storage._M_addr()) _Res(__res);
253 _M_initialized =
true;
259 ::new (_M_storage._M_addr()) _Res(std::move(__res));
260 _M_initialized =
true;
264 void _M_destroy() {
delete this; }
268 template<
typename _Res,
typename _Alloc>
271 using __allocator_type = __alloc_rebind<_Alloc, _Result_alloc>;
280 __allocator_type __a(*
this);
287 template<
typename _Res,
typename _Allocator>
289 _S_allocate_result(
const _Allocator& __a)
292 typename __result_type::__allocator_type __a2(__a);
294 __result_type* __p = ::new((
void*)__guard.get()) __result_type{__a};
300 template<
typename _Res,
typename _Tp>
314 enum _Status :
unsigned {
320 __atomic_futex_unsigned<> _M_status;
325 _State_baseV2() noexcept : _M_result(), _M_status(_Status::__not_ready)
327 _State_baseV2(
const _State_baseV2&) =
delete;
328 _State_baseV2& operator=(
const _State_baseV2&) =
delete;
329 virtual ~_State_baseV2() =
default;
338 _M_status._M_load_when_equal(_Status::__ready, memory_order_acquire);
342 template<
typename _Rep,
typename _Period>
348 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
349 return future_status::ready;
350 if (_M_is_deferred_future())
351 return future_status::deferred;
352 if (_M_status._M_load_when_equal_for(_Status::__ready,
353 memory_order_acquire, __rel))
366 return future_status::ready;
368 return future_status::timeout;
371 template<
typename _Clock,
typename _Duration>
377 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
378 return future_status::ready;
379 if (_M_is_deferred_future())
380 return future_status::deferred;
381 if (_M_status._M_load_when_equal_until(_Status::__ready,
382 memory_order_acquire, __abs))
389 return future_status::ready;
391 return future_status::timeout;
397 _M_set_result(
function<_Ptr_type()> __res,
bool __ignore_failure =
false)
399 bool __did_set =
false;
402 call_once(_M_once, &_State_baseV2::_M_do_set,
this,
406 _M_status._M_store_notify_all(_Status::__ready,
407 memory_order_release);
408 else if (!__ignore_failure)
409 __throw_future_error(
int(future_errc::promise_already_satisfied));
416 _M_set_delayed_result(
function<_Ptr_type()> __res,
419 bool __did_set =
false;
423 call_once(_M_once, &_State_baseV2::_M_do_set,
this,
426 __throw_future_error(
int(future_errc::promise_already_satisfied));
427 __mr->_M_shared_state = std::move(__self);
434 _M_break_promise(_Ptr_type __res)
436 if (static_cast<bool>(__res))
444 _M_result.swap(__res);
446 _M_status._M_store_notify_all(_Status::__ready,
447 memory_order_release);
453 _M_set_retrieved_flag()
455 if (_M_retrieved.test_and_set())
456 __throw_future_error(
int(future_errc::future_already_retrieved));
459 template<
typename _Res,
typename _Arg>
463 template<
typename _Res,
typename _Arg>
464 struct _Setter<_Res, _Arg&>
468 static_assert(is_same<_Res, _Arg&>::value
469 || is_same<const _Res, _Arg>::value,
470 "Invalid specialisation");
475 _State_baseV2::_S_check(_M_promise->_M_future);
476 _M_promise->_M_storage->_M_set(*_M_arg);
477 return std::move(_M_promise->_M_storage);
484 template<
typename _Res>
485 struct _Setter<_Res, _Res&&>
490 _State_baseV2::_S_check(_M_promise->_M_future);
491 _M_promise->_M_storage->_M_set(std::move(*_M_arg));
492 return std::move(_M_promise->_M_storage);
498 struct __exception_ptr_tag { };
501 template<
typename _Res>
502 struct _Setter<_Res, __exception_ptr_tag>
507 _State_baseV2::_S_check(_M_promise->_M_future);
508 _M_promise->_M_storage->_M_error = *_M_ex;
509 return std::move(_M_promise->_M_storage);
516 template<
typename _Res,
typename _Arg>
517 static _Setter<_Res, _Arg&&>
523 template<
typename _Res>
524 static _Setter<_Res, __exception_ptr_tag>
527 return _Setter<_Res, __exception_ptr_tag>{ __prom, &__ex };
530 template<
typename _Tp>
534 if (!static_cast<bool>(__p))
535 __throw_future_error((
int)future_errc::no_state);
541 _M_do_set(
function<_Ptr_type()>* __f,
bool* __did_set)
543 _Ptr_type __res = (*__f)();
548 _M_result.
swap(__res);
552 virtual void _M_complete_async() { }
555 virtual bool _M_is_deferred_future()
const {
return false; }
557 struct _Make_ready final : __at_thread_exit_elt
560 static void _S_run(
void*);
565 #ifdef _GLIBCXX_ASYNC_ABI_COMPAT 567 class _Async_state_common;
569 using _State_base = _State_baseV2;
570 class _Async_state_commonV2;
573 template<
typename _BoundFn,
574 typename _Res = decltype(std::declval<_BoundFn&>()())>
575 class _Deferred_state;
577 template<
typename _BoundFn,
578 typename _Res = decltype(std::declval<_BoundFn&>()())>
579 class _Async_state_impl;
581 template<
typename _Signature>
582 class _Task_state_base;
584 template<
typename _Fn,
typename _Alloc,
typename _Signature>
587 template<
typename _BoundFn>
589 _S_make_deferred_state(_BoundFn&& __fn);
591 template<
typename _BoundFn>
593 _S_make_async_state(_BoundFn&& __fn);
595 template<
typename _Res_ptr,
typename _Fn,
596 typename _Res =
typename _Res_ptr::element_type::result_type>
599 template<
typename _Res_ptr,
typename _BoundFn>
600 static _Task_setter<_Res_ptr, _BoundFn>
601 _S_task_setter(_Res_ptr& __ptr, _BoundFn& __call)
608 template<
typename _Res>
611 typedef _Res& result_type;
613 _Result() noexcept : _M_value_ptr() { }
616 _M_set(_Res& __res) noexcept
619 _Res& _M_get() noexcept {
return *_M_value_ptr; }
624 void _M_destroy() {
delete this; }
631 typedef void result_type;
634 void _M_destroy() {
delete this; }
637 #ifndef _GLIBCXX_ASYNC_ABI_COMPAT 640 template<
typename _Res,
typename _Arg>
642 <__future_base::_State_base::_Setter<_Res, _Arg>>
646 template<
typename _Res_ptr,
typename _Fn,
typename _Res>
648 <__future_base::_Task_setter<_Res_ptr, _Fn, _Res>>
652 template<
typename _Res>
660 __state_type _M_state;
668 valid()
const noexcept {
return static_cast<bool>(_M_state); }
673 _State_base::_S_check(_M_state);
677 template<
typename _Rep,
typename _Period>
681 _State_base::_S_check(_M_state);
682 return _M_state->wait_for(__rel);
685 template<
typename _Clock,
typename _Duration>
689 _State_base::_S_check(_M_state);
690 return _M_state->wait_until(__abs);
698 _State_base::_S_check(_M_state);
700 if (!(__res._M_error == 0))
702 return static_cast<__result_type
>(__res);
707 _M_state.swap(__that._M_state);
714 _State_base::_S_check(_M_state);
715 _M_state->_M_set_retrieved_flag();
734 explicit _Reset(
__basic_future& __fut) noexcept : _M_fut(__fut) { }
735 ~_Reset() { _M_fut._M_state.reset(); }
742 template<
typename _Res>
746 template<
typename>
friend class packaged_task;
747 template<
typename _Fn,
typename... _Args>
748 friend future<__async_result_of<_Fn, _Args...>>
755 future(
const __state_type& __state) : _Base_type(__state) { }
758 constexpr
future() noexcept : _Base_type() { }
769 future(std::move(__fut))._M_swap(*
this);
777 typename _Base_type::_Reset __reset(*
this);
778 return std::move(this->_M_get_result()._M_value());
785 template<
typename _Res>
789 template<
typename>
friend class packaged_task;
790 template<
typename _Fn,
typename... _Args>
791 friend future<__async_result_of<_Fn, _Args...>>
798 future(
const __state_type& __state) : _Base_type(__state) { }
801 constexpr
future() noexcept : _Base_type() { }
812 future(std::move(__fut))._M_swap(*
this);
820 typename _Base_type::_Reset __reset(*
this);
821 return this->_M_get_result()._M_get();
832 template<
typename>
friend class packaged_task;
833 template<
typename _Fn,
typename... _Args>
834 friend future<__async_result_of<_Fn, _Args...>>
841 future(
const __state_type& __state) : _Base_type(__state) { }
844 constexpr
future() noexcept : _Base_type() { }
855 future(std::move(__fut))._M_swap(*
this);
863 typename _Base_type::_Reset __reset(*
this);
864 this->_M_get_result();
872 template<
typename _Res>
885 : _Base_type(
std::move(__uf))
890 : _Base_type(
std::move(__sf))
907 get()
const {
return this->_M_get_result()._M_value(); }
911 template<
typename _Res>
924 : _Base_type(
std::move(__uf))
929 : _Base_type(
std::move(__sf))
946 get()
const {
return this->_M_get_result()._M_get(); }
963 : _Base_type(
std::move(__uf))
968 : _Base_type(
std::move(__sf))
985 get()
const { this->_M_get_result(); }
989 template<
typename _Res>
992 : _M_state(__sf._M_state)
995 template<
typename _Res>
998 : _M_state(std::move(__sf._M_state))
1001 template<
typename _Res>
1004 : _M_state(std::move(__uf._M_state))
1009 template<
typename _Res>
1014 template<
typename _Res>
1024 template<
typename _Res>
1027 typedef __future_base::_State_base _State;
1030 template<
typename,
typename>
friend class _State::_Setter;
1033 _Ptr_type _M_storage;
1037 : _M_future(std::make_shared<_State>()),
1038 _M_storage(
new _Res_type())
1042 : _M_future(std::move(__rhs._M_future)),
1043 _M_storage(std::move(__rhs._M_storage))
1046 template<
typename _Allocator>
1048 : _M_future(std::allocate_shared<_State>(__a)),
1049 _M_storage(__future_base::_S_allocate_result<_Res>(__a))
1052 template<
typename _Allocator>
1054 : _M_future(std::move(__rhs._M_future)),
1055 _M_storage(std::move(__rhs._M_storage))
1062 if (static_cast<bool>(_M_future) && !_M_future.unique())
1063 _M_future->_M_break_promise(std::move(_M_storage));
1068 operator=(
promise&& __rhs) noexcept
1070 promise(std::move(__rhs)).swap(*
this);
1079 _M_future.swap(__rhs._M_future);
1080 _M_storage.swap(__rhs._M_storage);
1090 set_value(
const _Res& __r)
1091 { _M_future->_M_set_result(_State::__setter(
this, __r)); }
1094 set_value(_Res&& __r)
1095 { _M_future->_M_set_result(_State::__setter(
this, std::move(__r))); }
1099 { _M_future->_M_set_result(_State::__setter(__p,
this)); }
1102 set_value_at_thread_exit(
const _Res& __r)
1104 _M_future->_M_set_delayed_result(_State::__setter(
this, __r),
1109 set_value_at_thread_exit(_Res&& __r)
1111 _M_future->_M_set_delayed_result(
1112 _State::__setter(
this, std::move(__r)), _M_future);
1118 _M_future->_M_set_delayed_result(_State::__setter(__p,
this),
1123 template<
typename _Res>
1128 template<
typename _Res,
typename _Alloc>
1134 template<
typename _Res>
1135 class promise<_Res&>
1137 typedef __future_base::_State_base _State;
1140 template<
typename,
typename>
friend class _State::_Setter;
1143 _Ptr_type _M_storage;
1147 : _M_future(std::make_shared<_State>()),
1148 _M_storage(
new _Res_type())
1151 promise(promise&& __rhs) noexcept
1152 : _M_future(std::move(__rhs._M_future)),
1153 _M_storage(std::move(__rhs._M_storage))
1156 template<
typename _Allocator>
1158 : _M_future(std::allocate_shared<_State>(__a)),
1159 _M_storage(__future_base::_S_allocate_result<_Res&>(__a))
1162 template<
typename _Allocator>
1164 : _M_future(std::move(__rhs._M_future)),
1165 _M_storage(std::move(__rhs._M_storage))
1168 promise(
const promise&) =
delete;
1172 if (static_cast<bool>(_M_future) && !_M_future.unique())
1173 _M_future->_M_break_promise(std::move(_M_storage));
1178 operator=(promise&& __rhs) noexcept
1180 promise(std::move(__rhs)).swap(*
this);
1184 promise& operator=(
const promise&) =
delete;
1187 swap(promise& __rhs) noexcept
1189 _M_future.swap(__rhs._M_future);
1190 _M_storage.
swap(__rhs._M_storage);
1200 set_value(_Res& __r)
1201 { _M_future->_M_set_result(_State::__setter(
this, __r)); }
1205 { _M_future->_M_set_result(_State::__setter(__p,
this)); }
1208 set_value_at_thread_exit(_Res& __r)
1210 _M_future->_M_set_delayed_result(_State::__setter(
this, __r),
1217 _M_future->_M_set_delayed_result(_State::__setter(__p,
this),
1226 typedef __future_base::_State_base _State;
1229 template<
typename,
typename>
friend class _State::_Setter;
1232 _Ptr_type _M_storage;
1236 : _M_future(std::make_shared<_State>()),
1237 _M_storage(
new _Res_type())
1240 promise(promise&& __rhs) noexcept
1241 : _M_future(std::move(__rhs._M_future)),
1242 _M_storage(std::move(__rhs._M_storage))
1245 template<
typename _Allocator>
1247 : _M_future(std::allocate_shared<_State>(__a)),
1248 _M_storage(__future_base::_S_allocate_result<void>(__a))
1253 template<
typename _Allocator>
1255 : _M_future(std::move(__rhs._M_future)),
1256 _M_storage(std::move(__rhs._M_storage))
1259 promise(
const promise&) =
delete;
1263 if (static_cast<bool>(_M_future) && !_M_future.unique())
1264 _M_future->_M_break_promise(std::move(_M_storage));
1269 operator=(promise&& __rhs) noexcept
1271 promise(std::move(__rhs)).swap(*
this);
1275 promise& operator=(
const promise&) =
delete;
1278 swap(promise& __rhs) noexcept
1280 _M_future.swap(__rhs._M_future);
1281 _M_storage.
swap(__rhs._M_storage);
1294 { _M_future->_M_set_result(_State::__setter(__p,
this)); }
1297 set_value_at_thread_exit();
1302 _M_future->_M_set_delayed_result(_State::__setter(__p,
this),
1309 struct __future_base::_State_base::_Setter<void, void>
1313 _State_base::_S_check(_M_promise->_M_future);
1314 return std::move(_M_promise->_M_storage);
1322 { _M_future->_M_set_result(_State::_Setter<void, void>{
this }); }
1327 _M_future->_M_set_delayed_result(_State::_Setter<void, void>{
this},
1331 template<
typename _Ptr_type,
typename _Fn,
typename _Res>
1332 struct __future_base::_Task_setter
1339 (*_M_result)->_M_set((*_M_fn)());
1343 __throw_exception_again;
1349 return std::move(*_M_result);
1355 template<
typename _Ptr_type,
typename _Fn>
1356 struct __future_base::_Task_setter<_Ptr_type, _Fn, void>
1358 _Ptr_type operator()()
const 1366 __throw_exception_again;
1372 return std::move(*_M_result);
1374 _Ptr_type* _M_result;
1379 template<
typename _Res,
typename... _Args>
1380 struct __future_base::_Task_state_base<_Res(_Args...)>
1381 : __future_base::_State_base
1385 template<
typename _Alloc>
1386 _Task_state_base(
const _Alloc& __a)
1387 : _M_result(_S_allocate_result<_Res>(__a))
1392 _M_run(_Args&&... __args) = 0;
1402 _Ptr_type _M_result;
1406 template<
typename _Fn,
typename _Alloc,
typename _Res,
typename... _Args>
1407 struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
1408 : __future_base::_Task_state_base<_Res(_Args...)>
1410 template<
typename _Fn2>
1411 _Task_state(_Fn2&& __fn,
const _Alloc& __a)
1412 : _Task_state_base<_Res(_Args...)>(__a),
1413 _M_impl(std::forward<_Fn2>(__fn), __a)
1418 _M_run(_Args&&... __args)
1420 auto __boundfn = [&] () ->
typename result_of<_Fn(_Args&&...)>::type {
1421 return std::__invoke(_M_impl._M_fn, std::forward<_Args>(__args)...);
1423 this->_M_set_result(_S_task_setter(this->_M_result, __boundfn));
1429 auto __boundfn = [&] () ->
typename result_of<_Fn(_Args&&...)>::type {
1430 return std::__invoke(_M_impl._M_fn, std::forward<_Args>(__args)...);
1432 this->_M_set_delayed_result(_S_task_setter(this->_M_result, __boundfn),
1436 virtual shared_ptr<_Task_state_base<_Res(_Args...)>>
1439 struct _Impl : _Alloc
1441 template<
typename _Fn2>
1442 _Impl(_Fn2&& __fn,
const _Alloc& __a)
1443 : _Alloc(__a), _M_fn(std::forward<_Fn2>(__fn)) { }
1448 template<
typename _Signature,
typename _Fn,
typename _Alloc>
1450 __create_task_state(_Fn&& __fn,
const _Alloc& __a)
1452 typedef typename decay<_Fn>::type _Fn2;
1453 typedef __future_base::_Task_state<_Fn2, _Alloc, _Signature> _State;
1454 return std::allocate_shared<_State>(__a, std::forward<_Fn>(__fn), __a);
1457 template<
typename _Fn,
typename _Alloc,
typename _Res,
typename... _Args>
1458 shared_ptr<__future_base::_Task_state_base<_Res(_Args...)>>
1459 __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)>::_M_reset()
1461 return __create_task_state<_Res(_Args...)>(std::move(_M_impl._M_fn),
1462 static_cast<_Alloc&
>(_M_impl));
1465 template<
typename _Task,
typename _Fn,
bool 1466 = is_same<_Task, typename decay<_Fn>::type>::value>
1467 struct __constrain_pkgdtask
1468 {
typedef void __type; };
1470 template<
typename _Task,
typename _Fn>
1471 struct __constrain_pkgdtask<_Task, _Fn, true>
1475 template<
typename _Res,
typename... _ArgTypes>
1476 class packaged_task<_Res(_ArgTypes...)>
1478 typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type;
1483 packaged_task() noexcept { }
1487 template<
typename _Allocator>
1491 template<
typename _Fn,
typename =
typename 1492 __constrain_pkgdtask<packaged_task, _Fn>::__type>
1494 packaged_task(_Fn&& __fn)
1496 std::forward<_Fn>(__fn))
1502 template<
typename _Fn,
typename _Alloc,
typename =
typename 1503 __constrain_pkgdtask<packaged_task, _Fn>::__type>
1505 : _M_state(__create_task_state<_Res(_ArgTypes...)>(
1506 std::forward<_Fn>(__fn), __a))
1511 if (static_cast<bool>(_M_state) && !_M_state.unique())
1512 _M_state->_M_break_promise(std::move(_M_state->_M_result));
1516 packaged_task(
const packaged_task&) =
delete;
1517 packaged_task& operator=(
const packaged_task&) =
delete;
1519 template<
typename _Allocator>
1521 const packaged_task&) =
delete;
1524 packaged_task(packaged_task&& __other) noexcept
1525 { this->swap(__other); }
1527 template<
typename _Allocator>
1529 packaged_task&& __other) noexcept
1530 { this->swap(__other); }
1532 packaged_task& operator=(packaged_task&& __other) noexcept
1534 packaged_task(std::move(__other)).swap(*
this);
1539 swap(packaged_task& __other) noexcept
1540 { _M_state.swap(__other._M_state); }
1543 valid()
const noexcept
1544 {
return static_cast<bool>(_M_state); }
1553 operator()(_ArgTypes... __args)
1555 __future_base::_State_base::_S_check(_M_state);
1556 _M_state->_M_run(std::forward<_ArgTypes>(__args)...);
1560 make_ready_at_thread_exit(_ArgTypes... __args)
1562 __future_base::_State_base::_S_check(_M_state);
1563 _M_state->_M_run_delayed(std::forward<_ArgTypes>(__args)..., _M_state);
1569 __future_base::_State_base::_S_check(_M_state);
1570 packaged_task __tmp;
1571 __tmp._M_state = _M_state;
1572 _M_state = _M_state->_M_reset();
1577 template<
typename _Res,
typename... _ArgTypes>
1579 swap(packaged_task<_Res(_ArgTypes...)>& __x,
1580 packaged_task<_Res(_ArgTypes...)>& __y) noexcept
1583 template<
typename _Res,
typename _Alloc>
1590 template<
typename _BoundFn,
typename _Res>
1591 class __future_base::_Deferred_state final
1592 :
public __future_base::_State_base
1596 _Deferred_state(_BoundFn&& __fn)
1597 : _M_result(
new _Result<_Res>()), _M_fn(std::move(__fn))
1602 _Ptr_type _M_result;
1615 _M_set_result(_S_task_setter(_M_result, _M_fn),
true);
1620 virtual bool _M_is_deferred_future()
const {
return true; }
1624 class __future_base::_Async_state_commonV2
1625 :
public __future_base::_State_base
1628 ~_Async_state_commonV2() =
default;
1645 virtual void _M_complete_async() { _M_join(); }
1647 void _M_join() {
std::call_once(_M_once, &thread::join, &_M_thread); }
1655 template<
typename _BoundFn,
typename _Res>
1656 class __future_base::_Async_state_impl final
1657 :
public __future_base::_Async_state_commonV2
1661 _Async_state_impl(_BoundFn&& __fn)
1662 : _M_result(
new _Result<_Res>()), _M_fn(std::move(__fn))
1667 _M_set_result(_S_task_setter(_M_result, _M_fn));
1672 if (static_cast<bool>(_M_result))
1673 this->_M_break_promise(std::move(_M_result));
1674 __throw_exception_again;
1682 ~_Async_state_impl() {
if (_M_thread.joinable()) _M_thread.join(); }
1686 _Ptr_type _M_result;
1690 template<
typename _BoundFn>
1692 __future_base::_S_make_deferred_state(_BoundFn&& __fn)
1694 typedef typename remove_reference<_BoundFn>::type __fn_type;
1695 typedef _Deferred_state<__fn_type> __state_type;
1696 return std::make_shared<__state_type>(std::move(__fn));
1699 template<
typename _BoundFn>
1701 __future_base::_S_make_async_state(_BoundFn&& __fn)
1703 typedef typename remove_reference<_BoundFn>::type __fn_type;
1704 typedef _Async_state_impl<__fn_type> __state_type;
1705 return std::make_shared<__state_type>(std::move(__fn));
1710 template<
typename _Fn,
typename... _Args>
1711 future<__async_result_of<_Fn, _Args...>>
1715 if ((__policy & launch::async) == launch::async)
1719 __state = __future_base::_S_make_async_state(
1720 std::thread::__make_invoker(std::forward<_Fn>(__fn),
1721 std::forward<_Args>(__args)...)
1724 #if __cpp_exceptions 1727 if (__e.code() != errc::resource_unavailable_try_again
1728 || (__policy & launch::deferred) != launch::deferred)
1735 __state = __future_base::_S_make_deferred_state(
1736 std::thread::__make_invoker(std::forward<_Fn>(__fn),
1737 std::forward<_Args>(__args)...));
1739 return future<__async_result_of<_Fn, _Args...>>(__state);
1743 template<
typename _Fn,
typename... _Args>
1744 inline future<__async_result_of<_Fn, _Args...>>
1747 return std::async(launch::async|launch::deferred,
1748 std::forward<_Fn>(__fn),
1749 std::forward<_Args>(__args)...);
1752 #endif // _GLIBCXX_ASYNC_ABI_COMPAT 1753 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 1757 _GLIBCXX_END_NAMESPACE_VERSION
1762 #endif // _GLIBCXX_FUTURE An opaque pointer to an arbitrary exception.
future(future &&__uf) noexcept
Move constructor.
Explicit specialization for promise<void>
A result object that uses an allocator.
future< __async_result_of< _Fn, _Args... > > async(launch __policy, _Fn &&__fn, _Args &&... __args)
async
shared_future(const shared_future &__sf)
Copy constructor.
Common implementation for future and shared_future.
Primary template for future.
shared_future(shared_future &&__sf) noexcept
Construct from a shared_future rvalue.
Explicit specialization for void.
future_errc
Error code for futures.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
const error_category & future_category() noexcept
Points to a statically-allocated object derived from error_category.
Explicit specialization for shared_future<void>
Partial specialization for future<R&>
void rethrow_exception(exception_ptr) __attribute__((__noreturn__))
Throw the object pointed to by the exception_ptr.
ISO C++ entities toplevel namespace is std.
Exception type thrown by futures.
future(future &&__uf) noexcept
Move constructor.
A result object that has storage for an object of type _Res.
One of two subclasses of exception.
Partial specialization for shared_future<R&>
Base class and enclosing scope.
shared_future(shared_future &&__sf) noexcept
Construct from a shared_future rvalue.
shared_future(const shared_future &__sf)
Copy constructor.
20.7.1.2 unique_ptr for single objects.
shared_future(future< void > &&__uf) noexcept
Construct from a future rvalue.
exception_ptr make_exception_ptr(_Ex) noexcept
Obtain an exception_ptr pointing to a copy of the supplied object.
void swap(unique_ptr &__u) noexcept
Exchange the pointer and deleter with another object.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
_GLIBCXX17_CONSTEXPR _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
void call_once(once_flag &__once, _Callable &&__f, _Args &&... __args)
call_once
Declare uses_allocator so it can be specialized in <queue> etc.
exception_ptr current_exception() noexcept
__allocated_ptr< _Alloc > __allocate_guarded(_Alloc &__a)
Allocate space for a single object using __a.
__result_type _M_get_result() const
Wait for the state to be ready and rethrow any stored exception.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
A smart pointer with reference-counted copy semantics.
future< __async_result_of< _Fn, _Args... > > async(_Fn &&__fn, _Args &&... __args)
async, potential overload
future(future &&__uf) noexcept
Move constructor.
Partial specialization for reference types.
void swap(packaged_task< _Res(_ArgTypes...)> &__x, packaged_task< _Res(_ArgTypes...)> &__y) noexcept
swap
shared_future(future< _Res &> &&__uf) noexcept
Construct from a future rvalue.
bitset< _Nb > operator &(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
shared_future(const shared_future &__sf)
Copy constructor.
Primary template for shared_future.
future_status
Status code for futures.
Thrown to indicate error code of underlying system.
constexpr result_of< _Callable &&(_Args &&...)>::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_callable< _Callable &&(_Args &&...)>::value)
Invoke a callable object.
Explicit specialization for future<void>
Primary template for promise.
launch
Launch code for futures.
shared_future(future< _Res > &&__uf) noexcept
Construct from a future rvalue.
Non-standard RAII type for managing pointers obtained from allocators.
shared_future(shared_future &&__sf) noexcept
Construct from a shared_future rvalue.
The standard allocator, as per [20.4].