2
//===--------------------------- future -----------------------------------===//
4
// The LLVM Compiler Infrastructure
6
// This file is dual licensed under the MIT and the University of Illinois Open
7
// Source Licenses. See LICENSE.TXT for details.
9
//===----------------------------------------------------------------------===//
11
#ifndef _LIBCPP_FUTURE
12
#define _LIBCPP_FUTURE
20
enum class future_errc
23
future_already_retrieved,
24
promise_already_satisfied,
32
any = async | deferred
35
enum class future_status
42
template <> struct is_error_code_enum<future_errc> : public true_type { };
43
error_code make_error_code(future_errc e) noexcept;
44
error_condition make_error_condition(future_errc e) noexcept;
46
const error_category& future_category() noexcept;
52
future_error(error_code ec); // exposition only
54
const error_code& code() const noexcept;
55
const char* what() const noexcept;
63
template <class Allocator>
64
promise(allocator_arg_t, const Allocator& a);
65
promise(promise&& rhs) noexcept;
66
promise(const promise& rhs) = delete;
70
promise& operator=(promise&& rhs) noexcept;
71
promise& operator=(const promise& rhs) = delete;
72
void swap(promise& other) noexcept;
74
// retrieving the result
75
future<R> get_future();
78
void set_value(const R& r);
79
void set_value(R&& r);
80
void set_exception(exception_ptr p);
82
// setting the result with deferred notification
83
void set_value_at_thread_exit(const R& r);
84
void set_value_at_thread_exit(R&& r);
85
void set_exception_at_thread_exit(exception_ptr p);
93
template <class Allocator>
94
promise(allocator_arg_t, const Allocator& a);
95
promise(promise&& rhs) noexcept;
96
promise(const promise& rhs) = delete;
100
promise& operator=(promise&& rhs) noexcept;
101
promise& operator=(const promise& rhs) = delete;
102
void swap(promise& other) noexcept;
104
// retrieving the result
105
future<R&> get_future();
107
// setting the result
108
void set_value(R& r);
109
void set_exception(exception_ptr p);
111
// setting the result with deferred notification
112
void set_value_at_thread_exit(R&);
113
void set_exception_at_thread_exit(exception_ptr p);
121
template <class Allocator>
122
promise(allocator_arg_t, const Allocator& a);
123
promise(promise&& rhs) noexcept;
124
promise(const promise& rhs) = delete;
128
promise& operator=(promise&& rhs) noexcept;
129
promise& operator=(const promise& rhs) = delete;
130
void swap(promise& other) noexcept;
132
// retrieving the result
133
future<void> get_future();
135
// setting the result
137
void set_exception(exception_ptr p);
139
// setting the result with deferred notification
140
void set_value_at_thread_exit();
141
void set_exception_at_thread_exit(exception_ptr p);
144
template <class R> void swap(promise<R>& x, promise<R>& y) noexcept;
146
template <class R, class Alloc>
147
struct uses_allocator<promise<R>, Alloc> : public true_type {};
154
future(future&&) noexcept;
155
future(const future& rhs) = delete;
157
future& operator=(const future& rhs) = delete;
158
future& operator=(future&&) noexcept;
159
shared_future<R> share();
161
// retrieving the value
164
// functions to check state
165
bool valid() const noexcept;
168
template <class Rep, class Period>
170
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
171
template <class Clock, class Duration>
173
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
181
future(future&&) noexcept;
182
future(const future& rhs) = delete;
184
future& operator=(const future& rhs) = delete;
185
future& operator=(future&&) noexcept;
186
shared_future<R&> share();
188
// retrieving the value
191
// functions to check state
192
bool valid() const noexcept;
195
template <class Rep, class Period>
197
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
198
template <class Clock, class Duration>
200
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
208
future(future&&) noexcept;
209
future(const future& rhs) = delete;
211
future& operator=(const future& rhs) = delete;
212
future& operator=(future&&) noexcept;
213
shared_future<void> share();
215
// retrieving the value
218
// functions to check state
219
bool valid() const noexcept;
222
template <class Rep, class Period>
224
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
225
template <class Clock, class Duration>
227
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
234
shared_future() noexcept;
235
shared_future(const shared_future& rhs);
236
shared_future(future<R>&&) noexcept;
237
shared_future(shared_future&& rhs) noexcept;
239
shared_future& operator=(const shared_future& rhs);
240
shared_future& operator=(shared_future&& rhs) noexcept;
242
// retrieving the value
243
const R& get() const;
245
// functions to check state
246
bool valid() const noexcept;
249
template <class Rep, class Period>
251
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
252
template <class Clock, class Duration>
254
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
258
class shared_future<R&>
261
shared_future() noexcept;
262
shared_future(const shared_future& rhs);
263
shared_future(future<R&>&&) noexcept;
264
shared_future(shared_future&& rhs) noexcept;
266
shared_future& operator=(const shared_future& rhs);
267
shared_future& operator=(shared_future&& rhs) noexcept;
269
// retrieving the value
272
// functions to check state
273
bool valid() const noexcept;
276
template <class Rep, class Period>
278
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
279
template <class Clock, class Duration>
281
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
285
class shared_future<void>
288
shared_future() noexcept;
289
shared_future(const shared_future& rhs);
290
shared_future(future<void>&&) noexcept;
291
shared_future(shared_future&& rhs) noexcept;
293
shared_future& operator=(const shared_future& rhs);
294
shared_future& operator=(shared_future&& rhs) noexcept;
296
// retrieving the value
299
// functions to check state
300
bool valid() const noexcept;
303
template <class Rep, class Period>
305
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
306
template <class Clock, class Duration>
308
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
311
template <class F, class... Args>
312
future<typename result_of<F(Args...)>::type>
313
async(F&& f, Args&&... args);
315
template <class F, class... Args>
316
future<typename result_of<F(Args...)>::type>
317
async(launch policy, F&& f, Args&&... args);
319
template <class> class packaged_task; // undefined
321
template <class R, class... ArgTypes>
322
class packaged_task<R(ArgTypes...)>
325
typedef R result_type;
327
// construction and destruction
328
packaged_task() noexcept;
330
explicit packaged_task(F&& f);
331
template <class F, class Allocator>
332
explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
336
packaged_task(const packaged_task&) = delete;
337
packaged_task& operator=(const packaged_task&) = delete;
340
packaged_task(packaged_task&& other) noexcept;
341
packaged_task& operator=(packaged_task&& other) noexcept;
342
void swap(packaged_task& other) noexcept;
344
bool valid() const noexcept;
347
future<R> get_future();
350
void operator()(ArgTypes... );
351
void make_ready_at_thread_exit(ArgTypes...);
357
void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept;
359
template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
366
#include <system_error>
373
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
374
#pragma GCC system_header
377
_LIBCPP_BEGIN_NAMESPACE_STD
379
//enum class future_errc
380
_LIBCPP_DECLARE_STRONG_ENUM(future_errc)
383
future_already_retrieved,
384
promise_already_satisfied,
387
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
390
struct _LIBCPP_TYPE_VIS is_error_code_enum<future_errc> : public true_type {};
392
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
394
struct _LIBCPP_TYPE_VIS is_error_code_enum<future_errc::__lx> : public true_type { };
398
_LIBCPP_DECLARE_STRONG_ENUM(launch)
402
any = async | deferred
404
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
406
//enum class future_status
407
_LIBCPP_DECLARE_STRONG_ENUM(future_status)
413
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status)
416
const error_category& future_category() _NOEXCEPT;
418
inline _LIBCPP_INLINE_VISIBILITY
420
make_error_code(future_errc __e) _NOEXCEPT
422
return error_code(static_cast<int>(__e), future_category());
425
inline _LIBCPP_INLINE_VISIBILITY
427
make_error_condition(future_errc __e) _NOEXCEPT
429
return error_condition(static_cast<int>(__e), future_category());
432
class _LIBCPP_EXCEPTION_ABI future_error
437
future_error(error_code __ec);
439
_LIBCPP_INLINE_VISIBILITY
440
const error_code& code() const _NOEXCEPT {return __ec_;}
442
virtual ~future_error() _NOEXCEPT;
445
class __assoc_sub_state
446
: public __shared_count
449
exception_ptr __exception_;
450
mutable mutex __mut_;
451
mutable condition_variable __cv_;
454
virtual void __on_zero_shared() _NOEXCEPT;
455
void __sub_wait(unique_lock<mutex>& __lk);
460
__future_attached = 2,
465
_LIBCPP_INLINE_VISIBILITY
466
__assoc_sub_state() : __state_(0) {}
468
_LIBCPP_INLINE_VISIBILITY
469
bool __has_value() const
470
{return (__state_ & __constructed) || (__exception_ != nullptr);}
472
_LIBCPP_INLINE_VISIBILITY
473
void __set_future_attached()
475
lock_guard<mutex> __lk(__mut_);
476
__state_ |= __future_attached;
478
_LIBCPP_INLINE_VISIBILITY
479
bool __has_future_attached() const {return __state_ & __future_attached;}
481
_LIBCPP_INLINE_VISIBILITY
482
void __set_deferred() {__state_ |= deferred;}
485
_LIBCPP_INLINE_VISIBILITY
486
bool __is_ready() const {return __state_ & ready;}
489
void set_value_at_thread_exit();
491
void set_exception(exception_ptr __p);
492
void set_exception_at_thread_exit(exception_ptr __p);
497
template <class _Rep, class _Period>
499
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
500
template <class _Clock, class _Duration>
502
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const;
504
virtual void __execute();
507
template <class _Clock, class _Duration>
509
__assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
511
unique_lock<mutex> __lk(__mut_);
512
if (__state_ & deferred)
513
return future_status::deferred;
514
while (!(__state_ & ready) && _Clock::now() < __abs_time)
515
__cv_.wait_until(__lk, __abs_time);
516
if (__state_ & ready)
517
return future_status::ready;
518
return future_status::timeout;
521
template <class _Rep, class _Period>
522
inline _LIBCPP_INLINE_VISIBILITY
524
__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
526
return wait_until(chrono::steady_clock::now() + __rel_time);
531
: public __assoc_sub_state
533
typedef __assoc_sub_state base;
534
typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up;
538
virtual void __on_zero_shared() _NOEXCEPT;
541
template <class _Arg>
542
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
543
void set_value(_Arg&& __arg);
545
void set_value(_Arg& __arg);
548
template <class _Arg>
549
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
550
void set_value_at_thread_exit(_Arg&& __arg);
552
void set_value_at_thread_exit(_Arg& __arg);
556
typename add_lvalue_reference<_Rp>::type copy();
561
__assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT
563
if (this->__state_ & base::__constructed)
564
reinterpret_cast<_Rp*>(&__value_)->~_Rp();
569
template <class _Arg>
571
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
572
__assoc_state<_Rp>::set_value(_Arg&& __arg)
574
__assoc_state<_Rp>::set_value(_Arg& __arg)
577
unique_lock<mutex> __lk(this->__mut_);
578
#ifndef _LIBCPP_NO_EXCEPTIONS
579
if (this->__has_value())
580
throw future_error(make_error_code(future_errc::promise_already_satisfied));
582
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
583
this->__state_ |= base::__constructed | base::ready;
589
template <class _Arg>
591
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
592
__assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg)
594
__assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg)
597
unique_lock<mutex> __lk(this->__mut_);
598
#ifndef _LIBCPP_NO_EXCEPTIONS
599
if (this->__has_value())
600
throw future_error(make_error_code(future_errc::promise_already_satisfied));
602
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
603
this->__state_ |= base::__constructed;
604
__thread_local_data()->__make_ready_at_thread_exit(this);
610
__assoc_state<_Rp>::move()
612
unique_lock<mutex> __lk(this->__mut_);
613
this->__sub_wait(__lk);
614
if (this->__exception_ != nullptr)
615
rethrow_exception(this->__exception_);
616
return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_));
620
typename add_lvalue_reference<_Rp>::type
621
__assoc_state<_Rp>::copy()
623
unique_lock<mutex> __lk(this->__mut_);
624
this->__sub_wait(__lk);
625
if (this->__exception_ != nullptr)
626
rethrow_exception(this->__exception_);
627
return *reinterpret_cast<_Rp*>(&__value_);
631
class __assoc_state<_Rp&>
632
: public __assoc_sub_state
634
typedef __assoc_sub_state base;
639
virtual void __on_zero_shared() _NOEXCEPT;
642
void set_value(_Rp& __arg);
643
void set_value_at_thread_exit(_Rp& __arg);
650
__assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT
657
__assoc_state<_Rp&>::set_value(_Rp& __arg)
659
unique_lock<mutex> __lk(this->__mut_);
660
#ifndef _LIBCPP_NO_EXCEPTIONS
661
if (this->__has_value())
662
throw future_error(make_error_code(future_errc::promise_already_satisfied));
665
this->__state_ |= base::__constructed | base::ready;
672
__assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
674
unique_lock<mutex> __lk(this->__mut_);
675
#ifndef _LIBCPP_NO_EXCEPTIONS
676
if (this->__has_value())
677
throw future_error(make_error_code(future_errc::promise_already_satisfied));
680
this->__state_ |= base::__constructed;
681
__thread_local_data()->__make_ready_at_thread_exit(this);
687
__assoc_state<_Rp&>::copy()
689
unique_lock<mutex> __lk(this->__mut_);
690
this->__sub_wait(__lk);
691
if (this->__exception_ != nullptr)
692
rethrow_exception(this->__exception_);
696
template <class _Rp, class _Alloc>
697
class __assoc_state_alloc
698
: public __assoc_state<_Rp>
700
typedef __assoc_state<_Rp> base;
703
virtual void __on_zero_shared() _NOEXCEPT;
705
_LIBCPP_INLINE_VISIBILITY
706
explicit __assoc_state_alloc(const _Alloc& __a)
710
template <class _Rp, class _Alloc>
712
__assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT
714
if (this->__state_ & base::__constructed)
715
reinterpret_cast<_Rp*>(&this->__value_)->~_Rp();
716
typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
717
this->~__assoc_state_alloc();
718
__a.deallocate(this, 1);
721
template <class _Rp, class _Alloc>
722
class __assoc_state_alloc<_Rp&, _Alloc>
723
: public __assoc_state<_Rp&>
725
typedef __assoc_state<_Rp&> base;
728
virtual void __on_zero_shared() _NOEXCEPT;
730
_LIBCPP_INLINE_VISIBILITY
731
explicit __assoc_state_alloc(const _Alloc& __a)
735
template <class _Rp, class _Alloc>
737
__assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT
739
typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
740
this->~__assoc_state_alloc();
741
__a.deallocate(this, 1);
744
template <class _Alloc>
745
class __assoc_sub_state_alloc
746
: public __assoc_sub_state
748
typedef __assoc_sub_state base;
751
virtual void __on_zero_shared() _NOEXCEPT;
753
_LIBCPP_INLINE_VISIBILITY
754
explicit __assoc_sub_state_alloc(const _Alloc& __a)
758
template <class _Alloc>
760
__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
762
typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_);
763
this->~__assoc_sub_state_alloc();
764
__a.deallocate(this, 1);
767
template <class _Rp, class _Fp>
768
class __deferred_assoc_state
769
: public __assoc_state<_Rp>
771
typedef __assoc_state<_Rp> base;
776
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
777
explicit __deferred_assoc_state(_Fp&& __f);
780
virtual void __execute();
783
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
785
template <class _Rp, class _Fp>
786
inline _LIBCPP_INLINE_VISIBILITY
787
__deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f)
788
: __func_(_VSTD::forward<_Fp>(__f))
790
this->__set_deferred();
793
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
795
template <class _Rp, class _Fp>
797
__deferred_assoc_state<_Rp, _Fp>::__execute()
799
#ifndef _LIBCPP_NO_EXCEPTIONS
802
#endif // _LIBCPP_NO_EXCEPTIONS
803
this->set_value(__func_());
804
#ifndef _LIBCPP_NO_EXCEPTIONS
808
this->set_exception(current_exception());
810
#endif // _LIBCPP_NO_EXCEPTIONS
814
class __deferred_assoc_state<void, _Fp>
815
: public __assoc_sub_state
817
typedef __assoc_sub_state base;
822
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
823
explicit __deferred_assoc_state(_Fp&& __f);
826
virtual void __execute();
829
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
832
inline _LIBCPP_INLINE_VISIBILITY
833
__deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f)
834
: __func_(_VSTD::forward<_Fp>(__f))
836
this->__set_deferred();
839
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
843
__deferred_assoc_state<void, _Fp>::__execute()
845
#ifndef _LIBCPP_NO_EXCEPTIONS
848
#endif // _LIBCPP_NO_EXCEPTIONS
851
#ifndef _LIBCPP_NO_EXCEPTIONS
855
this->set_exception(current_exception());
857
#endif // _LIBCPP_NO_EXCEPTIONS
860
template <class _Rp, class _Fp>
861
class __async_assoc_state
862
: public __assoc_state<_Rp>
864
typedef __assoc_state<_Rp> base;
868
virtual void __on_zero_shared() _NOEXCEPT;
870
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
871
explicit __async_assoc_state(_Fp&& __f);
874
virtual void __execute();
877
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
879
template <class _Rp, class _Fp>
880
inline _LIBCPP_INLINE_VISIBILITY
881
__async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f)
882
: __func_(_VSTD::forward<_Fp>(__f))
886
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
888
template <class _Rp, class _Fp>
890
__async_assoc_state<_Rp, _Fp>::__execute()
892
#ifndef _LIBCPP_NO_EXCEPTIONS
895
#endif // _LIBCPP_NO_EXCEPTIONS
896
this->set_value(__func_());
897
#ifndef _LIBCPP_NO_EXCEPTIONS
901
this->set_exception(current_exception());
903
#endif // _LIBCPP_NO_EXCEPTIONS
906
template <class _Rp, class _Fp>
908
__async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT
911
base::__on_zero_shared();
915
class __async_assoc_state<void, _Fp>
916
: public __assoc_sub_state
918
typedef __assoc_sub_state base;
922
virtual void __on_zero_shared() _NOEXCEPT;
924
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
925
explicit __async_assoc_state(_Fp&& __f);
928
virtual void __execute();
931
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
934
inline _LIBCPP_INLINE_VISIBILITY
935
__async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f)
936
: __func_(_VSTD::forward<_Fp>(__f))
940
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
944
__async_assoc_state<void, _Fp>::__execute()
946
#ifndef _LIBCPP_NO_EXCEPTIONS
949
#endif // _LIBCPP_NO_EXCEPTIONS
952
#ifndef _LIBCPP_NO_EXCEPTIONS
956
this->set_exception(current_exception());
958
#endif // _LIBCPP_NO_EXCEPTIONS
963
__async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT
966
base::__on_zero_shared();
969
template <class _Rp> class _LIBCPP_TYPE_VIS promise;
970
template <class _Rp> class _LIBCPP_TYPE_VIS shared_future;
974
template <class _Rp> class _LIBCPP_TYPE_VIS future;
976
template <class _Rp, class _Fp>
978
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
979
__make_deferred_assoc_state(_Fp&& __f);
981
__make_deferred_assoc_state(_Fp __f);
984
template <class _Rp, class _Fp>
986
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
987
__make_async_assoc_state(_Fp&& __f);
989
__make_async_assoc_state(_Fp __f);
993
class _LIBCPP_TYPE_VIS future
995
__assoc_state<_Rp>* __state_;
997
explicit future(__assoc_state<_Rp>* __state);
999
template <class> friend class promise;
1000
template <class> friend class shared_future;
1002
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1003
template <class _R1, class _Fp>
1004
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1005
template <class _R1, class _Fp>
1006
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1008
template <class _R1, class _Fp>
1009
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
1010
template <class _R1, class _Fp>
1011
friend future<_R1> __make_async_assoc_state(_Fp __f);
1015
_LIBCPP_INLINE_VISIBILITY
1016
future() _NOEXCEPT : __state_(nullptr) {}
1017
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1018
_LIBCPP_INLINE_VISIBILITY
1019
future(future&& __rhs) _NOEXCEPT
1020
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1021
future(const future&) = delete;
1022
future& operator=(const future&) = delete;
1023
_LIBCPP_INLINE_VISIBILITY
1024
future& operator=(future&& __rhs) _NOEXCEPT
1026
future(std::move(__rhs)).swap(*this);
1029
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1031
future(const future&);
1032
future& operator=(const future&);
1034
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1036
shared_future<_Rp> share();
1038
// retrieving the value
1041
_LIBCPP_INLINE_VISIBILITY
1042
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1044
// functions to check state
1045
_LIBCPP_INLINE_VISIBILITY
1046
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
1048
_LIBCPP_INLINE_VISIBILITY
1049
void wait() const {__state_->wait();}
1050
template <class _Rep, class _Period>
1051
_LIBCPP_INLINE_VISIBILITY
1053
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1054
{return __state_->wait_for(__rel_time);}
1055
template <class _Clock, class _Duration>
1056
_LIBCPP_INLINE_VISIBILITY
1058
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1059
{return __state_->wait_until(__abs_time);}
1062
template <class _Rp>
1063
future<_Rp>::future(__assoc_state<_Rp>* __state)
1066
#ifndef _LIBCPP_NO_EXCEPTIONS
1067
if (__state_->__has_future_attached())
1068
throw future_error(make_error_code(future_errc::future_already_retrieved));
1070
__state_->__add_shared();
1071
__state_->__set_future_attached();
1074
struct __release_shared_count
1076
void operator()(__shared_count* p) {p->__release_shared();}
1079
template <class _Rp>
1080
future<_Rp>::~future()
1083
__state_->__release_shared();
1086
template <class _Rp>
1090
unique_ptr<__shared_count, __release_shared_count> __(__state_);
1091
__assoc_state<_Rp>* __s = __state_;
1096
template <class _Rp>
1097
class _LIBCPP_TYPE_VIS future<_Rp&>
1099
__assoc_state<_Rp&>* __state_;
1101
explicit future(__assoc_state<_Rp&>* __state);
1103
template <class> friend class promise;
1104
template <class> friend class shared_future;
1106
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1107
template <class _R1, class _Fp>
1108
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1109
template <class _R1, class _Fp>
1110
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1112
template <class _R1, class _Fp>
1113
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
1114
template <class _R1, class _Fp>
1115
friend future<_R1> __make_async_assoc_state(_Fp __f);
1119
_LIBCPP_INLINE_VISIBILITY
1120
future() _NOEXCEPT : __state_(nullptr) {}
1121
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1122
_LIBCPP_INLINE_VISIBILITY
1123
future(future&& __rhs) _NOEXCEPT
1124
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1125
future(const future&) = delete;
1126
future& operator=(const future&) = delete;
1127
_LIBCPP_INLINE_VISIBILITY
1128
future& operator=(future&& __rhs) _NOEXCEPT
1130
future(std::move(__rhs)).swap(*this);
1133
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1135
future(const future&);
1136
future& operator=(const future&);
1138
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1140
shared_future<_Rp&> share();
1142
// retrieving the value
1145
_LIBCPP_INLINE_VISIBILITY
1146
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1148
// functions to check state
1149
_LIBCPP_INLINE_VISIBILITY
1150
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
1152
_LIBCPP_INLINE_VISIBILITY
1153
void wait() const {__state_->wait();}
1154
template <class _Rep, class _Period>
1155
_LIBCPP_INLINE_VISIBILITY
1157
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1158
{return __state_->wait_for(__rel_time);}
1159
template <class _Clock, class _Duration>
1160
_LIBCPP_INLINE_VISIBILITY
1162
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1163
{return __state_->wait_until(__abs_time);}
1166
template <class _Rp>
1167
future<_Rp&>::future(__assoc_state<_Rp&>* __state)
1170
#ifndef _LIBCPP_NO_EXCEPTIONS
1171
if (__state_->__has_future_attached())
1172
throw future_error(make_error_code(future_errc::future_already_retrieved));
1174
__state_->__add_shared();
1175
__state_->__set_future_attached();
1178
template <class _Rp>
1179
future<_Rp&>::~future()
1182
__state_->__release_shared();
1185
template <class _Rp>
1189
unique_ptr<__shared_count, __release_shared_count> __(__state_);
1190
__assoc_state<_Rp&>* __s = __state_;
1196
class _LIBCPP_TYPE_VIS future<void>
1198
__assoc_sub_state* __state_;
1200
explicit future(__assoc_sub_state* __state);
1202
template <class> friend class promise;
1203
template <class> friend class shared_future;
1205
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1206
template <class _R1, class _Fp>
1207
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1208
template <class _R1, class _Fp>
1209
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1211
template <class _R1, class _Fp>
1212
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
1213
template <class _R1, class _Fp>
1214
friend future<_R1> __make_async_assoc_state(_Fp __f);
1218
_LIBCPP_INLINE_VISIBILITY
1219
future() _NOEXCEPT : __state_(nullptr) {}
1220
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1221
_LIBCPP_INLINE_VISIBILITY
1222
future(future&& __rhs) _NOEXCEPT
1223
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1224
future(const future&) = delete;
1225
future& operator=(const future&) = delete;
1226
_LIBCPP_INLINE_VISIBILITY
1227
future& operator=(future&& __rhs) _NOEXCEPT
1229
future(std::move(__rhs)).swap(*this);
1232
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1234
future(const future&);
1235
future& operator=(const future&);
1237
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1239
shared_future<void> share();
1241
// retrieving the value
1244
_LIBCPP_INLINE_VISIBILITY
1245
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1247
// functions to check state
1248
_LIBCPP_INLINE_VISIBILITY
1249
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
1251
_LIBCPP_INLINE_VISIBILITY
1252
void wait() const {__state_->wait();}
1253
template <class _Rep, class _Period>
1254
_LIBCPP_INLINE_VISIBILITY
1256
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1257
{return __state_->wait_for(__rel_time);}
1258
template <class _Clock, class _Duration>
1259
_LIBCPP_INLINE_VISIBILITY
1261
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1262
{return __state_->wait_until(__abs_time);}
1265
template <class _Rp>
1266
inline _LIBCPP_INLINE_VISIBILITY
1268
swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT
1275
template <class _Callable> class packaged_task;
1277
template <class _Rp>
1278
class _LIBCPP_TYPE_VIS promise
1280
__assoc_state<_Rp>* __state_;
1282
_LIBCPP_INLINE_VISIBILITY
1283
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
1285
template <class> friend class packaged_task;
1288
template <class _Alloc>
1289
promise(allocator_arg_t, const _Alloc& __a);
1290
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1291
_LIBCPP_INLINE_VISIBILITY
1292
promise(promise&& __rhs) _NOEXCEPT
1293
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1294
promise(const promise& __rhs) = delete;
1295
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1297
promise(const promise& __rhs);
1299
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1303
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1304
_LIBCPP_INLINE_VISIBILITY
1305
promise& operator=(promise&& __rhs) _NOEXCEPT
1307
promise(std::move(__rhs)).swap(*this);
1310
promise& operator=(const promise& __rhs) = delete;
1311
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1313
promise& operator=(const promise& __rhs);
1315
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1316
_LIBCPP_INLINE_VISIBILITY
1317
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1319
// retrieving the result
1320
future<_Rp> get_future();
1322
// setting the result
1323
void set_value(const _Rp& __r);
1324
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1325
void set_value(_Rp&& __r);
1327
void set_exception(exception_ptr __p);
1329
// setting the result with deferred notification
1330
void set_value_at_thread_exit(const _Rp& __r);
1331
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1332
void set_value_at_thread_exit(_Rp&& __r);
1334
void set_exception_at_thread_exit(exception_ptr __p);
1337
template <class _Rp>
1338
promise<_Rp>::promise()
1339
: __state_(new __assoc_state<_Rp>)
1343
template <class _Rp>
1344
template <class _Alloc>
1345
promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0)
1347
typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp, _Alloc> >::other _A2;
1348
typedef __allocator_destructor<_A2> _D2;
1350
unique_ptr<__assoc_state_alloc<_Rp, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1351
::new(__hold.get()) __assoc_state_alloc<_Rp, _Alloc>(__a0);
1352
__state_ = __hold.release();
1355
template <class _Rp>
1356
promise<_Rp>::~promise()
1360
if (!__state_->__has_value() && __state_->use_count() > 1)
1361
__state_->set_exception(make_exception_ptr(
1362
future_error(make_error_code(future_errc::broken_promise))
1364
__state_->__release_shared();
1368
template <class _Rp>
1370
promise<_Rp>::get_future()
1372
#ifndef _LIBCPP_NO_EXCEPTIONS
1373
if (__state_ == nullptr)
1374
throw future_error(make_error_code(future_errc::no_state));
1376
return future<_Rp>(__state_);
1379
template <class _Rp>
1381
promise<_Rp>::set_value(const _Rp& __r)
1383
#ifndef _LIBCPP_NO_EXCEPTIONS
1384
if (__state_ == nullptr)
1385
throw future_error(make_error_code(future_errc::no_state));
1387
__state_->set_value(__r);
1390
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1392
template <class _Rp>
1394
promise<_Rp>::set_value(_Rp&& __r)
1396
#ifndef _LIBCPP_NO_EXCEPTIONS
1397
if (__state_ == nullptr)
1398
throw future_error(make_error_code(future_errc::no_state));
1400
__state_->set_value(_VSTD::move(__r));
1403
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1405
template <class _Rp>
1407
promise<_Rp>::set_exception(exception_ptr __p)
1409
#ifndef _LIBCPP_NO_EXCEPTIONS
1410
if (__state_ == nullptr)
1411
throw future_error(make_error_code(future_errc::no_state));
1413
__state_->set_exception(__p);
1416
template <class _Rp>
1418
promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
1420
#ifndef _LIBCPP_NO_EXCEPTIONS
1421
if (__state_ == nullptr)
1422
throw future_error(make_error_code(future_errc::no_state));
1424
__state_->set_value_at_thread_exit(__r);
1427
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1429
template <class _Rp>
1431
promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
1433
#ifndef _LIBCPP_NO_EXCEPTIONS
1434
if (__state_ == nullptr)
1435
throw future_error(make_error_code(future_errc::no_state));
1437
__state_->set_value_at_thread_exit(_VSTD::move(__r));
1440
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1442
template <class _Rp>
1444
promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
1446
#ifndef _LIBCPP_NO_EXCEPTIONS
1447
if (__state_ == nullptr)
1448
throw future_error(make_error_code(future_errc::no_state));
1450
__state_->set_exception_at_thread_exit(__p);
1455
template <class _Rp>
1456
class _LIBCPP_TYPE_VIS promise<_Rp&>
1458
__assoc_state<_Rp&>* __state_;
1460
_LIBCPP_INLINE_VISIBILITY
1461
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
1463
template <class> friend class packaged_task;
1467
template <class _Allocator>
1468
promise(allocator_arg_t, const _Allocator& __a);
1469
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1470
_LIBCPP_INLINE_VISIBILITY
1471
promise(promise&& __rhs) _NOEXCEPT
1472
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1473
promise(const promise& __rhs) = delete;
1474
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1476
promise(const promise& __rhs);
1478
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1482
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1483
_LIBCPP_INLINE_VISIBILITY
1484
promise& operator=(promise&& __rhs) _NOEXCEPT
1486
promise(std::move(__rhs)).swap(*this);
1489
promise& operator=(const promise& __rhs) = delete;
1490
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1492
promise& operator=(const promise& __rhs);
1494
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1495
_LIBCPP_INLINE_VISIBILITY
1496
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1498
// retrieving the result
1499
future<_Rp&> get_future();
1501
// setting the result
1502
void set_value(_Rp& __r);
1503
void set_exception(exception_ptr __p);
1505
// setting the result with deferred notification
1506
void set_value_at_thread_exit(_Rp&);
1507
void set_exception_at_thread_exit(exception_ptr __p);
1510
template <class _Rp>
1511
promise<_Rp&>::promise()
1512
: __state_(new __assoc_state<_Rp&>)
1516
template <class _Rp>
1517
template <class _Alloc>
1518
promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0)
1520
typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp&, _Alloc> >::other _A2;
1521
typedef __allocator_destructor<_A2> _D2;
1523
unique_ptr<__assoc_state_alloc<_Rp&, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1524
::new(__hold.get()) __assoc_state_alloc<_Rp&, _Alloc>(__a0);
1525
__state_ = __hold.release();
1528
template <class _Rp>
1529
promise<_Rp&>::~promise()
1533
if (!__state_->__has_value() && __state_->use_count() > 1)
1534
__state_->set_exception(make_exception_ptr(
1535
future_error(make_error_code(future_errc::broken_promise))
1537
__state_->__release_shared();
1541
template <class _Rp>
1543
promise<_Rp&>::get_future()
1545
#ifndef _LIBCPP_NO_EXCEPTIONS
1546
if (__state_ == nullptr)
1547
throw future_error(make_error_code(future_errc::no_state));
1549
return future<_Rp&>(__state_);
1552
template <class _Rp>
1554
promise<_Rp&>::set_value(_Rp& __r)
1556
#ifndef _LIBCPP_NO_EXCEPTIONS
1557
if (__state_ == nullptr)
1558
throw future_error(make_error_code(future_errc::no_state));
1560
__state_->set_value(__r);
1563
template <class _Rp>
1565
promise<_Rp&>::set_exception(exception_ptr __p)
1567
#ifndef _LIBCPP_NO_EXCEPTIONS
1568
if (__state_ == nullptr)
1569
throw future_error(make_error_code(future_errc::no_state));
1571
__state_->set_exception(__p);
1574
template <class _Rp>
1576
promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
1578
#ifndef _LIBCPP_NO_EXCEPTIONS
1579
if (__state_ == nullptr)
1580
throw future_error(make_error_code(future_errc::no_state));
1582
__state_->set_value_at_thread_exit(__r);
1585
template <class _Rp>
1587
promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
1589
#ifndef _LIBCPP_NO_EXCEPTIONS
1590
if (__state_ == nullptr)
1591
throw future_error(make_error_code(future_errc::no_state));
1593
__state_->set_exception_at_thread_exit(__p);
1599
class _LIBCPP_TYPE_VIS promise<void>
1601
__assoc_sub_state* __state_;
1603
_LIBCPP_INLINE_VISIBILITY
1604
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
1606
template <class> friend class packaged_task;
1610
template <class _Allocator>
1611
promise(allocator_arg_t, const _Allocator& __a);
1612
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1613
_LIBCPP_INLINE_VISIBILITY
1614
promise(promise&& __rhs) _NOEXCEPT
1615
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1616
promise(const promise& __rhs) = delete;
1617
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1619
promise(const promise& __rhs);
1621
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1625
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1626
_LIBCPP_INLINE_VISIBILITY
1627
promise& operator=(promise&& __rhs) _NOEXCEPT
1629
promise(std::move(__rhs)).swap(*this);
1632
promise& operator=(const promise& __rhs) = delete;
1633
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1635
promise& operator=(const promise& __rhs);
1637
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1638
_LIBCPP_INLINE_VISIBILITY
1639
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1641
// retrieving the result
1642
future<void> get_future();
1644
// setting the result
1646
void set_exception(exception_ptr __p);
1648
// setting the result with deferred notification
1649
void set_value_at_thread_exit();
1650
void set_exception_at_thread_exit(exception_ptr __p);
1653
template <class _Alloc>
1654
promise<void>::promise(allocator_arg_t, const _Alloc& __a0)
1656
typedef typename _Alloc::template rebind<__assoc_sub_state_alloc<_Alloc> >::other _A2;
1657
typedef __allocator_destructor<_A2> _D2;
1659
unique_ptr<__assoc_sub_state_alloc<_Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1660
::new(__hold.get()) __assoc_sub_state_alloc<_Alloc>(__a0);
1661
__state_ = __hold.release();
1664
template <class _Rp>
1665
inline _LIBCPP_INLINE_VISIBILITY
1667
swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT
1672
template <class _Rp, class _Alloc>
1673
struct _LIBCPP_TYPE_VIS uses_allocator<promise<_Rp>, _Alloc>
1674
: public true_type {};
1676
#ifndef _LIBCPP_HAS_NO_VARIADICS
1680
template<class _Fp> class __packaged_task_base;
1682
template<class _Rp, class ..._ArgTypes>
1683
class __packaged_task_base<_Rp(_ArgTypes...)>
1685
__packaged_task_base(const __packaged_task_base&);
1686
__packaged_task_base& operator=(const __packaged_task_base&);
1688
_LIBCPP_INLINE_VISIBILITY
1689
__packaged_task_base() {}
1690
_LIBCPP_INLINE_VISIBILITY
1691
virtual ~__packaged_task_base() {}
1692
virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0;
1693
virtual void destroy() = 0;
1694
virtual void destroy_deallocate() = 0;
1695
virtual _Rp operator()(_ArgTypes&& ...) = 0;
1698
template<class _FD, class _Alloc, class _FB> class __packaged_task_func;
1700
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1701
class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1702
: public __packaged_task_base<_Rp(_ArgTypes...)>
1704
__compressed_pair<_Fp, _Alloc> __f_;
1706
_LIBCPP_INLINE_VISIBILITY
1707
explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {}
1708
_LIBCPP_INLINE_VISIBILITY
1709
explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
1710
_LIBCPP_INLINE_VISIBILITY
1711
__packaged_task_func(const _Fp& __f, const _Alloc& __a)
1713
_LIBCPP_INLINE_VISIBILITY
1714
__packaged_task_func(_Fp&& __f, const _Alloc& __a)
1715
: __f_(_VSTD::move(__f), __a) {}
1716
virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT;
1717
virtual void destroy();
1718
virtual void destroy_deallocate();
1719
virtual _Rp operator()(_ArgTypes&& ... __args);
1722
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1724
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
1725
__packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT
1727
::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second()));
1730
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1732
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy()
1734
__f_.~__compressed_pair<_Fp, _Alloc>();
1737
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1739
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate()
1741
typedef typename _Alloc::template rebind<__packaged_task_func>::other _Ap;
1742
_Ap __a(__f_.second());
1743
__f_.~__compressed_pair<_Fp, _Alloc>();
1744
__a.deallocate(this, 1);
1747
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1749
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1751
return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1754
template <class _Callable> class __packaged_task_function;
1756
template<class _Rp, class ..._ArgTypes>
1757
class __packaged_task_function<_Rp(_ArgTypes...)>
1759
typedef __packaged_task_base<_Rp(_ArgTypes...)> __base;
1760
typename aligned_storage<3*sizeof(void*)>::type __buf_;
1764
typedef _Rp result_type;
1766
// construct/copy/destroy:
1767
_LIBCPP_INLINE_VISIBILITY
1768
__packaged_task_function() _NOEXCEPT : __f_(nullptr) {}
1770
__packaged_task_function(_Fp&& __f);
1771
template<class _Fp, class _Alloc>
1772
__packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f);
1774
__packaged_task_function(__packaged_task_function&&) _NOEXCEPT;
1775
__packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT;
1777
__packaged_task_function(const __packaged_task_function&) = delete;
1778
__packaged_task_function& operator=(const __packaged_task_function&) = delete;
1780
~__packaged_task_function();
1782
void swap(__packaged_task_function&) _NOEXCEPT;
1784
_Rp operator()(_ArgTypes...) const;
1787
template<class _Rp, class ..._ArgTypes>
1788
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT
1790
if (__f.__f_ == nullptr)
1792
else if (__f.__f_ == (__base*)&__f.__buf_)
1794
__f_ = (__base*)&__buf_;
1795
__f.__f_->__move_to(__f_);
1804
template<class _Rp, class ..._ArgTypes>
1805
template <class _Fp>
1806
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f)
1809
typedef typename remove_reference<_Fp>::type _FR;
1810
typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF;
1811
if (sizeof(_FF) <= sizeof(__buf_))
1813
__f_ = (__base*)&__buf_;
1814
::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
1818
typedef allocator<_FF> _Ap;
1820
typedef __allocator_destructor<_Ap> _Dp;
1821
unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1822
::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a));
1823
__f_ = __hold.release();
1827
template<class _Rp, class ..._ArgTypes>
1828
template <class _Fp, class _Alloc>
1829
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(
1830
allocator_arg_t, const _Alloc& __a0, _Fp&& __f)
1833
typedef allocator_traits<_Alloc> __alloc_traits;
1834
typedef typename remove_reference<_Fp>::type _FR;
1835
typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF;
1836
if (sizeof(_FF) <= sizeof(__buf_))
1838
__f_ = (__base*)&__buf_;
1839
::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
1843
typedef typename __alloc_traits::template
1844
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1847
rebind_alloc<_FF>::other
1851
typedef __allocator_destructor<_Ap> _Dp;
1852
unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1853
::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a));
1854
__f_ = __hold.release();
1858
template<class _Rp, class ..._ArgTypes>
1859
__packaged_task_function<_Rp(_ArgTypes...)>&
1860
__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT
1862
if (__f_ == (__base*)&__buf_)
1865
__f_->destroy_deallocate();
1867
if (__f.__f_ == nullptr)
1869
else if (__f.__f_ == (__base*)&__f.__buf_)
1871
__f_ = (__base*)&__buf_;
1872
__f.__f_->__move_to(__f_);
1882
template<class _Rp, class ..._ArgTypes>
1883
__packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function()
1885
if (__f_ == (__base*)&__buf_)
1888
__f_->destroy_deallocate();
1891
template<class _Rp, class ..._ArgTypes>
1893
__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT
1895
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1897
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1898
__base* __t = (__base*)&__tempbuf;
1899
__f_->__move_to(__t);
1902
__f.__f_->__move_to((__base*)&__buf_);
1903
__f.__f_->destroy();
1905
__f_ = (__base*)&__buf_;
1906
__t->__move_to((__base*)&__f.__buf_);
1908
__f.__f_ = (__base*)&__f.__buf_;
1910
else if (__f_ == (__base*)&__buf_)
1912
__f_->__move_to((__base*)&__f.__buf_);
1915
__f.__f_ = (__base*)&__f.__buf_;
1917
else if (__f.__f_ == (__base*)&__f.__buf_)
1919
__f.__f_->__move_to((__base*)&__buf_);
1920
__f.__f_->destroy();
1922
__f_ = (__base*)&__buf_;
1925
_VSTD::swap(__f_, __f.__f_);
1928
template<class _Rp, class ..._ArgTypes>
1929
inline _LIBCPP_INLINE_VISIBILITY
1931
__packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1933
return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1936
template<class _Rp, class ..._ArgTypes>
1937
class _LIBCPP_TYPE_VIS packaged_task<_Rp(_ArgTypes...)>
1940
typedef _Rp result_type;
1943
__packaged_task_function<result_type(_ArgTypes...)> __f_;
1944
promise<result_type> __p_;
1947
// construction and destruction
1948
_LIBCPP_INLINE_VISIBILITY
1949
packaged_task() _NOEXCEPT : __p_(nullptr) {}
1950
template <class _Fp>
1951
_LIBCPP_INLINE_VISIBILITY
1952
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
1953
template <class _Fp, class _Allocator>
1954
_LIBCPP_INLINE_VISIBILITY
1955
explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
1956
: __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
1957
__p_(allocator_arg, __a) {}
1958
// ~packaged_task() = default;
1961
packaged_task(const packaged_task&) = delete;
1962
packaged_task& operator=(const packaged_task&) = delete;
1965
_LIBCPP_INLINE_VISIBILITY
1966
packaged_task(packaged_task&& __other) _NOEXCEPT
1967
: __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
1968
_LIBCPP_INLINE_VISIBILITY
1969
packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
1971
__f_ = _VSTD::move(__other.__f_);
1972
__p_ = _VSTD::move(__other.__p_);
1975
_LIBCPP_INLINE_VISIBILITY
1976
void swap(packaged_task& __other) _NOEXCEPT
1978
__f_.swap(__other.__f_);
1979
__p_.swap(__other.__p_);
1982
_LIBCPP_INLINE_VISIBILITY
1983
bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
1986
_LIBCPP_INLINE_VISIBILITY
1987
future<result_type> get_future() {return __p_.get_future();}
1990
void operator()(_ArgTypes... __args);
1991
void make_ready_at_thread_exit(_ArgTypes... __args);
1996
template<class _Rp, class ..._ArgTypes>
1998
packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args)
2000
#ifndef _LIBCPP_NO_EXCEPTIONS
2001
if (__p_.__state_ == nullptr)
2002
throw future_error(make_error_code(future_errc::no_state));
2003
if (__p_.__state_->__has_value())
2004
throw future_error(make_error_code(future_errc::promise_already_satisfied));
2007
#endif // _LIBCPP_NO_EXCEPTIONS
2008
__p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...));
2009
#ifndef _LIBCPP_NO_EXCEPTIONS
2013
__p_.set_exception(current_exception());
2015
#endif // _LIBCPP_NO_EXCEPTIONS
2018
template<class _Rp, class ..._ArgTypes>
2020
packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
2022
#ifndef _LIBCPP_NO_EXCEPTIONS
2023
if (__p_.__state_ == nullptr)
2024
throw future_error(make_error_code(future_errc::no_state));
2025
if (__p_.__state_->__has_value())
2026
throw future_error(make_error_code(future_errc::promise_already_satisfied));
2029
#endif // _LIBCPP_NO_EXCEPTIONS
2030
__p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...));
2031
#ifndef _LIBCPP_NO_EXCEPTIONS
2035
__p_.set_exception_at_thread_exit(current_exception());
2037
#endif // _LIBCPP_NO_EXCEPTIONS
2040
template<class _Rp, class ..._ArgTypes>
2042
packaged_task<_Rp(_ArgTypes...)>::reset()
2044
#ifndef _LIBCPP_NO_EXCEPTIONS
2046
throw future_error(make_error_code(future_errc::no_state));
2047
#endif // _LIBCPP_NO_EXCEPTIONS
2048
__p_ = promise<result_type>();
2051
template<class ..._ArgTypes>
2052
class _LIBCPP_TYPE_VIS packaged_task<void(_ArgTypes...)>
2055
typedef void result_type;
2058
__packaged_task_function<result_type(_ArgTypes...)> __f_;
2059
promise<result_type> __p_;
2062
// construction and destruction
2063
_LIBCPP_INLINE_VISIBILITY
2064
packaged_task() _NOEXCEPT : __p_(nullptr) {}
2065
template <class _Fp>
2066
_LIBCPP_INLINE_VISIBILITY
2067
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
2068
template <class _Fp, class _Allocator>
2069
_LIBCPP_INLINE_VISIBILITY
2070
explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
2071
: __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
2072
__p_(allocator_arg, __a) {}
2073
// ~packaged_task() = default;
2076
packaged_task(const packaged_task&) = delete;
2077
packaged_task& operator=(const packaged_task&) = delete;
2080
_LIBCPP_INLINE_VISIBILITY
2081
packaged_task(packaged_task&& __other) _NOEXCEPT
2082
: __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
2083
_LIBCPP_INLINE_VISIBILITY
2084
packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
2086
__f_ = _VSTD::move(__other.__f_);
2087
__p_ = _VSTD::move(__other.__p_);
2090
_LIBCPP_INLINE_VISIBILITY
2091
void swap(packaged_task& __other) _NOEXCEPT
2093
__f_.swap(__other.__f_);
2094
__p_.swap(__other.__p_);
2097
_LIBCPP_INLINE_VISIBILITY
2098
bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
2101
_LIBCPP_INLINE_VISIBILITY
2102
future<result_type> get_future() {return __p_.get_future();}
2105
void operator()(_ArgTypes... __args);
2106
void make_ready_at_thread_exit(_ArgTypes... __args);
2111
template<class ..._ArgTypes>
2113
packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args)
2115
#ifndef _LIBCPP_NO_EXCEPTIONS
2116
if (__p_.__state_ == nullptr)
2117
throw future_error(make_error_code(future_errc::no_state));
2118
if (__p_.__state_->__has_value())
2119
throw future_error(make_error_code(future_errc::promise_already_satisfied));
2122
#endif // _LIBCPP_NO_EXCEPTIONS
2123
__f_(_VSTD::forward<_ArgTypes>(__args)...);
2125
#ifndef _LIBCPP_NO_EXCEPTIONS
2129
__p_.set_exception(current_exception());
2131
#endif // _LIBCPP_NO_EXCEPTIONS
2134
template<class ..._ArgTypes>
2136
packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
2138
#ifndef _LIBCPP_NO_EXCEPTIONS
2139
if (__p_.__state_ == nullptr)
2140
throw future_error(make_error_code(future_errc::no_state));
2141
if (__p_.__state_->__has_value())
2142
throw future_error(make_error_code(future_errc::promise_already_satisfied));
2145
#endif // _LIBCPP_NO_EXCEPTIONS
2146
__f_(_VSTD::forward<_ArgTypes>(__args)...);
2147
__p_.set_value_at_thread_exit();
2148
#ifndef _LIBCPP_NO_EXCEPTIONS
2152
__p_.set_exception_at_thread_exit(current_exception());
2154
#endif // _LIBCPP_NO_EXCEPTIONS
2157
template<class ..._ArgTypes>
2159
packaged_task<void(_ArgTypes...)>::reset()
2161
#ifndef _LIBCPP_NO_EXCEPTIONS
2163
throw future_error(make_error_code(future_errc::no_state));
2164
#endif // _LIBCPP_NO_EXCEPTIONS
2165
__p_ = promise<result_type>();
2168
template <class _Callable>
2169
inline _LIBCPP_INLINE_VISIBILITY
2171
swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT
2176
template <class _Callable, class _Alloc>
2177
struct _LIBCPP_TYPE_VIS uses_allocator<packaged_task<_Callable>, _Alloc>
2178
: public true_type {};
2180
template <class _Rp, class _Fp>
2182
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2183
__make_deferred_assoc_state(_Fp&& __f)
2185
__make_deferred_assoc_state(_Fp __f)
2188
unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count>
2189
__h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
2190
return future<_Rp>(__h.get());
2193
template <class _Rp, class _Fp>
2195
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2196
__make_async_assoc_state(_Fp&& __f)
2198
__make_async_assoc_state(_Fp __f)
2201
unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count>
2202
__h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
2203
_VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
2204
return future<_Rp>(__h.get());
2207
template <class _Fp, class... _Args>
2210
tuple<_Fp, _Args...> __f_;
2213
typedef typename __invoke_of<_Fp, _Args...>::type _Rp;
2215
_LIBCPP_INLINE_VISIBILITY
2216
explicit __async_func(_Fp&& __f, _Args&&... __args)
2217
: __f_(_VSTD::move(__f), _VSTD::move(__args)...) {}
2219
_LIBCPP_INLINE_VISIBILITY
2220
__async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {}
2224
typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index;
2225
return __execute(_Index());
2228
template <size_t ..._Indices>
2230
__execute(__tuple_indices<_Indices...>)
2232
return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
2236
template <class _Fp, class... _Args>
2237
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
2238
async(launch __policy, _Fp&& __f, _Args&&... __args)
2240
typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF;
2241
typedef typename _BF::_Rp _Rp;
2243
if (int(__policy) & int(launch::async))
2244
__r = _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
2245
__decay_copy(_VSTD::forward<_Args>(__args))...));
2246
else if (int(__policy) & int(launch::deferred))
2247
__r = _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
2248
__decay_copy(_VSTD::forward<_Args>(__args))...));
2252
template <class _Fp, class... _Args>
2253
inline _LIBCPP_INLINE_VISIBILITY
2254
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
2255
async(_Fp&& __f, _Args&&... __args)
2257
return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f),
2258
_VSTD::forward<_Args>(__args)...);
2261
#endif // _LIBCPP_HAS_NO_VARIADICS
2265
template <class _Rp>
2266
class _LIBCPP_TYPE_VIS shared_future
2268
__assoc_state<_Rp>* __state_;
2271
_LIBCPP_INLINE_VISIBILITY
2272
shared_future() _NOEXCEPT : __state_(nullptr) {}
2273
_LIBCPP_INLINE_VISIBILITY
2274
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2275
{if (__state_) __state_->__add_shared();}
2276
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2277
_LIBCPP_INLINE_VISIBILITY
2278
shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_)
2279
{__f.__state_ = nullptr;}
2280
_LIBCPP_INLINE_VISIBILITY
2281
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2282
{__rhs.__state_ = nullptr;}
2283
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2285
shared_future& operator=(const shared_future& __rhs);
2286
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2287
_LIBCPP_INLINE_VISIBILITY
2288
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
2290
shared_future(std::move(__rhs)).swap(*this);
2293
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2295
// retrieving the value
2296
_LIBCPP_INLINE_VISIBILITY
2297
const _Rp& get() const {return __state_->copy();}
2299
_LIBCPP_INLINE_VISIBILITY
2300
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
2302
// functions to check state
2303
_LIBCPP_INLINE_VISIBILITY
2304
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
2306
_LIBCPP_INLINE_VISIBILITY
2307
void wait() const {__state_->wait();}
2308
template <class _Rep, class _Period>
2309
_LIBCPP_INLINE_VISIBILITY
2311
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2312
{return __state_->wait_for(__rel_time);}
2313
template <class _Clock, class _Duration>
2314
_LIBCPP_INLINE_VISIBILITY
2316
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2317
{return __state_->wait_until(__abs_time);}
2320
template <class _Rp>
2321
shared_future<_Rp>::~shared_future()
2324
__state_->__release_shared();
2327
template <class _Rp>
2329
shared_future<_Rp>::operator=(const shared_future& __rhs)
2332
__rhs.__state_->__add_shared();
2334
__state_->__release_shared();
2335
__state_ = __rhs.__state_;
2339
template <class _Rp>
2340
class _LIBCPP_TYPE_VIS shared_future<_Rp&>
2342
__assoc_state<_Rp&>* __state_;
2345
_LIBCPP_INLINE_VISIBILITY
2346
shared_future() _NOEXCEPT : __state_(nullptr) {}
2347
_LIBCPP_INLINE_VISIBILITY
2348
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2349
{if (__state_) __state_->__add_shared();}
2350
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2351
_LIBCPP_INLINE_VISIBILITY
2352
shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_)
2353
{__f.__state_ = nullptr;}
2354
_LIBCPP_INLINE_VISIBILITY
2355
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2356
{__rhs.__state_ = nullptr;}
2357
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2359
shared_future& operator=(const shared_future& __rhs);
2360
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2361
_LIBCPP_INLINE_VISIBILITY
2362
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
2364
shared_future(std::move(__rhs)).swap(*this);
2367
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2369
// retrieving the value
2370
_LIBCPP_INLINE_VISIBILITY
2371
_Rp& get() const {return __state_->copy();}
2373
_LIBCPP_INLINE_VISIBILITY
2374
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
2376
// functions to check state
2377
_LIBCPP_INLINE_VISIBILITY
2378
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
2380
_LIBCPP_INLINE_VISIBILITY
2381
void wait() const {__state_->wait();}
2382
template <class _Rep, class _Period>
2383
_LIBCPP_INLINE_VISIBILITY
2385
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2386
{return __state_->wait_for(__rel_time);}
2387
template <class _Clock, class _Duration>
2388
_LIBCPP_INLINE_VISIBILITY
2390
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2391
{return __state_->wait_until(__abs_time);}
2394
template <class _Rp>
2395
shared_future<_Rp&>::~shared_future()
2398
__state_->__release_shared();
2401
template <class _Rp>
2402
shared_future<_Rp&>&
2403
shared_future<_Rp&>::operator=(const shared_future& __rhs)
2406
__rhs.__state_->__add_shared();
2408
__state_->__release_shared();
2409
__state_ = __rhs.__state_;
2414
class _LIBCPP_TYPE_VIS shared_future<void>
2416
__assoc_sub_state* __state_;
2419
_LIBCPP_INLINE_VISIBILITY
2420
shared_future() _NOEXCEPT : __state_(nullptr) {}
2421
_LIBCPP_INLINE_VISIBILITY
2422
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2423
{if (__state_) __state_->__add_shared();}
2424
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2425
_LIBCPP_INLINE_VISIBILITY
2426
shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_)
2427
{__f.__state_ = nullptr;}
2428
_LIBCPP_INLINE_VISIBILITY
2429
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2430
{__rhs.__state_ = nullptr;}
2431
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2433
shared_future& operator=(const shared_future& __rhs);
2434
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2435
_LIBCPP_INLINE_VISIBILITY
2436
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
2438
shared_future(std::move(__rhs)).swap(*this);
2441
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2443
// retrieving the value
2444
_LIBCPP_INLINE_VISIBILITY
2445
void get() const {__state_->copy();}
2447
_LIBCPP_INLINE_VISIBILITY
2448
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
2450
// functions to check state
2451
_LIBCPP_INLINE_VISIBILITY
2452
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
2454
_LIBCPP_INLINE_VISIBILITY
2455
void wait() const {__state_->wait();}
2456
template <class _Rep, class _Period>
2457
_LIBCPP_INLINE_VISIBILITY
2459
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2460
{return __state_->wait_for(__rel_time);}
2461
template <class _Clock, class _Duration>
2462
_LIBCPP_INLINE_VISIBILITY
2464
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2465
{return __state_->wait_until(__abs_time);}
2468
template <class _Rp>
2469
inline _LIBCPP_INLINE_VISIBILITY
2471
swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT
2476
template <class _Rp>
2477
inline _LIBCPP_INLINE_VISIBILITY
2479
future<_Rp>::share()
2481
return shared_future<_Rp>(_VSTD::move(*this));
2484
template <class _Rp>
2485
inline _LIBCPP_INLINE_VISIBILITY
2487
future<_Rp&>::share()
2489
return shared_future<_Rp&>(_VSTD::move(*this));
2492
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2494
inline _LIBCPP_INLINE_VISIBILITY
2496
future<void>::share()
2498
return shared_future<void>(_VSTD::move(*this));
2501
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2503
_LIBCPP_END_NAMESPACE_STD
2505
#endif // _LIBCPP_FUTURE