14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===--------------------------- future -----------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_FUTURE 124684ddb6SLionel Sambuc#define _LIBCPP_FUTURE 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc future synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambucnamespace std 184684ddb6SLionel Sambuc{ 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambucenum class future_errc 214684ddb6SLionel Sambuc{ 224684ddb6SLionel Sambuc future_already_retrieved = 1, 234684ddb6SLionel Sambuc promise_already_satisfied, 244684ddb6SLionel Sambuc no_state, 254684ddb6SLionel Sambuc broken_promise 264684ddb6SLionel Sambuc}; 274684ddb6SLionel Sambuc 284684ddb6SLionel Sambucenum class launch 294684ddb6SLionel Sambuc{ 304684ddb6SLionel Sambuc async = 1, 314684ddb6SLionel Sambuc deferred = 2, 324684ddb6SLionel Sambuc any = async | deferred 334684ddb6SLionel Sambuc}; 344684ddb6SLionel Sambuc 354684ddb6SLionel Sambucenum class future_status 364684ddb6SLionel Sambuc{ 374684ddb6SLionel Sambuc ready, 384684ddb6SLionel Sambuc timeout, 394684ddb6SLionel Sambuc deferred 404684ddb6SLionel Sambuc}; 414684ddb6SLionel Sambuc 424684ddb6SLionel Sambuctemplate <> struct is_error_code_enum<future_errc> : public true_type { }; 434684ddb6SLionel Sambucerror_code make_error_code(future_errc e) noexcept; 444684ddb6SLionel Sambucerror_condition make_error_condition(future_errc e) noexcept; 454684ddb6SLionel Sambuc 464684ddb6SLionel Sambucconst error_category& future_category() noexcept; 474684ddb6SLionel Sambuc 484684ddb6SLionel Sambucclass future_error 494684ddb6SLionel Sambuc : public logic_error 504684ddb6SLionel Sambuc{ 514684ddb6SLionel Sambucpublic: 524684ddb6SLionel Sambuc future_error(error_code ec); // exposition only 534684ddb6SLionel Sambuc 544684ddb6SLionel Sambuc const error_code& code() const noexcept; 554684ddb6SLionel Sambuc const char* what() const noexcept; 564684ddb6SLionel Sambuc}; 574684ddb6SLionel Sambuc 584684ddb6SLionel Sambuctemplate <class R> 594684ddb6SLionel Sambucclass promise 604684ddb6SLionel Sambuc{ 614684ddb6SLionel Sambucpublic: 624684ddb6SLionel Sambuc promise(); 634684ddb6SLionel Sambuc template <class Allocator> 644684ddb6SLionel Sambuc promise(allocator_arg_t, const Allocator& a); 654684ddb6SLionel Sambuc promise(promise&& rhs) noexcept; 664684ddb6SLionel Sambuc promise(const promise& rhs) = delete; 674684ddb6SLionel Sambuc ~promise(); 684684ddb6SLionel Sambuc 694684ddb6SLionel Sambuc // assignment 704684ddb6SLionel Sambuc promise& operator=(promise&& rhs) noexcept; 714684ddb6SLionel Sambuc promise& operator=(const promise& rhs) = delete; 724684ddb6SLionel Sambuc void swap(promise& other) noexcept; 734684ddb6SLionel Sambuc 744684ddb6SLionel Sambuc // retrieving the result 754684ddb6SLionel Sambuc future<R> get_future(); 764684ddb6SLionel Sambuc 774684ddb6SLionel Sambuc // setting the result 784684ddb6SLionel Sambuc void set_value(const R& r); 794684ddb6SLionel Sambuc void set_value(R&& r); 804684ddb6SLionel Sambuc void set_exception(exception_ptr p); 814684ddb6SLionel Sambuc 824684ddb6SLionel Sambuc // setting the result with deferred notification 834684ddb6SLionel Sambuc void set_value_at_thread_exit(const R& r); 844684ddb6SLionel Sambuc void set_value_at_thread_exit(R&& r); 854684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr p); 864684ddb6SLionel Sambuc}; 874684ddb6SLionel Sambuc 884684ddb6SLionel Sambuctemplate <class R> 894684ddb6SLionel Sambucclass promise<R&> 904684ddb6SLionel Sambuc{ 914684ddb6SLionel Sambucpublic: 924684ddb6SLionel Sambuc promise(); 934684ddb6SLionel Sambuc template <class Allocator> 944684ddb6SLionel Sambuc promise(allocator_arg_t, const Allocator& a); 954684ddb6SLionel Sambuc promise(promise&& rhs) noexcept; 964684ddb6SLionel Sambuc promise(const promise& rhs) = delete; 974684ddb6SLionel Sambuc ~promise(); 984684ddb6SLionel Sambuc 994684ddb6SLionel Sambuc // assignment 1004684ddb6SLionel Sambuc promise& operator=(promise&& rhs) noexcept; 1014684ddb6SLionel Sambuc promise& operator=(const promise& rhs) = delete; 1024684ddb6SLionel Sambuc void swap(promise& other) noexcept; 1034684ddb6SLionel Sambuc 1044684ddb6SLionel Sambuc // retrieving the result 1054684ddb6SLionel Sambuc future<R&> get_future(); 1064684ddb6SLionel Sambuc 1074684ddb6SLionel Sambuc // setting the result 1084684ddb6SLionel Sambuc void set_value(R& r); 1094684ddb6SLionel Sambuc void set_exception(exception_ptr p); 1104684ddb6SLionel Sambuc 1114684ddb6SLionel Sambuc // setting the result with deferred notification 1124684ddb6SLionel Sambuc void set_value_at_thread_exit(R&); 1134684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr p); 1144684ddb6SLionel Sambuc}; 1154684ddb6SLionel Sambuc 1164684ddb6SLionel Sambuctemplate <> 1174684ddb6SLionel Sambucclass promise<void> 1184684ddb6SLionel Sambuc{ 1194684ddb6SLionel Sambucpublic: 1204684ddb6SLionel Sambuc promise(); 1214684ddb6SLionel Sambuc template <class Allocator> 1224684ddb6SLionel Sambuc promise(allocator_arg_t, const Allocator& a); 1234684ddb6SLionel Sambuc promise(promise&& rhs) noexcept; 1244684ddb6SLionel Sambuc promise(const promise& rhs) = delete; 1254684ddb6SLionel Sambuc ~promise(); 1264684ddb6SLionel Sambuc 1274684ddb6SLionel Sambuc // assignment 1284684ddb6SLionel Sambuc promise& operator=(promise&& rhs) noexcept; 1294684ddb6SLionel Sambuc promise& operator=(const promise& rhs) = delete; 1304684ddb6SLionel Sambuc void swap(promise& other) noexcept; 1314684ddb6SLionel Sambuc 1324684ddb6SLionel Sambuc // retrieving the result 1334684ddb6SLionel Sambuc future<void> get_future(); 1344684ddb6SLionel Sambuc 1354684ddb6SLionel Sambuc // setting the result 1364684ddb6SLionel Sambuc void set_value(); 1374684ddb6SLionel Sambuc void set_exception(exception_ptr p); 1384684ddb6SLionel Sambuc 1394684ddb6SLionel Sambuc // setting the result with deferred notification 1404684ddb6SLionel Sambuc void set_value_at_thread_exit(); 1414684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr p); 1424684ddb6SLionel Sambuc}; 1434684ddb6SLionel Sambuc 1444684ddb6SLionel Sambuctemplate <class R> void swap(promise<R>& x, promise<R>& y) noexcept; 1454684ddb6SLionel Sambuc 1464684ddb6SLionel Sambuctemplate <class R, class Alloc> 1474684ddb6SLionel Sambuc struct uses_allocator<promise<R>, Alloc> : public true_type {}; 1484684ddb6SLionel Sambuc 1494684ddb6SLionel Sambuctemplate <class R> 1504684ddb6SLionel Sambucclass future 1514684ddb6SLionel Sambuc{ 1524684ddb6SLionel Sambucpublic: 1534684ddb6SLionel Sambuc future() noexcept; 1544684ddb6SLionel Sambuc future(future&&) noexcept; 1554684ddb6SLionel Sambuc future(const future& rhs) = delete; 1564684ddb6SLionel Sambuc ~future(); 1574684ddb6SLionel Sambuc future& operator=(const future& rhs) = delete; 1584684ddb6SLionel Sambuc future& operator=(future&&) noexcept; 1594684ddb6SLionel Sambuc shared_future<R> share(); 1604684ddb6SLionel Sambuc 1614684ddb6SLionel Sambuc // retrieving the value 1624684ddb6SLionel Sambuc R get(); 1634684ddb6SLionel Sambuc 1644684ddb6SLionel Sambuc // functions to check state 1654684ddb6SLionel Sambuc bool valid() const noexcept; 1664684ddb6SLionel Sambuc 1674684ddb6SLionel Sambuc void wait() const; 1684684ddb6SLionel Sambuc template <class Rep, class Period> 1694684ddb6SLionel Sambuc future_status 1704684ddb6SLionel Sambuc wait_for(const chrono::duration<Rep, Period>& rel_time) const; 1714684ddb6SLionel Sambuc template <class Clock, class Duration> 1724684ddb6SLionel Sambuc future_status 1734684ddb6SLionel Sambuc wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; 1744684ddb6SLionel Sambuc}; 1754684ddb6SLionel Sambuc 1764684ddb6SLionel Sambuctemplate <class R> 1774684ddb6SLionel Sambucclass future<R&> 1784684ddb6SLionel Sambuc{ 1794684ddb6SLionel Sambucpublic: 1804684ddb6SLionel Sambuc future() noexcept; 1814684ddb6SLionel Sambuc future(future&&) noexcept; 1824684ddb6SLionel Sambuc future(const future& rhs) = delete; 1834684ddb6SLionel Sambuc ~future(); 1844684ddb6SLionel Sambuc future& operator=(const future& rhs) = delete; 1854684ddb6SLionel Sambuc future& operator=(future&&) noexcept; 1864684ddb6SLionel Sambuc shared_future<R&> share(); 1874684ddb6SLionel Sambuc 1884684ddb6SLionel Sambuc // retrieving the value 1894684ddb6SLionel Sambuc R& get(); 1904684ddb6SLionel Sambuc 1914684ddb6SLionel Sambuc // functions to check state 1924684ddb6SLionel Sambuc bool valid() const noexcept; 1934684ddb6SLionel Sambuc 1944684ddb6SLionel Sambuc void wait() const; 1954684ddb6SLionel Sambuc template <class Rep, class Period> 1964684ddb6SLionel Sambuc future_status 1974684ddb6SLionel Sambuc wait_for(const chrono::duration<Rep, Period>& rel_time) const; 1984684ddb6SLionel Sambuc template <class Clock, class Duration> 1994684ddb6SLionel Sambuc future_status 2004684ddb6SLionel Sambuc wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; 2014684ddb6SLionel Sambuc}; 2024684ddb6SLionel Sambuc 2034684ddb6SLionel Sambuctemplate <> 2044684ddb6SLionel Sambucclass future<void> 2054684ddb6SLionel Sambuc{ 2064684ddb6SLionel Sambucpublic: 2074684ddb6SLionel Sambuc future() noexcept; 2084684ddb6SLionel Sambuc future(future&&) noexcept; 2094684ddb6SLionel Sambuc future(const future& rhs) = delete; 2104684ddb6SLionel Sambuc ~future(); 2114684ddb6SLionel Sambuc future& operator=(const future& rhs) = delete; 2124684ddb6SLionel Sambuc future& operator=(future&&) noexcept; 2134684ddb6SLionel Sambuc shared_future<void> share(); 2144684ddb6SLionel Sambuc 2154684ddb6SLionel Sambuc // retrieving the value 2164684ddb6SLionel Sambuc void get(); 2174684ddb6SLionel Sambuc 2184684ddb6SLionel Sambuc // functions to check state 2194684ddb6SLionel Sambuc bool valid() const noexcept; 2204684ddb6SLionel Sambuc 2214684ddb6SLionel Sambuc void wait() const; 2224684ddb6SLionel Sambuc template <class Rep, class Period> 2234684ddb6SLionel Sambuc future_status 2244684ddb6SLionel Sambuc wait_for(const chrono::duration<Rep, Period>& rel_time) const; 2254684ddb6SLionel Sambuc template <class Clock, class Duration> 2264684ddb6SLionel Sambuc future_status 2274684ddb6SLionel Sambuc wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; 2284684ddb6SLionel Sambuc}; 2294684ddb6SLionel Sambuc 2304684ddb6SLionel Sambuctemplate <class R> 2314684ddb6SLionel Sambucclass shared_future 2324684ddb6SLionel Sambuc{ 2334684ddb6SLionel Sambucpublic: 2344684ddb6SLionel Sambuc shared_future() noexcept; 2354684ddb6SLionel Sambuc shared_future(const shared_future& rhs); 2364684ddb6SLionel Sambuc shared_future(future<R>&&) noexcept; 2374684ddb6SLionel Sambuc shared_future(shared_future&& rhs) noexcept; 2384684ddb6SLionel Sambuc ~shared_future(); 2394684ddb6SLionel Sambuc shared_future& operator=(const shared_future& rhs); 2404684ddb6SLionel Sambuc shared_future& operator=(shared_future&& rhs) noexcept; 2414684ddb6SLionel Sambuc 2424684ddb6SLionel Sambuc // retrieving the value 2434684ddb6SLionel Sambuc const R& get() const; 2444684ddb6SLionel Sambuc 2454684ddb6SLionel Sambuc // functions to check state 2464684ddb6SLionel Sambuc bool valid() const noexcept; 2474684ddb6SLionel Sambuc 2484684ddb6SLionel Sambuc void wait() const; 2494684ddb6SLionel Sambuc template <class Rep, class Period> 2504684ddb6SLionel Sambuc future_status 2514684ddb6SLionel Sambuc wait_for(const chrono::duration<Rep, Period>& rel_time) const; 2524684ddb6SLionel Sambuc template <class Clock, class Duration> 2534684ddb6SLionel Sambuc future_status 2544684ddb6SLionel Sambuc wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; 2554684ddb6SLionel Sambuc}; 2564684ddb6SLionel Sambuc 2574684ddb6SLionel Sambuctemplate <class R> 2584684ddb6SLionel Sambucclass shared_future<R&> 2594684ddb6SLionel Sambuc{ 2604684ddb6SLionel Sambucpublic: 2614684ddb6SLionel Sambuc shared_future() noexcept; 2624684ddb6SLionel Sambuc shared_future(const shared_future& rhs); 2634684ddb6SLionel Sambuc shared_future(future<R&>&&) noexcept; 2644684ddb6SLionel Sambuc shared_future(shared_future&& rhs) noexcept; 2654684ddb6SLionel Sambuc ~shared_future(); 2664684ddb6SLionel Sambuc shared_future& operator=(const shared_future& rhs); 2674684ddb6SLionel Sambuc shared_future& operator=(shared_future&& rhs) noexcept; 2684684ddb6SLionel Sambuc 2694684ddb6SLionel Sambuc // retrieving the value 2704684ddb6SLionel Sambuc R& get() const; 2714684ddb6SLionel Sambuc 2724684ddb6SLionel Sambuc // functions to check state 2734684ddb6SLionel Sambuc bool valid() const noexcept; 2744684ddb6SLionel Sambuc 2754684ddb6SLionel Sambuc void wait() const; 2764684ddb6SLionel Sambuc template <class Rep, class Period> 2774684ddb6SLionel Sambuc future_status 2784684ddb6SLionel Sambuc wait_for(const chrono::duration<Rep, Period>& rel_time) const; 2794684ddb6SLionel Sambuc template <class Clock, class Duration> 2804684ddb6SLionel Sambuc future_status 2814684ddb6SLionel Sambuc wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; 2824684ddb6SLionel Sambuc}; 2834684ddb6SLionel Sambuc 2844684ddb6SLionel Sambuctemplate <> 2854684ddb6SLionel Sambucclass shared_future<void> 2864684ddb6SLionel Sambuc{ 2874684ddb6SLionel Sambucpublic: 2884684ddb6SLionel Sambuc shared_future() noexcept; 2894684ddb6SLionel Sambuc shared_future(const shared_future& rhs); 2904684ddb6SLionel Sambuc shared_future(future<void>&&) noexcept; 2914684ddb6SLionel Sambuc shared_future(shared_future&& rhs) noexcept; 2924684ddb6SLionel Sambuc ~shared_future(); 2934684ddb6SLionel Sambuc shared_future& operator=(const shared_future& rhs); 2944684ddb6SLionel Sambuc shared_future& operator=(shared_future&& rhs) noexcept; 2954684ddb6SLionel Sambuc 2964684ddb6SLionel Sambuc // retrieving the value 2974684ddb6SLionel Sambuc void get() const; 2984684ddb6SLionel Sambuc 2994684ddb6SLionel Sambuc // functions to check state 3004684ddb6SLionel Sambuc bool valid() const noexcept; 3014684ddb6SLionel Sambuc 3024684ddb6SLionel Sambuc void wait() const; 3034684ddb6SLionel Sambuc template <class Rep, class Period> 3044684ddb6SLionel Sambuc future_status 3054684ddb6SLionel Sambuc wait_for(const chrono::duration<Rep, Period>& rel_time) const; 3064684ddb6SLionel Sambuc template <class Clock, class Duration> 3074684ddb6SLionel Sambuc future_status 3084684ddb6SLionel Sambuc wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; 3094684ddb6SLionel Sambuc}; 3104684ddb6SLionel Sambuc 3114684ddb6SLionel Sambuctemplate <class F, class... Args> 3124684ddb6SLionel Sambuc future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> 3134684ddb6SLionel Sambuc async(F&& f, Args&&... args); 3144684ddb6SLionel Sambuc 3154684ddb6SLionel Sambuctemplate <class F, class... Args> 3164684ddb6SLionel Sambuc future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> 3174684ddb6SLionel Sambuc async(launch policy, F&& f, Args&&... args); 3184684ddb6SLionel Sambuc 3194684ddb6SLionel Sambuctemplate <class> class packaged_task; // undefined 3204684ddb6SLionel Sambuc 3214684ddb6SLionel Sambuctemplate <class R, class... ArgTypes> 3224684ddb6SLionel Sambucclass packaged_task<R(ArgTypes...)> 3234684ddb6SLionel Sambuc{ 3244684ddb6SLionel Sambucpublic: 3254684ddb6SLionel Sambuc typedef R result_type; 3264684ddb6SLionel Sambuc 3274684ddb6SLionel Sambuc // construction and destruction 3284684ddb6SLionel Sambuc packaged_task() noexcept; 3294684ddb6SLionel Sambuc template <class F> 3304684ddb6SLionel Sambuc explicit packaged_task(F&& f); 3314684ddb6SLionel Sambuc template <class F, class Allocator> 332*0a6a1f1dSLionel Sambuc packaged_task(allocator_arg_t, const Allocator& a, F&& f); 3334684ddb6SLionel Sambuc ~packaged_task(); 3344684ddb6SLionel Sambuc 3354684ddb6SLionel Sambuc // no copy 3364684ddb6SLionel Sambuc packaged_task(const packaged_task&) = delete; 3374684ddb6SLionel Sambuc packaged_task& operator=(const packaged_task&) = delete; 3384684ddb6SLionel Sambuc 3394684ddb6SLionel Sambuc // move support 3404684ddb6SLionel Sambuc packaged_task(packaged_task&& other) noexcept; 3414684ddb6SLionel Sambuc packaged_task& operator=(packaged_task&& other) noexcept; 3424684ddb6SLionel Sambuc void swap(packaged_task& other) noexcept; 3434684ddb6SLionel Sambuc 3444684ddb6SLionel Sambuc bool valid() const noexcept; 3454684ddb6SLionel Sambuc 3464684ddb6SLionel Sambuc // result retrieval 3474684ddb6SLionel Sambuc future<R> get_future(); 3484684ddb6SLionel Sambuc 3494684ddb6SLionel Sambuc // execution 3504684ddb6SLionel Sambuc void operator()(ArgTypes... ); 3514684ddb6SLionel Sambuc void make_ready_at_thread_exit(ArgTypes...); 3524684ddb6SLionel Sambuc 3534684ddb6SLionel Sambuc void reset(); 3544684ddb6SLionel Sambuc}; 3554684ddb6SLionel Sambuc 3564684ddb6SLionel Sambuctemplate <class R> 3574684ddb6SLionel Sambuc void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept; 3584684ddb6SLionel Sambuc 3594684ddb6SLionel Sambuctemplate <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>; 3604684ddb6SLionel Sambuc 3614684ddb6SLionel Sambuc} // std 3624684ddb6SLionel Sambuc 3634684ddb6SLionel Sambuc*/ 3644684ddb6SLionel Sambuc 3654684ddb6SLionel Sambuc#include <__config> 3664684ddb6SLionel Sambuc#include <system_error> 3674684ddb6SLionel Sambuc#include <memory> 3684684ddb6SLionel Sambuc#include <chrono> 3694684ddb6SLionel Sambuc#include <exception> 3704684ddb6SLionel Sambuc#include <mutex> 3714684ddb6SLionel Sambuc#include <thread> 3724684ddb6SLionel Sambuc 3734684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 3744684ddb6SLionel Sambuc#pragma GCC system_header 3754684ddb6SLionel Sambuc#endif 3764684ddb6SLionel Sambuc 377*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_NO_THREADS 378*0a6a1f1dSLionel Sambuc#error <future> is not supported on this single threaded system 379*0a6a1f1dSLionel Sambuc#else // !_LIBCPP_HAS_NO_THREADS 380*0a6a1f1dSLionel Sambuc 3814684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 3824684ddb6SLionel Sambuc 3834684ddb6SLionel Sambuc//enum class future_errc 3844684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM(future_errc) 3854684ddb6SLionel Sambuc{ 3864684ddb6SLionel Sambuc future_already_retrieved = 1, 3874684ddb6SLionel Sambuc promise_already_satisfied, 3884684ddb6SLionel Sambuc no_state, 3894684ddb6SLionel Sambuc broken_promise 3904684ddb6SLionel Sambuc}; 3914684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc) 3924684ddb6SLionel Sambuc 3934684ddb6SLionel Sambuctemplate <> 3944684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc> : public true_type {}; 3954684ddb6SLionel Sambuc 3964684ddb6SLionel Sambuc#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS 3974684ddb6SLionel Sambuctemplate <> 3984684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc::__lx> : public true_type { }; 3994684ddb6SLionel Sambuc#endif 4004684ddb6SLionel Sambuc 4014684ddb6SLionel Sambuc//enum class launch 4024684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM(launch) 4034684ddb6SLionel Sambuc{ 4044684ddb6SLionel Sambuc async = 1, 4054684ddb6SLionel Sambuc deferred = 2, 4064684ddb6SLionel Sambuc any = async | deferred 4074684ddb6SLionel Sambuc}; 4084684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) 4094684ddb6SLionel Sambuc 4104684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS 4114684ddb6SLionel Sambuc 4124684ddb6SLionel Sambuc#ifdef _LIBCXX_UNDERLYING_TYPE 4134684ddb6SLionel Sambuctypedef underlying_type<launch>::type __launch_underlying_type; 4144684ddb6SLionel Sambuc#else 4154684ddb6SLionel Sambuctypedef int __launch_underlying_type; 4164684ddb6SLionel Sambuc#endif 4174684ddb6SLionel Sambuc 4184684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4194684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR 4204684ddb6SLionel Sambuclaunch 4214684ddb6SLionel Sambucoperator&(launch __x, launch __y) 4224684ddb6SLionel Sambuc{ 4234684ddb6SLionel Sambuc return static_cast<launch>(static_cast<__launch_underlying_type>(__x) & 4244684ddb6SLionel Sambuc static_cast<__launch_underlying_type>(__y)); 4254684ddb6SLionel Sambuc} 4264684ddb6SLionel Sambuc 4274684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4284684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR 4294684ddb6SLionel Sambuclaunch 4304684ddb6SLionel Sambucoperator|(launch __x, launch __y) 4314684ddb6SLionel Sambuc{ 4324684ddb6SLionel Sambuc return static_cast<launch>(static_cast<__launch_underlying_type>(__x) | 4334684ddb6SLionel Sambuc static_cast<__launch_underlying_type>(__y)); 4344684ddb6SLionel Sambuc} 4354684ddb6SLionel Sambuc 4364684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4374684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR 4384684ddb6SLionel Sambuclaunch 4394684ddb6SLionel Sambucoperator^(launch __x, launch __y) 4404684ddb6SLionel Sambuc{ 4414684ddb6SLionel Sambuc return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^ 4424684ddb6SLionel Sambuc static_cast<__launch_underlying_type>(__y)); 4434684ddb6SLionel Sambuc} 4444684ddb6SLionel Sambuc 4454684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4464684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR 4474684ddb6SLionel Sambuclaunch 4484684ddb6SLionel Sambucoperator~(launch __x) 4494684ddb6SLionel Sambuc{ 4504684ddb6SLionel Sambuc return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3); 4514684ddb6SLionel Sambuc} 4524684ddb6SLionel Sambuc 4534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4544684ddb6SLionel Sambuclaunch& 4554684ddb6SLionel Sambucoperator&=(launch& __x, launch __y) 4564684ddb6SLionel Sambuc{ 4574684ddb6SLionel Sambuc __x = __x & __y; return __x; 4584684ddb6SLionel Sambuc} 4594684ddb6SLionel Sambuc 4604684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4614684ddb6SLionel Sambuclaunch& 4624684ddb6SLionel Sambucoperator|=(launch& __x, launch __y) 4634684ddb6SLionel Sambuc{ 4644684ddb6SLionel Sambuc __x = __x | __y; return __x; 4654684ddb6SLionel Sambuc} 4664684ddb6SLionel Sambuc 4674684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4684684ddb6SLionel Sambuclaunch& 4694684ddb6SLionel Sambucoperator^=(launch& __x, launch __y) 4704684ddb6SLionel Sambuc{ 4714684ddb6SLionel Sambuc __x = __x ^ __y; return __x; 4724684ddb6SLionel Sambuc} 4734684ddb6SLionel Sambuc 4744684ddb6SLionel Sambuc#endif // !_LIBCPP_HAS_NO_STRONG_ENUMS 4754684ddb6SLionel Sambuc 4764684ddb6SLionel Sambuc//enum class future_status 4774684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM(future_status) 4784684ddb6SLionel Sambuc{ 4794684ddb6SLionel Sambuc ready, 4804684ddb6SLionel Sambuc timeout, 4814684ddb6SLionel Sambuc deferred 4824684ddb6SLionel Sambuc}; 4834684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status) 4844684ddb6SLionel Sambuc 4854684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS 4864684ddb6SLionel Sambucconst error_category& future_category() _NOEXCEPT; 4874684ddb6SLionel Sambuc 4884684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4894684ddb6SLionel Sambucerror_code 4904684ddb6SLionel Sambucmake_error_code(future_errc __e) _NOEXCEPT 4914684ddb6SLionel Sambuc{ 4924684ddb6SLionel Sambuc return error_code(static_cast<int>(__e), future_category()); 4934684ddb6SLionel Sambuc} 4944684ddb6SLionel Sambuc 4954684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4964684ddb6SLionel Sambucerror_condition 4974684ddb6SLionel Sambucmake_error_condition(future_errc __e) _NOEXCEPT 4984684ddb6SLionel Sambuc{ 4994684ddb6SLionel Sambuc return error_condition(static_cast<int>(__e), future_category()); 5004684ddb6SLionel Sambuc} 5014684ddb6SLionel Sambuc 5024684ddb6SLionel Sambucclass _LIBCPP_EXCEPTION_ABI future_error 5034684ddb6SLionel Sambuc : public logic_error 5044684ddb6SLionel Sambuc{ 5054684ddb6SLionel Sambuc error_code __ec_; 5064684ddb6SLionel Sambucpublic: 5074684ddb6SLionel Sambuc future_error(error_code __ec); 5084684ddb6SLionel Sambuc 5094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5104684ddb6SLionel Sambuc const error_code& code() const _NOEXCEPT {return __ec_;} 5114684ddb6SLionel Sambuc 5124684ddb6SLionel Sambuc virtual ~future_error() _NOEXCEPT; 5134684ddb6SLionel Sambuc}; 5144684ddb6SLionel Sambuc 5154684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS __assoc_sub_state 5164684ddb6SLionel Sambuc : public __shared_count 5174684ddb6SLionel Sambuc{ 5184684ddb6SLionel Sambucprotected: 5194684ddb6SLionel Sambuc exception_ptr __exception_; 5204684ddb6SLionel Sambuc mutable mutex __mut_; 5214684ddb6SLionel Sambuc mutable condition_variable __cv_; 5224684ddb6SLionel Sambuc unsigned __state_; 5234684ddb6SLionel Sambuc 5244684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 5254684ddb6SLionel Sambuc void __sub_wait(unique_lock<mutex>& __lk); 5264684ddb6SLionel Sambucpublic: 5274684ddb6SLionel Sambuc enum 5284684ddb6SLionel Sambuc { 5294684ddb6SLionel Sambuc __constructed = 1, 5304684ddb6SLionel Sambuc __future_attached = 2, 5314684ddb6SLionel Sambuc ready = 4, 5324684ddb6SLionel Sambuc deferred = 8 5334684ddb6SLionel Sambuc }; 5344684ddb6SLionel Sambuc 5354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5364684ddb6SLionel Sambuc __assoc_sub_state() : __state_(0) {} 5374684ddb6SLionel Sambuc 5384684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5394684ddb6SLionel Sambuc bool __has_value() const 5404684ddb6SLionel Sambuc {return (__state_ & __constructed) || (__exception_ != nullptr);} 5414684ddb6SLionel Sambuc 5424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5434684ddb6SLionel Sambuc void __set_future_attached() 5444684ddb6SLionel Sambuc { 5454684ddb6SLionel Sambuc lock_guard<mutex> __lk(__mut_); 5464684ddb6SLionel Sambuc __state_ |= __future_attached; 5474684ddb6SLionel Sambuc } 5484684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5494684ddb6SLionel Sambuc bool __has_future_attached() const {return (__state_ & __future_attached) != 0;} 5504684ddb6SLionel Sambuc 5514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5524684ddb6SLionel Sambuc void __set_deferred() {__state_ |= deferred;} 5534684ddb6SLionel Sambuc 5544684ddb6SLionel Sambuc void __make_ready(); 5554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5564684ddb6SLionel Sambuc bool __is_ready() const {return (__state_ & ready) != 0;} 5574684ddb6SLionel Sambuc 5584684ddb6SLionel Sambuc void set_value(); 5594684ddb6SLionel Sambuc void set_value_at_thread_exit(); 5604684ddb6SLionel Sambuc 5614684ddb6SLionel Sambuc void set_exception(exception_ptr __p); 5624684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr __p); 5634684ddb6SLionel Sambuc 5644684ddb6SLionel Sambuc void copy(); 5654684ddb6SLionel Sambuc 5664684ddb6SLionel Sambuc void wait(); 5674684ddb6SLionel Sambuc template <class _Rep, class _Period> 5684684ddb6SLionel Sambuc future_status 5694684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const; 5704684ddb6SLionel Sambuc template <class _Clock, class _Duration> 5714684ddb6SLionel Sambuc future_status 5724684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const; 5734684ddb6SLionel Sambuc 5744684ddb6SLionel Sambuc virtual void __execute(); 5754684ddb6SLionel Sambuc}; 5764684ddb6SLionel Sambuc 5774684ddb6SLionel Sambuctemplate <class _Clock, class _Duration> 5784684ddb6SLionel Sambucfuture_status 5794684ddb6SLionel Sambuc__assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 5804684ddb6SLionel Sambuc{ 5814684ddb6SLionel Sambuc unique_lock<mutex> __lk(__mut_); 5824684ddb6SLionel Sambuc if (__state_ & deferred) 5834684ddb6SLionel Sambuc return future_status::deferred; 5844684ddb6SLionel Sambuc while (!(__state_ & ready) && _Clock::now() < __abs_time) 5854684ddb6SLionel Sambuc __cv_.wait_until(__lk, __abs_time); 5864684ddb6SLionel Sambuc if (__state_ & ready) 5874684ddb6SLionel Sambuc return future_status::ready; 5884684ddb6SLionel Sambuc return future_status::timeout; 5894684ddb6SLionel Sambuc} 5904684ddb6SLionel Sambuc 5914684ddb6SLionel Sambuctemplate <class _Rep, class _Period> 5924684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 5934684ddb6SLionel Sambucfuture_status 5944684ddb6SLionel Sambuc__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 5954684ddb6SLionel Sambuc{ 5964684ddb6SLionel Sambuc return wait_until(chrono::steady_clock::now() + __rel_time); 5974684ddb6SLionel Sambuc} 5984684ddb6SLionel Sambuc 5994684ddb6SLionel Sambuctemplate <class _Rp> 6004684ddb6SLionel Sambucclass __assoc_state 6014684ddb6SLionel Sambuc : public __assoc_sub_state 6024684ddb6SLionel Sambuc{ 6034684ddb6SLionel Sambuc typedef __assoc_sub_state base; 6044684ddb6SLionel Sambuc typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up; 6054684ddb6SLionel Sambucprotected: 6064684ddb6SLionel Sambuc _Up __value_; 6074684ddb6SLionel Sambuc 6084684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 6094684ddb6SLionel Sambucpublic: 6104684ddb6SLionel Sambuc 6114684ddb6SLionel Sambuc template <class _Arg> 6124684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 6134684ddb6SLionel Sambuc void set_value(_Arg&& __arg); 6144684ddb6SLionel Sambuc#else 6154684ddb6SLionel Sambuc void set_value(_Arg& __arg); 6164684ddb6SLionel Sambuc#endif 6174684ddb6SLionel Sambuc 6184684ddb6SLionel Sambuc template <class _Arg> 6194684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 6204684ddb6SLionel Sambuc void set_value_at_thread_exit(_Arg&& __arg); 6214684ddb6SLionel Sambuc#else 6224684ddb6SLionel Sambuc void set_value_at_thread_exit(_Arg& __arg); 6234684ddb6SLionel Sambuc#endif 6244684ddb6SLionel Sambuc 6254684ddb6SLionel Sambuc _Rp move(); 6264684ddb6SLionel Sambuc typename add_lvalue_reference<_Rp>::type copy(); 6274684ddb6SLionel Sambuc}; 6284684ddb6SLionel Sambuc 6294684ddb6SLionel Sambuctemplate <class _Rp> 6304684ddb6SLionel Sambucvoid 6314684ddb6SLionel Sambuc__assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT 6324684ddb6SLionel Sambuc{ 6334684ddb6SLionel Sambuc if (this->__state_ & base::__constructed) 6344684ddb6SLionel Sambuc reinterpret_cast<_Rp*>(&__value_)->~_Rp(); 6354684ddb6SLionel Sambuc delete this; 6364684ddb6SLionel Sambuc} 6374684ddb6SLionel Sambuc 6384684ddb6SLionel Sambuctemplate <class _Rp> 6394684ddb6SLionel Sambuctemplate <class _Arg> 6404684ddb6SLionel Sambucvoid 6414684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 6424684ddb6SLionel Sambuc__assoc_state<_Rp>::set_value(_Arg&& __arg) 6434684ddb6SLionel Sambuc#else 6444684ddb6SLionel Sambuc__assoc_state<_Rp>::set_value(_Arg& __arg) 6454684ddb6SLionel Sambuc#endif 6464684ddb6SLionel Sambuc{ 6474684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 6484684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 6494684ddb6SLionel Sambuc if (this->__has_value()) 6504684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 6514684ddb6SLionel Sambuc#endif 6524684ddb6SLionel Sambuc ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); 6534684ddb6SLionel Sambuc this->__state_ |= base::__constructed | base::ready; 6544684ddb6SLionel Sambuc __cv_.notify_all(); 6554684ddb6SLionel Sambuc} 6564684ddb6SLionel Sambuc 6574684ddb6SLionel Sambuctemplate <class _Rp> 6584684ddb6SLionel Sambuctemplate <class _Arg> 6594684ddb6SLionel Sambucvoid 6604684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 6614684ddb6SLionel Sambuc__assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg) 6624684ddb6SLionel Sambuc#else 6634684ddb6SLionel Sambuc__assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg) 6644684ddb6SLionel Sambuc#endif 6654684ddb6SLionel Sambuc{ 6664684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 6674684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 6684684ddb6SLionel Sambuc if (this->__has_value()) 6694684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 6704684ddb6SLionel Sambuc#endif 6714684ddb6SLionel Sambuc ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); 6724684ddb6SLionel Sambuc this->__state_ |= base::__constructed; 6734684ddb6SLionel Sambuc __thread_local_data()->__make_ready_at_thread_exit(this); 6744684ddb6SLionel Sambuc} 6754684ddb6SLionel Sambuc 6764684ddb6SLionel Sambuctemplate <class _Rp> 6774684ddb6SLionel Sambuc_Rp 6784684ddb6SLionel Sambuc__assoc_state<_Rp>::move() 6794684ddb6SLionel Sambuc{ 6804684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 6814684ddb6SLionel Sambuc this->__sub_wait(__lk); 6824684ddb6SLionel Sambuc if (this->__exception_ != nullptr) 6834684ddb6SLionel Sambuc rethrow_exception(this->__exception_); 6844684ddb6SLionel Sambuc return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_)); 6854684ddb6SLionel Sambuc} 6864684ddb6SLionel Sambuc 6874684ddb6SLionel Sambuctemplate <class _Rp> 6884684ddb6SLionel Sambuctypename add_lvalue_reference<_Rp>::type 6894684ddb6SLionel Sambuc__assoc_state<_Rp>::copy() 6904684ddb6SLionel Sambuc{ 6914684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 6924684ddb6SLionel Sambuc this->__sub_wait(__lk); 6934684ddb6SLionel Sambuc if (this->__exception_ != nullptr) 6944684ddb6SLionel Sambuc rethrow_exception(this->__exception_); 6954684ddb6SLionel Sambuc return *reinterpret_cast<_Rp*>(&__value_); 6964684ddb6SLionel Sambuc} 6974684ddb6SLionel Sambuc 6984684ddb6SLionel Sambuctemplate <class _Rp> 6994684ddb6SLionel Sambucclass __assoc_state<_Rp&> 7004684ddb6SLionel Sambuc : public __assoc_sub_state 7014684ddb6SLionel Sambuc{ 7024684ddb6SLionel Sambuc typedef __assoc_sub_state base; 7034684ddb6SLionel Sambuc typedef _Rp* _Up; 7044684ddb6SLionel Sambucprotected: 7054684ddb6SLionel Sambuc _Up __value_; 7064684ddb6SLionel Sambuc 7074684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 7084684ddb6SLionel Sambucpublic: 7094684ddb6SLionel Sambuc 7104684ddb6SLionel Sambuc void set_value(_Rp& __arg); 7114684ddb6SLionel Sambuc void set_value_at_thread_exit(_Rp& __arg); 7124684ddb6SLionel Sambuc 7134684ddb6SLionel Sambuc _Rp& copy(); 7144684ddb6SLionel Sambuc}; 7154684ddb6SLionel Sambuc 7164684ddb6SLionel Sambuctemplate <class _Rp> 7174684ddb6SLionel Sambucvoid 7184684ddb6SLionel Sambuc__assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT 7194684ddb6SLionel Sambuc{ 7204684ddb6SLionel Sambuc delete this; 7214684ddb6SLionel Sambuc} 7224684ddb6SLionel Sambuc 7234684ddb6SLionel Sambuctemplate <class _Rp> 7244684ddb6SLionel Sambucvoid 7254684ddb6SLionel Sambuc__assoc_state<_Rp&>::set_value(_Rp& __arg) 7264684ddb6SLionel Sambuc{ 7274684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 7284684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 7294684ddb6SLionel Sambuc if (this->__has_value()) 7304684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 7314684ddb6SLionel Sambuc#endif 7324684ddb6SLionel Sambuc __value_ = _VSTD::addressof(__arg); 7334684ddb6SLionel Sambuc this->__state_ |= base::__constructed | base::ready; 7344684ddb6SLionel Sambuc __cv_.notify_all(); 7354684ddb6SLionel Sambuc} 7364684ddb6SLionel Sambuc 7374684ddb6SLionel Sambuctemplate <class _Rp> 7384684ddb6SLionel Sambucvoid 7394684ddb6SLionel Sambuc__assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg) 7404684ddb6SLionel Sambuc{ 7414684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 7424684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 7434684ddb6SLionel Sambuc if (this->__has_value()) 7444684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 7454684ddb6SLionel Sambuc#endif 7464684ddb6SLionel Sambuc __value_ = _VSTD::addressof(__arg); 7474684ddb6SLionel Sambuc this->__state_ |= base::__constructed; 7484684ddb6SLionel Sambuc __thread_local_data()->__make_ready_at_thread_exit(this); 7494684ddb6SLionel Sambuc} 7504684ddb6SLionel Sambuc 7514684ddb6SLionel Sambuctemplate <class _Rp> 7524684ddb6SLionel Sambuc_Rp& 7534684ddb6SLionel Sambuc__assoc_state<_Rp&>::copy() 7544684ddb6SLionel Sambuc{ 7554684ddb6SLionel Sambuc unique_lock<mutex> __lk(this->__mut_); 7564684ddb6SLionel Sambuc this->__sub_wait(__lk); 7574684ddb6SLionel Sambuc if (this->__exception_ != nullptr) 7584684ddb6SLionel Sambuc rethrow_exception(this->__exception_); 7594684ddb6SLionel Sambuc return *__value_; 7604684ddb6SLionel Sambuc} 7614684ddb6SLionel Sambuc 7624684ddb6SLionel Sambuctemplate <class _Rp, class _Alloc> 7634684ddb6SLionel Sambucclass __assoc_state_alloc 7644684ddb6SLionel Sambuc : public __assoc_state<_Rp> 7654684ddb6SLionel Sambuc{ 7664684ddb6SLionel Sambuc typedef __assoc_state<_Rp> base; 7674684ddb6SLionel Sambuc _Alloc __alloc_; 7684684ddb6SLionel Sambuc 7694684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 7704684ddb6SLionel Sambucpublic: 7714684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7724684ddb6SLionel Sambuc explicit __assoc_state_alloc(const _Alloc& __a) 7734684ddb6SLionel Sambuc : __alloc_(__a) {} 7744684ddb6SLionel Sambuc}; 7754684ddb6SLionel Sambuc 7764684ddb6SLionel Sambuctemplate <class _Rp, class _Alloc> 7774684ddb6SLionel Sambucvoid 7784684ddb6SLionel Sambuc__assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT 7794684ddb6SLionel Sambuc{ 7804684ddb6SLionel Sambuc if (this->__state_ & base::__constructed) 7814684ddb6SLionel Sambuc reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp(); 782*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; 783*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Al> _ATraits; 784*0a6a1f1dSLionel Sambuc typedef pointer_traits<typename _ATraits::pointer> _PTraits; 785*0a6a1f1dSLionel Sambuc _Al __a(__alloc_); 7864684ddb6SLionel Sambuc this->~__assoc_state_alloc(); 787*0a6a1f1dSLionel Sambuc __a.deallocate(_PTraits::pointer_to(*this), 1); 7884684ddb6SLionel Sambuc} 7894684ddb6SLionel Sambuc 7904684ddb6SLionel Sambuctemplate <class _Rp, class _Alloc> 7914684ddb6SLionel Sambucclass __assoc_state_alloc<_Rp&, _Alloc> 7924684ddb6SLionel Sambuc : public __assoc_state<_Rp&> 7934684ddb6SLionel Sambuc{ 7944684ddb6SLionel Sambuc typedef __assoc_state<_Rp&> base; 7954684ddb6SLionel Sambuc _Alloc __alloc_; 7964684ddb6SLionel Sambuc 7974684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 7984684ddb6SLionel Sambucpublic: 7994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 8004684ddb6SLionel Sambuc explicit __assoc_state_alloc(const _Alloc& __a) 8014684ddb6SLionel Sambuc : __alloc_(__a) {} 8024684ddb6SLionel Sambuc}; 8034684ddb6SLionel Sambuc 8044684ddb6SLionel Sambuctemplate <class _Rp, class _Alloc> 8054684ddb6SLionel Sambucvoid 8064684ddb6SLionel Sambuc__assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT 8074684ddb6SLionel Sambuc{ 808*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; 809*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Al> _ATraits; 810*0a6a1f1dSLionel Sambuc typedef pointer_traits<typename _ATraits::pointer> _PTraits; 811*0a6a1f1dSLionel Sambuc _Al __a(__alloc_); 8124684ddb6SLionel Sambuc this->~__assoc_state_alloc(); 813*0a6a1f1dSLionel Sambuc __a.deallocate(_PTraits::pointer_to(*this), 1); 8144684ddb6SLionel Sambuc} 8154684ddb6SLionel Sambuc 8164684ddb6SLionel Sambuctemplate <class _Alloc> 8174684ddb6SLionel Sambucclass __assoc_sub_state_alloc 8184684ddb6SLionel Sambuc : public __assoc_sub_state 8194684ddb6SLionel Sambuc{ 8204684ddb6SLionel Sambuc typedef __assoc_sub_state base; 8214684ddb6SLionel Sambuc _Alloc __alloc_; 8224684ddb6SLionel Sambuc 8234684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 8244684ddb6SLionel Sambucpublic: 8254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 8264684ddb6SLionel Sambuc explicit __assoc_sub_state_alloc(const _Alloc& __a) 8274684ddb6SLionel Sambuc : __alloc_(__a) {} 8284684ddb6SLionel Sambuc}; 8294684ddb6SLionel Sambuc 8304684ddb6SLionel Sambuctemplate <class _Alloc> 8314684ddb6SLionel Sambucvoid 8324684ddb6SLionel Sambuc__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT 8334684ddb6SLionel Sambuc{ 834*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _Al; 835*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Al> _ATraits; 836*0a6a1f1dSLionel Sambuc typedef pointer_traits<typename _ATraits::pointer> _PTraits; 837*0a6a1f1dSLionel Sambuc _Al __a(__alloc_); 8384684ddb6SLionel Sambuc this->~__assoc_sub_state_alloc(); 839*0a6a1f1dSLionel Sambuc __a.deallocate(_PTraits::pointer_to(*this), 1); 8404684ddb6SLionel Sambuc} 8414684ddb6SLionel Sambuc 8424684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 8434684ddb6SLionel Sambucclass __deferred_assoc_state 8444684ddb6SLionel Sambuc : public __assoc_state<_Rp> 8454684ddb6SLionel Sambuc{ 8464684ddb6SLionel Sambuc typedef __assoc_state<_Rp> base; 8474684ddb6SLionel Sambuc 8484684ddb6SLionel Sambuc _Fp __func_; 8494684ddb6SLionel Sambuc 8504684ddb6SLionel Sambucpublic: 8514684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 8524684ddb6SLionel Sambuc explicit __deferred_assoc_state(_Fp&& __f); 8534684ddb6SLionel Sambuc#endif 8544684ddb6SLionel Sambuc 8554684ddb6SLionel Sambuc virtual void __execute(); 8564684ddb6SLionel Sambuc}; 8574684ddb6SLionel Sambuc 8584684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 8594684ddb6SLionel Sambuc 8604684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 8614684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 8624684ddb6SLionel Sambuc__deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f) 8634684ddb6SLionel Sambuc : __func_(_VSTD::forward<_Fp>(__f)) 8644684ddb6SLionel Sambuc{ 8654684ddb6SLionel Sambuc this->__set_deferred(); 8664684ddb6SLionel Sambuc} 8674684ddb6SLionel Sambuc 8684684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 8694684ddb6SLionel Sambuc 8704684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 8714684ddb6SLionel Sambucvoid 8724684ddb6SLionel Sambuc__deferred_assoc_state<_Rp, _Fp>::__execute() 8734684ddb6SLionel Sambuc{ 8744684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 8754684ddb6SLionel Sambuc try 8764684ddb6SLionel Sambuc { 8774684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 8784684ddb6SLionel Sambuc this->set_value(__func_()); 8794684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 8804684ddb6SLionel Sambuc } 8814684ddb6SLionel Sambuc catch (...) 8824684ddb6SLionel Sambuc { 8834684ddb6SLionel Sambuc this->set_exception(current_exception()); 8844684ddb6SLionel Sambuc } 8854684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 8864684ddb6SLionel Sambuc} 8874684ddb6SLionel Sambuc 8884684ddb6SLionel Sambuctemplate <class _Fp> 8894684ddb6SLionel Sambucclass __deferred_assoc_state<void, _Fp> 8904684ddb6SLionel Sambuc : public __assoc_sub_state 8914684ddb6SLionel Sambuc{ 8924684ddb6SLionel Sambuc typedef __assoc_sub_state base; 8934684ddb6SLionel Sambuc 8944684ddb6SLionel Sambuc _Fp __func_; 8954684ddb6SLionel Sambuc 8964684ddb6SLionel Sambucpublic: 8974684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 8984684ddb6SLionel Sambuc explicit __deferred_assoc_state(_Fp&& __f); 8994684ddb6SLionel Sambuc#endif 9004684ddb6SLionel Sambuc 9014684ddb6SLionel Sambuc virtual void __execute(); 9024684ddb6SLionel Sambuc}; 9034684ddb6SLionel Sambuc 9044684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 9054684ddb6SLionel Sambuc 9064684ddb6SLionel Sambuctemplate <class _Fp> 9074684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 9084684ddb6SLionel Sambuc__deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f) 9094684ddb6SLionel Sambuc : __func_(_VSTD::forward<_Fp>(__f)) 9104684ddb6SLionel Sambuc{ 9114684ddb6SLionel Sambuc this->__set_deferred(); 9124684ddb6SLionel Sambuc} 9134684ddb6SLionel Sambuc 9144684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 9154684ddb6SLionel Sambuc 9164684ddb6SLionel Sambuctemplate <class _Fp> 9174684ddb6SLionel Sambucvoid 9184684ddb6SLionel Sambuc__deferred_assoc_state<void, _Fp>::__execute() 9194684ddb6SLionel Sambuc{ 9204684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 9214684ddb6SLionel Sambuc try 9224684ddb6SLionel Sambuc { 9234684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 9244684ddb6SLionel Sambuc __func_(); 9254684ddb6SLionel Sambuc this->set_value(); 9264684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 9274684ddb6SLionel Sambuc } 9284684ddb6SLionel Sambuc catch (...) 9294684ddb6SLionel Sambuc { 9304684ddb6SLionel Sambuc this->set_exception(current_exception()); 9314684ddb6SLionel Sambuc } 9324684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 9334684ddb6SLionel Sambuc} 9344684ddb6SLionel Sambuc 9354684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 9364684ddb6SLionel Sambucclass __async_assoc_state 9374684ddb6SLionel Sambuc : public __assoc_state<_Rp> 9384684ddb6SLionel Sambuc{ 9394684ddb6SLionel Sambuc typedef __assoc_state<_Rp> base; 9404684ddb6SLionel Sambuc 9414684ddb6SLionel Sambuc _Fp __func_; 9424684ddb6SLionel Sambuc 9434684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 9444684ddb6SLionel Sambucpublic: 9454684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 9464684ddb6SLionel Sambuc explicit __async_assoc_state(_Fp&& __f); 9474684ddb6SLionel Sambuc#endif 9484684ddb6SLionel Sambuc 9494684ddb6SLionel Sambuc virtual void __execute(); 9504684ddb6SLionel Sambuc}; 9514684ddb6SLionel Sambuc 9524684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 9534684ddb6SLionel Sambuc 9544684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 9554684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 9564684ddb6SLionel Sambuc__async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f) 9574684ddb6SLionel Sambuc : __func_(_VSTD::forward<_Fp>(__f)) 9584684ddb6SLionel Sambuc{ 9594684ddb6SLionel Sambuc} 9604684ddb6SLionel Sambuc 9614684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 9624684ddb6SLionel Sambuc 9634684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 9644684ddb6SLionel Sambucvoid 9654684ddb6SLionel Sambuc__async_assoc_state<_Rp, _Fp>::__execute() 9664684ddb6SLionel Sambuc{ 9674684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 9684684ddb6SLionel Sambuc try 9694684ddb6SLionel Sambuc { 9704684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 9714684ddb6SLionel Sambuc this->set_value(__func_()); 9724684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 9734684ddb6SLionel Sambuc } 9744684ddb6SLionel Sambuc catch (...) 9754684ddb6SLionel Sambuc { 9764684ddb6SLionel Sambuc this->set_exception(current_exception()); 9774684ddb6SLionel Sambuc } 9784684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 9794684ddb6SLionel Sambuc} 9804684ddb6SLionel Sambuc 9814684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 9824684ddb6SLionel Sambucvoid 9834684ddb6SLionel Sambuc__async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT 9844684ddb6SLionel Sambuc{ 9854684ddb6SLionel Sambuc this->wait(); 9864684ddb6SLionel Sambuc base::__on_zero_shared(); 9874684ddb6SLionel Sambuc} 9884684ddb6SLionel Sambuc 9894684ddb6SLionel Sambuctemplate <class _Fp> 9904684ddb6SLionel Sambucclass __async_assoc_state<void, _Fp> 9914684ddb6SLionel Sambuc : public __assoc_sub_state 9924684ddb6SLionel Sambuc{ 9934684ddb6SLionel Sambuc typedef __assoc_sub_state base; 9944684ddb6SLionel Sambuc 9954684ddb6SLionel Sambuc _Fp __func_; 9964684ddb6SLionel Sambuc 9974684ddb6SLionel Sambuc virtual void __on_zero_shared() _NOEXCEPT; 9984684ddb6SLionel Sambucpublic: 9994684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10004684ddb6SLionel Sambuc explicit __async_assoc_state(_Fp&& __f); 10014684ddb6SLionel Sambuc#endif 10024684ddb6SLionel Sambuc 10034684ddb6SLionel Sambuc virtual void __execute(); 10044684ddb6SLionel Sambuc}; 10054684ddb6SLionel Sambuc 10064684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10074684ddb6SLionel Sambuc 10084684ddb6SLionel Sambuctemplate <class _Fp> 10094684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10104684ddb6SLionel Sambuc__async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f) 10114684ddb6SLionel Sambuc : __func_(_VSTD::forward<_Fp>(__f)) 10124684ddb6SLionel Sambuc{ 10134684ddb6SLionel Sambuc} 10144684ddb6SLionel Sambuc 10154684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 10164684ddb6SLionel Sambuc 10174684ddb6SLionel Sambuctemplate <class _Fp> 10184684ddb6SLionel Sambucvoid 10194684ddb6SLionel Sambuc__async_assoc_state<void, _Fp>::__execute() 10204684ddb6SLionel Sambuc{ 10214684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 10224684ddb6SLionel Sambuc try 10234684ddb6SLionel Sambuc { 10244684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 10254684ddb6SLionel Sambuc __func_(); 10264684ddb6SLionel Sambuc this->set_value(); 10274684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 10284684ddb6SLionel Sambuc } 10294684ddb6SLionel Sambuc catch (...) 10304684ddb6SLionel Sambuc { 10314684ddb6SLionel Sambuc this->set_exception(current_exception()); 10324684ddb6SLionel Sambuc } 10334684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 10344684ddb6SLionel Sambuc} 10354684ddb6SLionel Sambuc 10364684ddb6SLionel Sambuctemplate <class _Fp> 10374684ddb6SLionel Sambucvoid 10384684ddb6SLionel Sambuc__async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT 10394684ddb6SLionel Sambuc{ 10404684ddb6SLionel Sambuc this->wait(); 10414684ddb6SLionel Sambuc base::__on_zero_shared(); 10424684ddb6SLionel Sambuc} 10434684ddb6SLionel Sambuc 10444684ddb6SLionel Sambuctemplate <class _Rp> class _LIBCPP_TYPE_VIS_ONLY promise; 10454684ddb6SLionel Sambuctemplate <class _Rp> class _LIBCPP_TYPE_VIS_ONLY shared_future; 10464684ddb6SLionel Sambuc 10474684ddb6SLionel Sambuc// future 10484684ddb6SLionel Sambuc 10494684ddb6SLionel Sambuctemplate <class _Rp> class _LIBCPP_TYPE_VIS_ONLY future; 10504684ddb6SLionel Sambuc 10514684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 10524684ddb6SLionel Sambucfuture<_Rp> 10534684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10544684ddb6SLionel Sambuc__make_deferred_assoc_state(_Fp&& __f); 10554684ddb6SLionel Sambuc#else 10564684ddb6SLionel Sambuc__make_deferred_assoc_state(_Fp __f); 10574684ddb6SLionel Sambuc#endif 10584684ddb6SLionel Sambuc 10594684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 10604684ddb6SLionel Sambucfuture<_Rp> 10614684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10624684ddb6SLionel Sambuc__make_async_assoc_state(_Fp&& __f); 10634684ddb6SLionel Sambuc#else 10644684ddb6SLionel Sambuc__make_async_assoc_state(_Fp __f); 10654684ddb6SLionel Sambuc#endif 10664684ddb6SLionel Sambuc 10674684ddb6SLionel Sambuctemplate <class _Rp> 10684684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY future 10694684ddb6SLionel Sambuc{ 10704684ddb6SLionel Sambuc __assoc_state<_Rp>* __state_; 10714684ddb6SLionel Sambuc 10724684ddb6SLionel Sambuc explicit future(__assoc_state<_Rp>* __state); 10734684ddb6SLionel Sambuc 10744684ddb6SLionel Sambuc template <class> friend class promise; 10754684ddb6SLionel Sambuc template <class> friend class shared_future; 10764684ddb6SLionel Sambuc 10774684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10784684ddb6SLionel Sambuc template <class _R1, class _Fp> 10794684ddb6SLionel Sambuc friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); 10804684ddb6SLionel Sambuc template <class _R1, class _Fp> 10814684ddb6SLionel Sambuc friend future<_R1> __make_async_assoc_state(_Fp&& __f); 10824684ddb6SLionel Sambuc#else 10834684ddb6SLionel Sambuc template <class _R1, class _Fp> 10844684ddb6SLionel Sambuc friend future<_R1> __make_deferred_assoc_state(_Fp __f); 10854684ddb6SLionel Sambuc template <class _R1, class _Fp> 10864684ddb6SLionel Sambuc friend future<_R1> __make_async_assoc_state(_Fp __f); 10874684ddb6SLionel Sambuc#endif 10884684ddb6SLionel Sambuc 10894684ddb6SLionel Sambucpublic: 10904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 10914684ddb6SLionel Sambuc future() _NOEXCEPT : __state_(nullptr) {} 10924684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 10944684ddb6SLionel Sambuc future(future&& __rhs) _NOEXCEPT 10954684ddb6SLionel Sambuc : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} 10964684ddb6SLionel Sambuc future(const future&) = delete; 10974684ddb6SLionel Sambuc future& operator=(const future&) = delete; 10984684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 10994684ddb6SLionel Sambuc future& operator=(future&& __rhs) _NOEXCEPT 11004684ddb6SLionel Sambuc { 11014684ddb6SLionel Sambuc future(std::move(__rhs)).swap(*this); 11024684ddb6SLionel Sambuc return *this; 11034684ddb6SLionel Sambuc } 11044684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 11054684ddb6SLionel Sambucprivate: 11064684ddb6SLionel Sambuc future(const future&); 11074684ddb6SLionel Sambuc future& operator=(const future&); 11084684ddb6SLionel Sambucpublic: 11094684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 11104684ddb6SLionel Sambuc ~future(); 11114684ddb6SLionel Sambuc shared_future<_Rp> share(); 11124684ddb6SLionel Sambuc 11134684ddb6SLionel Sambuc // retrieving the value 11144684ddb6SLionel Sambuc _Rp get(); 11154684ddb6SLionel Sambuc 11164684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11174684ddb6SLionel Sambuc void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 11184684ddb6SLionel Sambuc 11194684ddb6SLionel Sambuc // functions to check state 11204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11214684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __state_ != nullptr;} 11224684ddb6SLionel Sambuc 11234684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11244684ddb6SLionel Sambuc void wait() const {__state_->wait();} 11254684ddb6SLionel Sambuc template <class _Rep, class _Period> 11264684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11274684ddb6SLionel Sambuc future_status 11284684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 11294684ddb6SLionel Sambuc {return __state_->wait_for(__rel_time);} 11304684ddb6SLionel Sambuc template <class _Clock, class _Duration> 11314684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11324684ddb6SLionel Sambuc future_status 11334684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 11344684ddb6SLionel Sambuc {return __state_->wait_until(__abs_time);} 11354684ddb6SLionel Sambuc}; 11364684ddb6SLionel Sambuc 11374684ddb6SLionel Sambuctemplate <class _Rp> 11384684ddb6SLionel Sambucfuture<_Rp>::future(__assoc_state<_Rp>* __state) 11394684ddb6SLionel Sambuc : __state_(__state) 11404684ddb6SLionel Sambuc{ 11414684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 11424684ddb6SLionel Sambuc if (__state_->__has_future_attached()) 11434684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::future_already_retrieved)); 11444684ddb6SLionel Sambuc#endif 11454684ddb6SLionel Sambuc __state_->__add_shared(); 11464684ddb6SLionel Sambuc __state_->__set_future_attached(); 11474684ddb6SLionel Sambuc} 11484684ddb6SLionel Sambuc 11494684ddb6SLionel Sambucstruct __release_shared_count 11504684ddb6SLionel Sambuc{ 11514684ddb6SLionel Sambuc void operator()(__shared_count* p) {p->__release_shared();} 11524684ddb6SLionel Sambuc}; 11534684ddb6SLionel Sambuc 11544684ddb6SLionel Sambuctemplate <class _Rp> 11554684ddb6SLionel Sambucfuture<_Rp>::~future() 11564684ddb6SLionel Sambuc{ 11574684ddb6SLionel Sambuc if (__state_) 11584684ddb6SLionel Sambuc __state_->__release_shared(); 11594684ddb6SLionel Sambuc} 11604684ddb6SLionel Sambuc 11614684ddb6SLionel Sambuctemplate <class _Rp> 11624684ddb6SLionel Sambuc_Rp 11634684ddb6SLionel Sambucfuture<_Rp>::get() 11644684ddb6SLionel Sambuc{ 11654684ddb6SLionel Sambuc unique_ptr<__shared_count, __release_shared_count> __(__state_); 11664684ddb6SLionel Sambuc __assoc_state<_Rp>* __s = __state_; 11674684ddb6SLionel Sambuc __state_ = nullptr; 11684684ddb6SLionel Sambuc return __s->move(); 11694684ddb6SLionel Sambuc} 11704684ddb6SLionel Sambuc 11714684ddb6SLionel Sambuctemplate <class _Rp> 11724684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY future<_Rp&> 11734684ddb6SLionel Sambuc{ 11744684ddb6SLionel Sambuc __assoc_state<_Rp&>* __state_; 11754684ddb6SLionel Sambuc 11764684ddb6SLionel Sambuc explicit future(__assoc_state<_Rp&>* __state); 11774684ddb6SLionel Sambuc 11784684ddb6SLionel Sambuc template <class> friend class promise; 11794684ddb6SLionel Sambuc template <class> friend class shared_future; 11804684ddb6SLionel Sambuc 11814684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 11824684ddb6SLionel Sambuc template <class _R1, class _Fp> 11834684ddb6SLionel Sambuc friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); 11844684ddb6SLionel Sambuc template <class _R1, class _Fp> 11854684ddb6SLionel Sambuc friend future<_R1> __make_async_assoc_state(_Fp&& __f); 11864684ddb6SLionel Sambuc#else 11874684ddb6SLionel Sambuc template <class _R1, class _Fp> 11884684ddb6SLionel Sambuc friend future<_R1> __make_deferred_assoc_state(_Fp __f); 11894684ddb6SLionel Sambuc template <class _R1, class _Fp> 11904684ddb6SLionel Sambuc friend future<_R1> __make_async_assoc_state(_Fp __f); 11914684ddb6SLionel Sambuc#endif 11924684ddb6SLionel Sambuc 11934684ddb6SLionel Sambucpublic: 11944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11954684ddb6SLionel Sambuc future() _NOEXCEPT : __state_(nullptr) {} 11964684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 11974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11984684ddb6SLionel Sambuc future(future&& __rhs) _NOEXCEPT 11994684ddb6SLionel Sambuc : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} 12004684ddb6SLionel Sambuc future(const future&) = delete; 12014684ddb6SLionel Sambuc future& operator=(const future&) = delete; 12024684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12034684ddb6SLionel Sambuc future& operator=(future&& __rhs) _NOEXCEPT 12044684ddb6SLionel Sambuc { 12054684ddb6SLionel Sambuc future(std::move(__rhs)).swap(*this); 12064684ddb6SLionel Sambuc return *this; 12074684ddb6SLionel Sambuc } 12084684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 12094684ddb6SLionel Sambucprivate: 12104684ddb6SLionel Sambuc future(const future&); 12114684ddb6SLionel Sambuc future& operator=(const future&); 12124684ddb6SLionel Sambucpublic: 12134684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 12144684ddb6SLionel Sambuc ~future(); 12154684ddb6SLionel Sambuc shared_future<_Rp&> share(); 12164684ddb6SLionel Sambuc 12174684ddb6SLionel Sambuc // retrieving the value 12184684ddb6SLionel Sambuc _Rp& get(); 12194684ddb6SLionel Sambuc 12204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12214684ddb6SLionel Sambuc void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 12224684ddb6SLionel Sambuc 12234684ddb6SLionel Sambuc // functions to check state 12244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12254684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __state_ != nullptr;} 12264684ddb6SLionel Sambuc 12274684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12284684ddb6SLionel Sambuc void wait() const {__state_->wait();} 12294684ddb6SLionel Sambuc template <class _Rep, class _Period> 12304684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12314684ddb6SLionel Sambuc future_status 12324684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 12334684ddb6SLionel Sambuc {return __state_->wait_for(__rel_time);} 12344684ddb6SLionel Sambuc template <class _Clock, class _Duration> 12354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12364684ddb6SLionel Sambuc future_status 12374684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 12384684ddb6SLionel Sambuc {return __state_->wait_until(__abs_time);} 12394684ddb6SLionel Sambuc}; 12404684ddb6SLionel Sambuc 12414684ddb6SLionel Sambuctemplate <class _Rp> 12424684ddb6SLionel Sambucfuture<_Rp&>::future(__assoc_state<_Rp&>* __state) 12434684ddb6SLionel Sambuc : __state_(__state) 12444684ddb6SLionel Sambuc{ 12454684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 12464684ddb6SLionel Sambuc if (__state_->__has_future_attached()) 12474684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::future_already_retrieved)); 12484684ddb6SLionel Sambuc#endif 12494684ddb6SLionel Sambuc __state_->__add_shared(); 12504684ddb6SLionel Sambuc __state_->__set_future_attached(); 12514684ddb6SLionel Sambuc} 12524684ddb6SLionel Sambuc 12534684ddb6SLionel Sambuctemplate <class _Rp> 12544684ddb6SLionel Sambucfuture<_Rp&>::~future() 12554684ddb6SLionel Sambuc{ 12564684ddb6SLionel Sambuc if (__state_) 12574684ddb6SLionel Sambuc __state_->__release_shared(); 12584684ddb6SLionel Sambuc} 12594684ddb6SLionel Sambuc 12604684ddb6SLionel Sambuctemplate <class _Rp> 12614684ddb6SLionel Sambuc_Rp& 12624684ddb6SLionel Sambucfuture<_Rp&>::get() 12634684ddb6SLionel Sambuc{ 12644684ddb6SLionel Sambuc unique_ptr<__shared_count, __release_shared_count> __(__state_); 12654684ddb6SLionel Sambuc __assoc_state<_Rp&>* __s = __state_; 12664684ddb6SLionel Sambuc __state_ = nullptr; 12674684ddb6SLionel Sambuc return __s->copy(); 12684684ddb6SLionel Sambuc} 12694684ddb6SLionel Sambuc 12704684ddb6SLionel Sambuctemplate <> 12714684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS future<void> 12724684ddb6SLionel Sambuc{ 12734684ddb6SLionel Sambuc __assoc_sub_state* __state_; 12744684ddb6SLionel Sambuc 12754684ddb6SLionel Sambuc explicit future(__assoc_sub_state* __state); 12764684ddb6SLionel Sambuc 12774684ddb6SLionel Sambuc template <class> friend class promise; 12784684ddb6SLionel Sambuc template <class> friend class shared_future; 12794684ddb6SLionel Sambuc 12804684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 12814684ddb6SLionel Sambuc template <class _R1, class _Fp> 12824684ddb6SLionel Sambuc friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); 12834684ddb6SLionel Sambuc template <class _R1, class _Fp> 12844684ddb6SLionel Sambuc friend future<_R1> __make_async_assoc_state(_Fp&& __f); 12854684ddb6SLionel Sambuc#else 12864684ddb6SLionel Sambuc template <class _R1, class _Fp> 12874684ddb6SLionel Sambuc friend future<_R1> __make_deferred_assoc_state(_Fp __f); 12884684ddb6SLionel Sambuc template <class _R1, class _Fp> 12894684ddb6SLionel Sambuc friend future<_R1> __make_async_assoc_state(_Fp __f); 12904684ddb6SLionel Sambuc#endif 12914684ddb6SLionel Sambuc 12924684ddb6SLionel Sambucpublic: 12934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12944684ddb6SLionel Sambuc future() _NOEXCEPT : __state_(nullptr) {} 12954684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 12964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12974684ddb6SLionel Sambuc future(future&& __rhs) _NOEXCEPT 12984684ddb6SLionel Sambuc : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} 12994684ddb6SLionel Sambuc future(const future&) = delete; 13004684ddb6SLionel Sambuc future& operator=(const future&) = delete; 13014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13024684ddb6SLionel Sambuc future& operator=(future&& __rhs) _NOEXCEPT 13034684ddb6SLionel Sambuc { 13044684ddb6SLionel Sambuc future(std::move(__rhs)).swap(*this); 13054684ddb6SLionel Sambuc return *this; 13064684ddb6SLionel Sambuc } 13074684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13084684ddb6SLionel Sambucprivate: 13094684ddb6SLionel Sambuc future(const future&); 13104684ddb6SLionel Sambuc future& operator=(const future&); 13114684ddb6SLionel Sambucpublic: 13124684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13134684ddb6SLionel Sambuc ~future(); 13144684ddb6SLionel Sambuc shared_future<void> share(); 13154684ddb6SLionel Sambuc 13164684ddb6SLionel Sambuc // retrieving the value 13174684ddb6SLionel Sambuc void get(); 13184684ddb6SLionel Sambuc 13194684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13204684ddb6SLionel Sambuc void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 13214684ddb6SLionel Sambuc 13224684ddb6SLionel Sambuc // functions to check state 13234684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13244684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __state_ != nullptr;} 13254684ddb6SLionel Sambuc 13264684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13274684ddb6SLionel Sambuc void wait() const {__state_->wait();} 13284684ddb6SLionel Sambuc template <class _Rep, class _Period> 13294684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13304684ddb6SLionel Sambuc future_status 13314684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 13324684ddb6SLionel Sambuc {return __state_->wait_for(__rel_time);} 13334684ddb6SLionel Sambuc template <class _Clock, class _Duration> 13344684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13354684ddb6SLionel Sambuc future_status 13364684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 13374684ddb6SLionel Sambuc {return __state_->wait_until(__abs_time);} 13384684ddb6SLionel Sambuc}; 13394684ddb6SLionel Sambuc 13404684ddb6SLionel Sambuctemplate <class _Rp> 13414684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13424684ddb6SLionel Sambucvoid 13434684ddb6SLionel Sambucswap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT 13444684ddb6SLionel Sambuc{ 13454684ddb6SLionel Sambuc __x.swap(__y); 13464684ddb6SLionel Sambuc} 13474684ddb6SLionel Sambuc 13484684ddb6SLionel Sambuc// promise<R> 13494684ddb6SLionel Sambuc 13504684ddb6SLionel Sambuctemplate <class _Callable> class packaged_task; 13514684ddb6SLionel Sambuc 13524684ddb6SLionel Sambuctemplate <class _Rp> 13534684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY promise 13544684ddb6SLionel Sambuc{ 13554684ddb6SLionel Sambuc __assoc_state<_Rp>* __state_; 13564684ddb6SLionel Sambuc 13574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13584684ddb6SLionel Sambuc explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} 13594684ddb6SLionel Sambuc 13604684ddb6SLionel Sambuc template <class> friend class packaged_task; 13614684ddb6SLionel Sambucpublic: 13624684ddb6SLionel Sambuc promise(); 13634684ddb6SLionel Sambuc template <class _Alloc> 13644684ddb6SLionel Sambuc promise(allocator_arg_t, const _Alloc& __a); 13654684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 13664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13674684ddb6SLionel Sambuc promise(promise&& __rhs) _NOEXCEPT 13684684ddb6SLionel Sambuc : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} 13694684ddb6SLionel Sambuc promise(const promise& __rhs) = delete; 13704684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13714684ddb6SLionel Sambucprivate: 13724684ddb6SLionel Sambuc promise(const promise& __rhs); 13734684ddb6SLionel Sambucpublic: 13744684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13754684ddb6SLionel Sambuc ~promise(); 13764684ddb6SLionel Sambuc 13774684ddb6SLionel Sambuc // assignment 13784684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 13794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13804684ddb6SLionel Sambuc promise& operator=(promise&& __rhs) _NOEXCEPT 13814684ddb6SLionel Sambuc { 13824684ddb6SLionel Sambuc promise(std::move(__rhs)).swap(*this); 13834684ddb6SLionel Sambuc return *this; 13844684ddb6SLionel Sambuc } 13854684ddb6SLionel Sambuc promise& operator=(const promise& __rhs) = delete; 13864684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13874684ddb6SLionel Sambucprivate: 13884684ddb6SLionel Sambuc promise& operator=(const promise& __rhs); 13894684ddb6SLionel Sambucpublic: 13904684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13924684ddb6SLionel Sambuc void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 13934684ddb6SLionel Sambuc 13944684ddb6SLionel Sambuc // retrieving the result 13954684ddb6SLionel Sambuc future<_Rp> get_future(); 13964684ddb6SLionel Sambuc 13974684ddb6SLionel Sambuc // setting the result 13984684ddb6SLionel Sambuc void set_value(const _Rp& __r); 13994684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 14004684ddb6SLionel Sambuc void set_value(_Rp&& __r); 14014684ddb6SLionel Sambuc#endif 14024684ddb6SLionel Sambuc void set_exception(exception_ptr __p); 14034684ddb6SLionel Sambuc 14044684ddb6SLionel Sambuc // setting the result with deferred notification 14054684ddb6SLionel Sambuc void set_value_at_thread_exit(const _Rp& __r); 14064684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 14074684ddb6SLionel Sambuc void set_value_at_thread_exit(_Rp&& __r); 14084684ddb6SLionel Sambuc#endif 14094684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr __p); 14104684ddb6SLionel Sambuc}; 14114684ddb6SLionel Sambuc 14124684ddb6SLionel Sambuctemplate <class _Rp> 14134684ddb6SLionel Sambucpromise<_Rp>::promise() 14144684ddb6SLionel Sambuc : __state_(new __assoc_state<_Rp>) 14154684ddb6SLionel Sambuc{ 14164684ddb6SLionel Sambuc} 14174684ddb6SLionel Sambuc 14184684ddb6SLionel Sambuctemplate <class _Rp> 14194684ddb6SLionel Sambuctemplate <class _Alloc> 14204684ddb6SLionel Sambucpromise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) 14214684ddb6SLionel Sambuc{ 1422*0a6a1f1dSLionel Sambuc typedef __assoc_state_alloc<_Rp, _Alloc> _State; 1423*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; 14244684ddb6SLionel Sambuc typedef __allocator_destructor<_A2> _D2; 14254684ddb6SLionel Sambuc _A2 __a(__a0); 1426*0a6a1f1dSLionel Sambuc unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); 1427*0a6a1f1dSLionel Sambuc ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); 1428*0a6a1f1dSLionel Sambuc __state_ = _VSTD::addressof(*__hold.release()); 14294684ddb6SLionel Sambuc} 14304684ddb6SLionel Sambuc 14314684ddb6SLionel Sambuctemplate <class _Rp> 14324684ddb6SLionel Sambucpromise<_Rp>::~promise() 14334684ddb6SLionel Sambuc{ 14344684ddb6SLionel Sambuc if (__state_) 14354684ddb6SLionel Sambuc { 14364684ddb6SLionel Sambuc if (!__state_->__has_value() && __state_->use_count() > 1) 14374684ddb6SLionel Sambuc __state_->set_exception(make_exception_ptr( 14384684ddb6SLionel Sambuc future_error(make_error_code(future_errc::broken_promise)) 14394684ddb6SLionel Sambuc )); 14404684ddb6SLionel Sambuc __state_->__release_shared(); 14414684ddb6SLionel Sambuc } 14424684ddb6SLionel Sambuc} 14434684ddb6SLionel Sambuc 14444684ddb6SLionel Sambuctemplate <class _Rp> 14454684ddb6SLionel Sambucfuture<_Rp> 14464684ddb6SLionel Sambucpromise<_Rp>::get_future() 14474684ddb6SLionel Sambuc{ 14484684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 14494684ddb6SLionel Sambuc if (__state_ == nullptr) 14504684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 14514684ddb6SLionel Sambuc#endif 14524684ddb6SLionel Sambuc return future<_Rp>(__state_); 14534684ddb6SLionel Sambuc} 14544684ddb6SLionel Sambuc 14554684ddb6SLionel Sambuctemplate <class _Rp> 14564684ddb6SLionel Sambucvoid 14574684ddb6SLionel Sambucpromise<_Rp>::set_value(const _Rp& __r) 14584684ddb6SLionel Sambuc{ 14594684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 14604684ddb6SLionel Sambuc if (__state_ == nullptr) 14614684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 14624684ddb6SLionel Sambuc#endif 14634684ddb6SLionel Sambuc __state_->set_value(__r); 14644684ddb6SLionel Sambuc} 14654684ddb6SLionel Sambuc 14664684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 14674684ddb6SLionel Sambuc 14684684ddb6SLionel Sambuctemplate <class _Rp> 14694684ddb6SLionel Sambucvoid 14704684ddb6SLionel Sambucpromise<_Rp>::set_value(_Rp&& __r) 14714684ddb6SLionel Sambuc{ 14724684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 14734684ddb6SLionel Sambuc if (__state_ == nullptr) 14744684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 14754684ddb6SLionel Sambuc#endif 14764684ddb6SLionel Sambuc __state_->set_value(_VSTD::move(__r)); 14774684ddb6SLionel Sambuc} 14784684ddb6SLionel Sambuc 14794684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 14804684ddb6SLionel Sambuc 14814684ddb6SLionel Sambuctemplate <class _Rp> 14824684ddb6SLionel Sambucvoid 14834684ddb6SLionel Sambucpromise<_Rp>::set_exception(exception_ptr __p) 14844684ddb6SLionel Sambuc{ 14854684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 14864684ddb6SLionel Sambuc if (__state_ == nullptr) 14874684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 14884684ddb6SLionel Sambuc#endif 14894684ddb6SLionel Sambuc __state_->set_exception(__p); 14904684ddb6SLionel Sambuc} 14914684ddb6SLionel Sambuc 14924684ddb6SLionel Sambuctemplate <class _Rp> 14934684ddb6SLionel Sambucvoid 14944684ddb6SLionel Sambucpromise<_Rp>::set_value_at_thread_exit(const _Rp& __r) 14954684ddb6SLionel Sambuc{ 14964684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 14974684ddb6SLionel Sambuc if (__state_ == nullptr) 14984684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 14994684ddb6SLionel Sambuc#endif 15004684ddb6SLionel Sambuc __state_->set_value_at_thread_exit(__r); 15014684ddb6SLionel Sambuc} 15024684ddb6SLionel Sambuc 15034684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 15044684ddb6SLionel Sambuc 15054684ddb6SLionel Sambuctemplate <class _Rp> 15064684ddb6SLionel Sambucvoid 15074684ddb6SLionel Sambucpromise<_Rp>::set_value_at_thread_exit(_Rp&& __r) 15084684ddb6SLionel Sambuc{ 15094684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 15104684ddb6SLionel Sambuc if (__state_ == nullptr) 15114684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 15124684ddb6SLionel Sambuc#endif 15134684ddb6SLionel Sambuc __state_->set_value_at_thread_exit(_VSTD::move(__r)); 15144684ddb6SLionel Sambuc} 15154684ddb6SLionel Sambuc 15164684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 15174684ddb6SLionel Sambuc 15184684ddb6SLionel Sambuctemplate <class _Rp> 15194684ddb6SLionel Sambucvoid 15204684ddb6SLionel Sambucpromise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) 15214684ddb6SLionel Sambuc{ 15224684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 15234684ddb6SLionel Sambuc if (__state_ == nullptr) 15244684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 15254684ddb6SLionel Sambuc#endif 15264684ddb6SLionel Sambuc __state_->set_exception_at_thread_exit(__p); 15274684ddb6SLionel Sambuc} 15284684ddb6SLionel Sambuc 15294684ddb6SLionel Sambuc// promise<R&> 15304684ddb6SLionel Sambuc 15314684ddb6SLionel Sambuctemplate <class _Rp> 15324684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY promise<_Rp&> 15334684ddb6SLionel Sambuc{ 15344684ddb6SLionel Sambuc __assoc_state<_Rp&>* __state_; 15354684ddb6SLionel Sambuc 15364684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 15374684ddb6SLionel Sambuc explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} 15384684ddb6SLionel Sambuc 15394684ddb6SLionel Sambuc template <class> friend class packaged_task; 15404684ddb6SLionel Sambuc 15414684ddb6SLionel Sambucpublic: 15424684ddb6SLionel Sambuc promise(); 15434684ddb6SLionel Sambuc template <class _Allocator> 15444684ddb6SLionel Sambuc promise(allocator_arg_t, const _Allocator& __a); 15454684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 15464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 15474684ddb6SLionel Sambuc promise(promise&& __rhs) _NOEXCEPT 15484684ddb6SLionel Sambuc : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} 15494684ddb6SLionel Sambuc promise(const promise& __rhs) = delete; 15504684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 15514684ddb6SLionel Sambucprivate: 15524684ddb6SLionel Sambuc promise(const promise& __rhs); 15534684ddb6SLionel Sambucpublic: 15544684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 15554684ddb6SLionel Sambuc ~promise(); 15564684ddb6SLionel Sambuc 15574684ddb6SLionel Sambuc // assignment 15584684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 15594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 15604684ddb6SLionel Sambuc promise& operator=(promise&& __rhs) _NOEXCEPT 15614684ddb6SLionel Sambuc { 15624684ddb6SLionel Sambuc promise(std::move(__rhs)).swap(*this); 15634684ddb6SLionel Sambuc return *this; 15644684ddb6SLionel Sambuc } 15654684ddb6SLionel Sambuc promise& operator=(const promise& __rhs) = delete; 15664684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 15674684ddb6SLionel Sambucprivate: 15684684ddb6SLionel Sambuc promise& operator=(const promise& __rhs); 15694684ddb6SLionel Sambucpublic: 15704684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 15714684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 15724684ddb6SLionel Sambuc void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 15734684ddb6SLionel Sambuc 15744684ddb6SLionel Sambuc // retrieving the result 15754684ddb6SLionel Sambuc future<_Rp&> get_future(); 15764684ddb6SLionel Sambuc 15774684ddb6SLionel Sambuc // setting the result 15784684ddb6SLionel Sambuc void set_value(_Rp& __r); 15794684ddb6SLionel Sambuc void set_exception(exception_ptr __p); 15804684ddb6SLionel Sambuc 15814684ddb6SLionel Sambuc // setting the result with deferred notification 15824684ddb6SLionel Sambuc void set_value_at_thread_exit(_Rp&); 15834684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr __p); 15844684ddb6SLionel Sambuc}; 15854684ddb6SLionel Sambuc 15864684ddb6SLionel Sambuctemplate <class _Rp> 15874684ddb6SLionel Sambucpromise<_Rp&>::promise() 15884684ddb6SLionel Sambuc : __state_(new __assoc_state<_Rp&>) 15894684ddb6SLionel Sambuc{ 15904684ddb6SLionel Sambuc} 15914684ddb6SLionel Sambuc 15924684ddb6SLionel Sambuctemplate <class _Rp> 15934684ddb6SLionel Sambuctemplate <class _Alloc> 15944684ddb6SLionel Sambucpromise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) 15954684ddb6SLionel Sambuc{ 1596*0a6a1f1dSLionel Sambuc typedef __assoc_state_alloc<_Rp&, _Alloc> _State; 1597*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; 15984684ddb6SLionel Sambuc typedef __allocator_destructor<_A2> _D2; 15994684ddb6SLionel Sambuc _A2 __a(__a0); 1600*0a6a1f1dSLionel Sambuc unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); 1601*0a6a1f1dSLionel Sambuc ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); 1602*0a6a1f1dSLionel Sambuc __state_ = _VSTD::addressof(*__hold.release()); 16034684ddb6SLionel Sambuc} 16044684ddb6SLionel Sambuc 16054684ddb6SLionel Sambuctemplate <class _Rp> 16064684ddb6SLionel Sambucpromise<_Rp&>::~promise() 16074684ddb6SLionel Sambuc{ 16084684ddb6SLionel Sambuc if (__state_) 16094684ddb6SLionel Sambuc { 16104684ddb6SLionel Sambuc if (!__state_->__has_value() && __state_->use_count() > 1) 16114684ddb6SLionel Sambuc __state_->set_exception(make_exception_ptr( 16124684ddb6SLionel Sambuc future_error(make_error_code(future_errc::broken_promise)) 16134684ddb6SLionel Sambuc )); 16144684ddb6SLionel Sambuc __state_->__release_shared(); 16154684ddb6SLionel Sambuc } 16164684ddb6SLionel Sambuc} 16174684ddb6SLionel Sambuc 16184684ddb6SLionel Sambuctemplate <class _Rp> 16194684ddb6SLionel Sambucfuture<_Rp&> 16204684ddb6SLionel Sambucpromise<_Rp&>::get_future() 16214684ddb6SLionel Sambuc{ 16224684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 16234684ddb6SLionel Sambuc if (__state_ == nullptr) 16244684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 16254684ddb6SLionel Sambuc#endif 16264684ddb6SLionel Sambuc return future<_Rp&>(__state_); 16274684ddb6SLionel Sambuc} 16284684ddb6SLionel Sambuc 16294684ddb6SLionel Sambuctemplate <class _Rp> 16304684ddb6SLionel Sambucvoid 16314684ddb6SLionel Sambucpromise<_Rp&>::set_value(_Rp& __r) 16324684ddb6SLionel Sambuc{ 16334684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 16344684ddb6SLionel Sambuc if (__state_ == nullptr) 16354684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 16364684ddb6SLionel Sambuc#endif 16374684ddb6SLionel Sambuc __state_->set_value(__r); 16384684ddb6SLionel Sambuc} 16394684ddb6SLionel Sambuc 16404684ddb6SLionel Sambuctemplate <class _Rp> 16414684ddb6SLionel Sambucvoid 16424684ddb6SLionel Sambucpromise<_Rp&>::set_exception(exception_ptr __p) 16434684ddb6SLionel Sambuc{ 16444684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 16454684ddb6SLionel Sambuc if (__state_ == nullptr) 16464684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 16474684ddb6SLionel Sambuc#endif 16484684ddb6SLionel Sambuc __state_->set_exception(__p); 16494684ddb6SLionel Sambuc} 16504684ddb6SLionel Sambuc 16514684ddb6SLionel Sambuctemplate <class _Rp> 16524684ddb6SLionel Sambucvoid 16534684ddb6SLionel Sambucpromise<_Rp&>::set_value_at_thread_exit(_Rp& __r) 16544684ddb6SLionel Sambuc{ 16554684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 16564684ddb6SLionel Sambuc if (__state_ == nullptr) 16574684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 16584684ddb6SLionel Sambuc#endif 16594684ddb6SLionel Sambuc __state_->set_value_at_thread_exit(__r); 16604684ddb6SLionel Sambuc} 16614684ddb6SLionel Sambuc 16624684ddb6SLionel Sambuctemplate <class _Rp> 16634684ddb6SLionel Sambucvoid 16644684ddb6SLionel Sambucpromise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p) 16654684ddb6SLionel Sambuc{ 16664684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 16674684ddb6SLionel Sambuc if (__state_ == nullptr) 16684684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 16694684ddb6SLionel Sambuc#endif 16704684ddb6SLionel Sambuc __state_->set_exception_at_thread_exit(__p); 16714684ddb6SLionel Sambuc} 16724684ddb6SLionel Sambuc 16734684ddb6SLionel Sambuc// promise<void> 16744684ddb6SLionel Sambuc 16754684ddb6SLionel Sambuctemplate <> 16764684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS promise<void> 16774684ddb6SLionel Sambuc{ 16784684ddb6SLionel Sambuc __assoc_sub_state* __state_; 16794684ddb6SLionel Sambuc 16804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 16814684ddb6SLionel Sambuc explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} 16824684ddb6SLionel Sambuc 16834684ddb6SLionel Sambuc template <class> friend class packaged_task; 16844684ddb6SLionel Sambuc 16854684ddb6SLionel Sambucpublic: 16864684ddb6SLionel Sambuc promise(); 16874684ddb6SLionel Sambuc template <class _Allocator> 16884684ddb6SLionel Sambuc promise(allocator_arg_t, const _Allocator& __a); 16894684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 16904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 16914684ddb6SLionel Sambuc promise(promise&& __rhs) _NOEXCEPT 16924684ddb6SLionel Sambuc : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} 16934684ddb6SLionel Sambuc promise(const promise& __rhs) = delete; 16944684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 16954684ddb6SLionel Sambucprivate: 16964684ddb6SLionel Sambuc promise(const promise& __rhs); 16974684ddb6SLionel Sambucpublic: 16984684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 16994684ddb6SLionel Sambuc ~promise(); 17004684ddb6SLionel Sambuc 17014684ddb6SLionel Sambuc // assignment 17024684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 17034684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17044684ddb6SLionel Sambuc promise& operator=(promise&& __rhs) _NOEXCEPT 17054684ddb6SLionel Sambuc { 17064684ddb6SLionel Sambuc promise(std::move(__rhs)).swap(*this); 17074684ddb6SLionel Sambuc return *this; 17084684ddb6SLionel Sambuc } 17094684ddb6SLionel Sambuc promise& operator=(const promise& __rhs) = delete; 17104684ddb6SLionel Sambuc#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 17114684ddb6SLionel Sambucprivate: 17124684ddb6SLionel Sambuc promise& operator=(const promise& __rhs); 17134684ddb6SLionel Sambucpublic: 17144684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 17154684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17164684ddb6SLionel Sambuc void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 17174684ddb6SLionel Sambuc 17184684ddb6SLionel Sambuc // retrieving the result 17194684ddb6SLionel Sambuc future<void> get_future(); 17204684ddb6SLionel Sambuc 17214684ddb6SLionel Sambuc // setting the result 17224684ddb6SLionel Sambuc void set_value(); 17234684ddb6SLionel Sambuc void set_exception(exception_ptr __p); 17244684ddb6SLionel Sambuc 17254684ddb6SLionel Sambuc // setting the result with deferred notification 17264684ddb6SLionel Sambuc void set_value_at_thread_exit(); 17274684ddb6SLionel Sambuc void set_exception_at_thread_exit(exception_ptr __p); 17284684ddb6SLionel Sambuc}; 17294684ddb6SLionel Sambuc 17304684ddb6SLionel Sambuctemplate <class _Alloc> 17314684ddb6SLionel Sambucpromise<void>::promise(allocator_arg_t, const _Alloc& __a0) 17324684ddb6SLionel Sambuc{ 1733*0a6a1f1dSLionel Sambuc typedef __assoc_sub_state_alloc<_Alloc> _State; 1734*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; 17354684ddb6SLionel Sambuc typedef __allocator_destructor<_A2> _D2; 17364684ddb6SLionel Sambuc _A2 __a(__a0); 1737*0a6a1f1dSLionel Sambuc unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); 1738*0a6a1f1dSLionel Sambuc ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); 1739*0a6a1f1dSLionel Sambuc __state_ = _VSTD::addressof(*__hold.release()); 17404684ddb6SLionel Sambuc} 17414684ddb6SLionel Sambuc 17424684ddb6SLionel Sambuctemplate <class _Rp> 17434684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 17444684ddb6SLionel Sambucvoid 17454684ddb6SLionel Sambucswap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT 17464684ddb6SLionel Sambuc{ 17474684ddb6SLionel Sambuc __x.swap(__y); 17484684ddb6SLionel Sambuc} 17494684ddb6SLionel Sambuc 17504684ddb6SLionel Sambuctemplate <class _Rp, class _Alloc> 17514684ddb6SLionel Sambuc struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<promise<_Rp>, _Alloc> 17524684ddb6SLionel Sambuc : public true_type {}; 17534684ddb6SLionel Sambuc 17544684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 17554684ddb6SLionel Sambuc 17564684ddb6SLionel Sambuc// packaged_task 17574684ddb6SLionel Sambuc 17584684ddb6SLionel Sambuctemplate<class _Fp> class __packaged_task_base; 17594684ddb6SLionel Sambuc 17604684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 17614684ddb6SLionel Sambucclass __packaged_task_base<_Rp(_ArgTypes...)> 17624684ddb6SLionel Sambuc{ 17634684ddb6SLionel Sambuc __packaged_task_base(const __packaged_task_base&); 17644684ddb6SLionel Sambuc __packaged_task_base& operator=(const __packaged_task_base&); 17654684ddb6SLionel Sambucpublic: 17664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17674684ddb6SLionel Sambuc __packaged_task_base() {} 17684684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17694684ddb6SLionel Sambuc virtual ~__packaged_task_base() {} 17704684ddb6SLionel Sambuc virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0; 17714684ddb6SLionel Sambuc virtual void destroy() = 0; 17724684ddb6SLionel Sambuc virtual void destroy_deallocate() = 0; 17734684ddb6SLionel Sambuc virtual _Rp operator()(_ArgTypes&& ...) = 0; 17744684ddb6SLionel Sambuc}; 17754684ddb6SLionel Sambuc 17764684ddb6SLionel Sambuctemplate<class _FD, class _Alloc, class _FB> class __packaged_task_func; 17774684ddb6SLionel Sambuc 17784684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17794684ddb6SLionel Sambucclass __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> 17804684ddb6SLionel Sambuc : public __packaged_task_base<_Rp(_ArgTypes...)> 17814684ddb6SLionel Sambuc{ 17824684ddb6SLionel Sambuc __compressed_pair<_Fp, _Alloc> __f_; 17834684ddb6SLionel Sambucpublic: 17844684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17854684ddb6SLionel Sambuc explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {} 17864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17874684ddb6SLionel Sambuc explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {} 17884684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17894684ddb6SLionel Sambuc __packaged_task_func(const _Fp& __f, const _Alloc& __a) 17904684ddb6SLionel Sambuc : __f_(__f, __a) {} 17914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17924684ddb6SLionel Sambuc __packaged_task_func(_Fp&& __f, const _Alloc& __a) 17934684ddb6SLionel Sambuc : __f_(_VSTD::move(__f), __a) {} 17944684ddb6SLionel Sambuc virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT; 17954684ddb6SLionel Sambuc virtual void destroy(); 17964684ddb6SLionel Sambuc virtual void destroy_deallocate(); 17974684ddb6SLionel Sambuc virtual _Rp operator()(_ArgTypes&& ... __args); 17984684ddb6SLionel Sambuc}; 17994684ddb6SLionel Sambuc 18004684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 18014684ddb6SLionel Sambucvoid 18024684ddb6SLionel Sambuc__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to( 18034684ddb6SLionel Sambuc __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT 18044684ddb6SLionel Sambuc{ 18054684ddb6SLionel Sambuc ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); 18064684ddb6SLionel Sambuc} 18074684ddb6SLionel Sambuc 18084684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 18094684ddb6SLionel Sambucvoid 18104684ddb6SLionel Sambuc__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() 18114684ddb6SLionel Sambuc{ 18124684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 18134684ddb6SLionel Sambuc} 18144684ddb6SLionel Sambuc 18154684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 18164684ddb6SLionel Sambucvoid 18174684ddb6SLionel Sambuc__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() 18184684ddb6SLionel Sambuc{ 1819*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap; 1820*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Ap> _ATraits; 1821*0a6a1f1dSLionel Sambuc typedef pointer_traits<typename _ATraits::pointer> _PTraits; 18224684ddb6SLionel Sambuc _Ap __a(__f_.second()); 18234684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 1824*0a6a1f1dSLionel Sambuc __a.deallocate(_PTraits::pointer_to(*this), 1); 18254684ddb6SLionel Sambuc} 18264684ddb6SLionel Sambuc 18274684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 18284684ddb6SLionel Sambuc_Rp 18294684ddb6SLionel Sambuc__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 18304684ddb6SLionel Sambuc{ 18314684ddb6SLionel Sambuc return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 18324684ddb6SLionel Sambuc} 18334684ddb6SLionel Sambuc 18344684ddb6SLionel Sambuctemplate <class _Callable> class __packaged_task_function; 18354684ddb6SLionel Sambuc 18364684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 18374684ddb6SLionel Sambucclass __packaged_task_function<_Rp(_ArgTypes...)> 18384684ddb6SLionel Sambuc{ 18394684ddb6SLionel Sambuc typedef __packaged_task_base<_Rp(_ArgTypes...)> __base; 18404684ddb6SLionel Sambuc typename aligned_storage<3*sizeof(void*)>::type __buf_; 18414684ddb6SLionel Sambuc __base* __f_; 18424684ddb6SLionel Sambuc 18434684ddb6SLionel Sambucpublic: 18444684ddb6SLionel Sambuc typedef _Rp result_type; 18454684ddb6SLionel Sambuc 18464684ddb6SLionel Sambuc // construct/copy/destroy: 18474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18484684ddb6SLionel Sambuc __packaged_task_function() _NOEXCEPT : __f_(nullptr) {} 18494684ddb6SLionel Sambuc template<class _Fp> 18504684ddb6SLionel Sambuc __packaged_task_function(_Fp&& __f); 18514684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 18524684ddb6SLionel Sambuc __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f); 18534684ddb6SLionel Sambuc 18544684ddb6SLionel Sambuc __packaged_task_function(__packaged_task_function&&) _NOEXCEPT; 18554684ddb6SLionel Sambuc __packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT; 18564684ddb6SLionel Sambuc 18574684ddb6SLionel Sambuc __packaged_task_function(const __packaged_task_function&) = delete; 18584684ddb6SLionel Sambuc __packaged_task_function& operator=(const __packaged_task_function&) = delete; 18594684ddb6SLionel Sambuc 18604684ddb6SLionel Sambuc ~__packaged_task_function(); 18614684ddb6SLionel Sambuc 18624684ddb6SLionel Sambuc void swap(__packaged_task_function&) _NOEXCEPT; 18634684ddb6SLionel Sambuc 18644684ddb6SLionel Sambuc _Rp operator()(_ArgTypes...) const; 18654684ddb6SLionel Sambuc}; 18664684ddb6SLionel Sambuc 18674684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 18684684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT 18694684ddb6SLionel Sambuc{ 18704684ddb6SLionel Sambuc if (__f.__f_ == nullptr) 18714684ddb6SLionel Sambuc __f_ = nullptr; 18724684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 18734684ddb6SLionel Sambuc { 18744684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 18754684ddb6SLionel Sambuc __f.__f_->__move_to(__f_); 18764684ddb6SLionel Sambuc } 18774684ddb6SLionel Sambuc else 18784684ddb6SLionel Sambuc { 18794684ddb6SLionel Sambuc __f_ = __f.__f_; 18804684ddb6SLionel Sambuc __f.__f_ = nullptr; 18814684ddb6SLionel Sambuc } 18824684ddb6SLionel Sambuc} 18834684ddb6SLionel Sambuc 18844684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 18854684ddb6SLionel Sambuctemplate <class _Fp> 18864684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f) 18874684ddb6SLionel Sambuc : __f_(nullptr) 18884684ddb6SLionel Sambuc{ 1889*0a6a1f1dSLionel Sambuc typedef typename remove_reference<typename decay<_Fp>::type>::type _FR; 18904684ddb6SLionel Sambuc typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF; 18914684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 18924684ddb6SLionel Sambuc { 18934684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 18944684ddb6SLionel Sambuc ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); 18954684ddb6SLionel Sambuc } 18964684ddb6SLionel Sambuc else 18974684ddb6SLionel Sambuc { 18984684ddb6SLionel Sambuc typedef allocator<_FF> _Ap; 18994684ddb6SLionel Sambuc _Ap __a; 19004684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 19014684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 19024684ddb6SLionel Sambuc ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a)); 19034684ddb6SLionel Sambuc __f_ = __hold.release(); 19044684ddb6SLionel Sambuc } 19054684ddb6SLionel Sambuc} 19064684ddb6SLionel Sambuc 19074684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 19084684ddb6SLionel Sambuctemplate <class _Fp, class _Alloc> 19094684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function( 19104684ddb6SLionel Sambuc allocator_arg_t, const _Alloc& __a0, _Fp&& __f) 19114684ddb6SLionel Sambuc : __f_(nullptr) 19124684ddb6SLionel Sambuc{ 1913*0a6a1f1dSLionel Sambuc typedef typename remove_reference<typename decay<_Fp>::type>::type _FR; 19144684ddb6SLionel Sambuc typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF; 19154684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 19164684ddb6SLionel Sambuc { 19174684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 19184684ddb6SLionel Sambuc ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); 19194684ddb6SLionel Sambuc } 19204684ddb6SLionel Sambuc else 19214684ddb6SLionel Sambuc { 1922*0a6a1f1dSLionel Sambuc typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap; 19234684ddb6SLionel Sambuc _Ap __a(__a0); 19244684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 19254684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1926*0a6a1f1dSLionel Sambuc ::new (static_cast<void*>(_VSTD::addressof(*__hold.get()))) 1927*0a6a1f1dSLionel Sambuc _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); 1928*0a6a1f1dSLionel Sambuc __f_ = _VSTD::addressof(*__hold.release()); 19294684ddb6SLionel Sambuc } 19304684ddb6SLionel Sambuc} 19314684ddb6SLionel Sambuc 19324684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 19334684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>& 19344684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT 19354684ddb6SLionel Sambuc{ 19364684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 19374684ddb6SLionel Sambuc __f_->destroy(); 19384684ddb6SLionel Sambuc else if (__f_) 19394684ddb6SLionel Sambuc __f_->destroy_deallocate(); 19404684ddb6SLionel Sambuc __f_ = nullptr; 19414684ddb6SLionel Sambuc if (__f.__f_ == nullptr) 19424684ddb6SLionel Sambuc __f_ = nullptr; 19434684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 19444684ddb6SLionel Sambuc { 19454684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 19464684ddb6SLionel Sambuc __f.__f_->__move_to(__f_); 19474684ddb6SLionel Sambuc } 19484684ddb6SLionel Sambuc else 19494684ddb6SLionel Sambuc { 19504684ddb6SLionel Sambuc __f_ = __f.__f_; 19514684ddb6SLionel Sambuc __f.__f_ = nullptr; 19524684ddb6SLionel Sambuc } 19534684ddb6SLionel Sambuc return *this; 19544684ddb6SLionel Sambuc} 19554684ddb6SLionel Sambuc 19564684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 19574684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function() 19584684ddb6SLionel Sambuc{ 19594684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 19604684ddb6SLionel Sambuc __f_->destroy(); 19614684ddb6SLionel Sambuc else if (__f_) 19624684ddb6SLionel Sambuc __f_->destroy_deallocate(); 19634684ddb6SLionel Sambuc} 19644684ddb6SLionel Sambuc 19654684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 19664684ddb6SLionel Sambucvoid 19674684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT 19684684ddb6SLionel Sambuc{ 19694684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 19704684ddb6SLionel Sambuc { 19714684ddb6SLionel Sambuc typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 19724684ddb6SLionel Sambuc __base* __t = (__base*)&__tempbuf; 19734684ddb6SLionel Sambuc __f_->__move_to(__t); 19744684ddb6SLionel Sambuc __f_->destroy(); 19754684ddb6SLionel Sambuc __f_ = nullptr; 19764684ddb6SLionel Sambuc __f.__f_->__move_to((__base*)&__buf_); 19774684ddb6SLionel Sambuc __f.__f_->destroy(); 19784684ddb6SLionel Sambuc __f.__f_ = nullptr; 19794684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 19804684ddb6SLionel Sambuc __t->__move_to((__base*)&__f.__buf_); 19814684ddb6SLionel Sambuc __t->destroy(); 19824684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 19834684ddb6SLionel Sambuc } 19844684ddb6SLionel Sambuc else if (__f_ == (__base*)&__buf_) 19854684ddb6SLionel Sambuc { 19864684ddb6SLionel Sambuc __f_->__move_to((__base*)&__f.__buf_); 19874684ddb6SLionel Sambuc __f_->destroy(); 19884684ddb6SLionel Sambuc __f_ = __f.__f_; 19894684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 19904684ddb6SLionel Sambuc } 19914684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 19924684ddb6SLionel Sambuc { 19934684ddb6SLionel Sambuc __f.__f_->__move_to((__base*)&__buf_); 19944684ddb6SLionel Sambuc __f.__f_->destroy(); 19954684ddb6SLionel Sambuc __f.__f_ = __f_; 19964684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 19974684ddb6SLionel Sambuc } 19984684ddb6SLionel Sambuc else 19994684ddb6SLionel Sambuc _VSTD::swap(__f_, __f.__f_); 20004684ddb6SLionel Sambuc} 20014684ddb6SLionel Sambuc 20024684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 20034684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 20044684ddb6SLionel Sambuc_Rp 20054684ddb6SLionel Sambuc__packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 20064684ddb6SLionel Sambuc{ 20074684ddb6SLionel Sambuc return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 20084684ddb6SLionel Sambuc} 20094684ddb6SLionel Sambuc 20104684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 20114684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY packaged_task<_Rp(_ArgTypes...)> 20124684ddb6SLionel Sambuc{ 20134684ddb6SLionel Sambucpublic: 20144684ddb6SLionel Sambuc typedef _Rp result_type; 20154684ddb6SLionel Sambuc 20164684ddb6SLionel Sambucprivate: 20174684ddb6SLionel Sambuc __packaged_task_function<result_type(_ArgTypes...)> __f_; 20184684ddb6SLionel Sambuc promise<result_type> __p_; 20194684ddb6SLionel Sambuc 20204684ddb6SLionel Sambucpublic: 20214684ddb6SLionel Sambuc // construction and destruction 20224684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20234684ddb6SLionel Sambuc packaged_task() _NOEXCEPT : __p_(nullptr) {} 20244684ddb6SLionel Sambuc template <class _Fp, 20254684ddb6SLionel Sambuc class = typename enable_if 20264684ddb6SLionel Sambuc < 20274684ddb6SLionel Sambuc !is_same< 20284684ddb6SLionel Sambuc typename decay<_Fp>::type, 20294684ddb6SLionel Sambuc packaged_task 20304684ddb6SLionel Sambuc >::value 20314684ddb6SLionel Sambuc >::type 20324684ddb6SLionel Sambuc > 20334684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20344684ddb6SLionel Sambuc explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} 20354684ddb6SLionel Sambuc template <class _Fp, class _Allocator, 20364684ddb6SLionel Sambuc class = typename enable_if 20374684ddb6SLionel Sambuc < 20384684ddb6SLionel Sambuc !is_same< 20394684ddb6SLionel Sambuc typename decay<_Fp>::type, 20404684ddb6SLionel Sambuc packaged_task 20414684ddb6SLionel Sambuc >::value 20424684ddb6SLionel Sambuc >::type 20434684ddb6SLionel Sambuc > 20444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2045*0a6a1f1dSLionel Sambuc packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) 20464684ddb6SLionel Sambuc : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), 20474684ddb6SLionel Sambuc __p_(allocator_arg, __a) {} 20484684ddb6SLionel Sambuc // ~packaged_task() = default; 20494684ddb6SLionel Sambuc 20504684ddb6SLionel Sambuc // no copy 20514684ddb6SLionel Sambuc packaged_task(const packaged_task&) = delete; 20524684ddb6SLionel Sambuc packaged_task& operator=(const packaged_task&) = delete; 20534684ddb6SLionel Sambuc 20544684ddb6SLionel Sambuc // move support 20554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20564684ddb6SLionel Sambuc packaged_task(packaged_task&& __other) _NOEXCEPT 20574684ddb6SLionel Sambuc : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} 20584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20594684ddb6SLionel Sambuc packaged_task& operator=(packaged_task&& __other) _NOEXCEPT 20604684ddb6SLionel Sambuc { 20614684ddb6SLionel Sambuc __f_ = _VSTD::move(__other.__f_); 20624684ddb6SLionel Sambuc __p_ = _VSTD::move(__other.__p_); 20634684ddb6SLionel Sambuc return *this; 20644684ddb6SLionel Sambuc } 20654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20664684ddb6SLionel Sambuc void swap(packaged_task& __other) _NOEXCEPT 20674684ddb6SLionel Sambuc { 20684684ddb6SLionel Sambuc __f_.swap(__other.__f_); 20694684ddb6SLionel Sambuc __p_.swap(__other.__p_); 20704684ddb6SLionel Sambuc } 20714684ddb6SLionel Sambuc 20724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20734684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} 20744684ddb6SLionel Sambuc 20754684ddb6SLionel Sambuc // result retrieval 20764684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 20774684ddb6SLionel Sambuc future<result_type> get_future() {return __p_.get_future();} 20784684ddb6SLionel Sambuc 20794684ddb6SLionel Sambuc // execution 20804684ddb6SLionel Sambuc void operator()(_ArgTypes... __args); 20814684ddb6SLionel Sambuc void make_ready_at_thread_exit(_ArgTypes... __args); 20824684ddb6SLionel Sambuc 20834684ddb6SLionel Sambuc void reset(); 20844684ddb6SLionel Sambuc}; 20854684ddb6SLionel Sambuc 20864684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 20874684ddb6SLionel Sambucvoid 20884684ddb6SLionel Sambucpackaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) 20894684ddb6SLionel Sambuc{ 20904684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 20914684ddb6SLionel Sambuc if (__p_.__state_ == nullptr) 20924684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 20934684ddb6SLionel Sambuc if (__p_.__state_->__has_value()) 20944684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 20954684ddb6SLionel Sambuc try 20964684ddb6SLionel Sambuc { 20974684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 20984684ddb6SLionel Sambuc __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...)); 20994684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 21004684ddb6SLionel Sambuc } 21014684ddb6SLionel Sambuc catch (...) 21024684ddb6SLionel Sambuc { 21034684ddb6SLionel Sambuc __p_.set_exception(current_exception()); 21044684ddb6SLionel Sambuc } 21054684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 21064684ddb6SLionel Sambuc} 21074684ddb6SLionel Sambuc 21084684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 21094684ddb6SLionel Sambucvoid 21104684ddb6SLionel Sambucpackaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) 21114684ddb6SLionel Sambuc{ 21124684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 21134684ddb6SLionel Sambuc if (__p_.__state_ == nullptr) 21144684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 21154684ddb6SLionel Sambuc if (__p_.__state_->__has_value()) 21164684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 21174684ddb6SLionel Sambuc try 21184684ddb6SLionel Sambuc { 21194684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 21204684ddb6SLionel Sambuc __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...)); 21214684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 21224684ddb6SLionel Sambuc } 21234684ddb6SLionel Sambuc catch (...) 21244684ddb6SLionel Sambuc { 21254684ddb6SLionel Sambuc __p_.set_exception_at_thread_exit(current_exception()); 21264684ddb6SLionel Sambuc } 21274684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 21284684ddb6SLionel Sambuc} 21294684ddb6SLionel Sambuc 21304684ddb6SLionel Sambuctemplate<class _Rp, class ..._ArgTypes> 21314684ddb6SLionel Sambucvoid 21324684ddb6SLionel Sambucpackaged_task<_Rp(_ArgTypes...)>::reset() 21334684ddb6SLionel Sambuc{ 21344684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 21354684ddb6SLionel Sambuc if (!valid()) 21364684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 21374684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 21384684ddb6SLionel Sambuc __p_ = promise<result_type>(); 21394684ddb6SLionel Sambuc} 21404684ddb6SLionel Sambuc 21414684ddb6SLionel Sambuctemplate<class ..._ArgTypes> 21424684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY packaged_task<void(_ArgTypes...)> 21434684ddb6SLionel Sambuc{ 21444684ddb6SLionel Sambucpublic: 21454684ddb6SLionel Sambuc typedef void result_type; 21464684ddb6SLionel Sambuc 21474684ddb6SLionel Sambucprivate: 21484684ddb6SLionel Sambuc __packaged_task_function<result_type(_ArgTypes...)> __f_; 21494684ddb6SLionel Sambuc promise<result_type> __p_; 21504684ddb6SLionel Sambuc 21514684ddb6SLionel Sambucpublic: 21524684ddb6SLionel Sambuc // construction and destruction 21534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21544684ddb6SLionel Sambuc packaged_task() _NOEXCEPT : __p_(nullptr) {} 21554684ddb6SLionel Sambuc template <class _Fp, 21564684ddb6SLionel Sambuc class = typename enable_if 21574684ddb6SLionel Sambuc < 21584684ddb6SLionel Sambuc !is_same< 21594684ddb6SLionel Sambuc typename decay<_Fp>::type, 21604684ddb6SLionel Sambuc packaged_task 21614684ddb6SLionel Sambuc >::value 21624684ddb6SLionel Sambuc >::type 21634684ddb6SLionel Sambuc > 21644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21654684ddb6SLionel Sambuc explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} 21664684ddb6SLionel Sambuc template <class _Fp, class _Allocator, 21674684ddb6SLionel Sambuc class = typename enable_if 21684684ddb6SLionel Sambuc < 21694684ddb6SLionel Sambuc !is_same< 21704684ddb6SLionel Sambuc typename decay<_Fp>::type, 21714684ddb6SLionel Sambuc packaged_task 21724684ddb6SLionel Sambuc >::value 21734684ddb6SLionel Sambuc >::type 21744684ddb6SLionel Sambuc > 21754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2176*0a6a1f1dSLionel Sambuc packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) 21774684ddb6SLionel Sambuc : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), 21784684ddb6SLionel Sambuc __p_(allocator_arg, __a) {} 21794684ddb6SLionel Sambuc // ~packaged_task() = default; 21804684ddb6SLionel Sambuc 21814684ddb6SLionel Sambuc // no copy 21824684ddb6SLionel Sambuc packaged_task(const packaged_task&) = delete; 21834684ddb6SLionel Sambuc packaged_task& operator=(const packaged_task&) = delete; 21844684ddb6SLionel Sambuc 21854684ddb6SLionel Sambuc // move support 21864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21874684ddb6SLionel Sambuc packaged_task(packaged_task&& __other) _NOEXCEPT 21884684ddb6SLionel Sambuc : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} 21894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21904684ddb6SLionel Sambuc packaged_task& operator=(packaged_task&& __other) _NOEXCEPT 21914684ddb6SLionel Sambuc { 21924684ddb6SLionel Sambuc __f_ = _VSTD::move(__other.__f_); 21934684ddb6SLionel Sambuc __p_ = _VSTD::move(__other.__p_); 21944684ddb6SLionel Sambuc return *this; 21954684ddb6SLionel Sambuc } 21964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21974684ddb6SLionel Sambuc void swap(packaged_task& __other) _NOEXCEPT 21984684ddb6SLionel Sambuc { 21994684ddb6SLionel Sambuc __f_.swap(__other.__f_); 22004684ddb6SLionel Sambuc __p_.swap(__other.__p_); 22014684ddb6SLionel Sambuc } 22024684ddb6SLionel Sambuc 22034684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22044684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} 22054684ddb6SLionel Sambuc 22064684ddb6SLionel Sambuc // result retrieval 22074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22084684ddb6SLionel Sambuc future<result_type> get_future() {return __p_.get_future();} 22094684ddb6SLionel Sambuc 22104684ddb6SLionel Sambuc // execution 22114684ddb6SLionel Sambuc void operator()(_ArgTypes... __args); 22124684ddb6SLionel Sambuc void make_ready_at_thread_exit(_ArgTypes... __args); 22134684ddb6SLionel Sambuc 22144684ddb6SLionel Sambuc void reset(); 22154684ddb6SLionel Sambuc}; 22164684ddb6SLionel Sambuc 22174684ddb6SLionel Sambuctemplate<class ..._ArgTypes> 22184684ddb6SLionel Sambucvoid 22194684ddb6SLionel Sambucpackaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) 22204684ddb6SLionel Sambuc{ 22214684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 22224684ddb6SLionel Sambuc if (__p_.__state_ == nullptr) 22234684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 22244684ddb6SLionel Sambuc if (__p_.__state_->__has_value()) 22254684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 22264684ddb6SLionel Sambuc try 22274684ddb6SLionel Sambuc { 22284684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 22294684ddb6SLionel Sambuc __f_(_VSTD::forward<_ArgTypes>(__args)...); 22304684ddb6SLionel Sambuc __p_.set_value(); 22314684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 22324684ddb6SLionel Sambuc } 22334684ddb6SLionel Sambuc catch (...) 22344684ddb6SLionel Sambuc { 22354684ddb6SLionel Sambuc __p_.set_exception(current_exception()); 22364684ddb6SLionel Sambuc } 22374684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 22384684ddb6SLionel Sambuc} 22394684ddb6SLionel Sambuc 22404684ddb6SLionel Sambuctemplate<class ..._ArgTypes> 22414684ddb6SLionel Sambucvoid 22424684ddb6SLionel Sambucpackaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) 22434684ddb6SLionel Sambuc{ 22444684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 22454684ddb6SLionel Sambuc if (__p_.__state_ == nullptr) 22464684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 22474684ddb6SLionel Sambuc if (__p_.__state_->__has_value()) 22484684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::promise_already_satisfied)); 22494684ddb6SLionel Sambuc try 22504684ddb6SLionel Sambuc { 22514684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 22524684ddb6SLionel Sambuc __f_(_VSTD::forward<_ArgTypes>(__args)...); 22534684ddb6SLionel Sambuc __p_.set_value_at_thread_exit(); 22544684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 22554684ddb6SLionel Sambuc } 22564684ddb6SLionel Sambuc catch (...) 22574684ddb6SLionel Sambuc { 22584684ddb6SLionel Sambuc __p_.set_exception_at_thread_exit(current_exception()); 22594684ddb6SLionel Sambuc } 22604684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 22614684ddb6SLionel Sambuc} 22624684ddb6SLionel Sambuc 22634684ddb6SLionel Sambuctemplate<class ..._ArgTypes> 22644684ddb6SLionel Sambucvoid 22654684ddb6SLionel Sambucpackaged_task<void(_ArgTypes...)>::reset() 22664684ddb6SLionel Sambuc{ 22674684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 22684684ddb6SLionel Sambuc if (!valid()) 22694684ddb6SLionel Sambuc throw future_error(make_error_code(future_errc::no_state)); 22704684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 22714684ddb6SLionel Sambuc __p_ = promise<result_type>(); 22724684ddb6SLionel Sambuc} 22734684ddb6SLionel Sambuc 22744684ddb6SLionel Sambuctemplate <class _Callable> 22754684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 22764684ddb6SLionel Sambucvoid 22774684ddb6SLionel Sambucswap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT 22784684ddb6SLionel Sambuc{ 22794684ddb6SLionel Sambuc __x.swap(__y); 22804684ddb6SLionel Sambuc} 22814684ddb6SLionel Sambuc 22824684ddb6SLionel Sambuctemplate <class _Callable, class _Alloc> 22834684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY uses_allocator<packaged_task<_Callable>, _Alloc> 22844684ddb6SLionel Sambuc : public true_type {}; 22854684ddb6SLionel Sambuc 22864684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 22874684ddb6SLionel Sambucfuture<_Rp> 22884684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 22894684ddb6SLionel Sambuc__make_deferred_assoc_state(_Fp&& __f) 22904684ddb6SLionel Sambuc#else 22914684ddb6SLionel Sambuc__make_deferred_assoc_state(_Fp __f) 22924684ddb6SLionel Sambuc#endif 22934684ddb6SLionel Sambuc{ 22944684ddb6SLionel Sambuc unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count> 22954684ddb6SLionel Sambuc __h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); 22964684ddb6SLionel Sambuc return future<_Rp>(__h.get()); 22974684ddb6SLionel Sambuc} 22984684ddb6SLionel Sambuc 22994684ddb6SLionel Sambuctemplate <class _Rp, class _Fp> 23004684ddb6SLionel Sambucfuture<_Rp> 23014684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 23024684ddb6SLionel Sambuc__make_async_assoc_state(_Fp&& __f) 23034684ddb6SLionel Sambuc#else 23044684ddb6SLionel Sambuc__make_async_assoc_state(_Fp __f) 23054684ddb6SLionel Sambuc#endif 23064684ddb6SLionel Sambuc{ 23074684ddb6SLionel Sambuc unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> 23084684ddb6SLionel Sambuc __h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); 23094684ddb6SLionel Sambuc _VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach(); 23104684ddb6SLionel Sambuc return future<_Rp>(__h.get()); 23114684ddb6SLionel Sambuc} 23124684ddb6SLionel Sambuc 23134684ddb6SLionel Sambuctemplate <class _Fp, class... _Args> 23144684ddb6SLionel Sambucclass __async_func 23154684ddb6SLionel Sambuc{ 23164684ddb6SLionel Sambuc tuple<_Fp, _Args...> __f_; 23174684ddb6SLionel Sambuc 23184684ddb6SLionel Sambucpublic: 23194684ddb6SLionel Sambuc typedef typename __invoke_of<_Fp, _Args...>::type _Rp; 23204684ddb6SLionel Sambuc 23214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23224684ddb6SLionel Sambuc explicit __async_func(_Fp&& __f, _Args&&... __args) 23234684ddb6SLionel Sambuc : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {} 23244684ddb6SLionel Sambuc 23254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23264684ddb6SLionel Sambuc __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {} 23274684ddb6SLionel Sambuc 23284684ddb6SLionel Sambuc _Rp operator()() 23294684ddb6SLionel Sambuc { 23304684ddb6SLionel Sambuc typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index; 23314684ddb6SLionel Sambuc return __execute(_Index()); 23324684ddb6SLionel Sambuc } 23334684ddb6SLionel Sambucprivate: 23344684ddb6SLionel Sambuc template <size_t ..._Indices> 23354684ddb6SLionel Sambuc _Rp 23364684ddb6SLionel Sambuc __execute(__tuple_indices<_Indices...>) 23374684ddb6SLionel Sambuc { 23384684ddb6SLionel Sambuc return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...); 23394684ddb6SLionel Sambuc } 23404684ddb6SLionel Sambuc}; 23414684ddb6SLionel Sambuc 23424684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value ) 23434684ddb6SLionel Sambuc{ return (int(__policy) & int(__value)) != 0; } 23444684ddb6SLionel Sambuc 23454684ddb6SLionel Sambuctemplate <class _Fp, class... _Args> 23464684ddb6SLionel Sambucfuture<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> 23474684ddb6SLionel Sambucasync(launch __policy, _Fp&& __f, _Args&&... __args) 23484684ddb6SLionel Sambuc{ 23494684ddb6SLionel Sambuc typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF; 23504684ddb6SLionel Sambuc typedef typename _BF::_Rp _Rp; 23514684ddb6SLionel Sambuc 23524684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 23534684ddb6SLionel Sambuc try 23544684ddb6SLionel Sambuc { 23554684ddb6SLionel Sambuc#endif 23564684ddb6SLionel Sambuc if (__does_policy_contain(__policy, launch::async)) 23574684ddb6SLionel Sambuc return _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), 23584684ddb6SLionel Sambuc __decay_copy(_VSTD::forward<_Args>(__args))...)); 23594684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 23604684ddb6SLionel Sambuc } 23614684ddb6SLionel Sambuc catch ( ... ) { if (__policy == launch::async) throw ; } 23624684ddb6SLionel Sambuc#endif 23634684ddb6SLionel Sambuc 23644684ddb6SLionel Sambuc if (__does_policy_contain(__policy, launch::deferred)) 23654684ddb6SLionel Sambuc return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), 23664684ddb6SLionel Sambuc __decay_copy(_VSTD::forward<_Args>(__args))...)); 23674684ddb6SLionel Sambuc return future<_Rp>{}; 23684684ddb6SLionel Sambuc} 23694684ddb6SLionel Sambuc 23704684ddb6SLionel Sambuctemplate <class _Fp, class... _Args> 23714684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 23724684ddb6SLionel Sambucfuture<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> 23734684ddb6SLionel Sambucasync(_Fp&& __f, _Args&&... __args) 23744684ddb6SLionel Sambuc{ 23754684ddb6SLionel Sambuc return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f), 23764684ddb6SLionel Sambuc _VSTD::forward<_Args>(__args)...); 23774684ddb6SLionel Sambuc} 23784684ddb6SLionel Sambuc 23794684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 23804684ddb6SLionel Sambuc 23814684ddb6SLionel Sambuc// shared_future 23824684ddb6SLionel Sambuc 23834684ddb6SLionel Sambuctemplate <class _Rp> 23844684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY shared_future 23854684ddb6SLionel Sambuc{ 23864684ddb6SLionel Sambuc __assoc_state<_Rp>* __state_; 23874684ddb6SLionel Sambuc 23884684ddb6SLionel Sambucpublic: 23894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23904684ddb6SLionel Sambuc shared_future() _NOEXCEPT : __state_(nullptr) {} 23914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23924684ddb6SLionel Sambuc shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) 23934684ddb6SLionel Sambuc {if (__state_) __state_->__add_shared();} 23944684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 23954684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23964684ddb6SLionel Sambuc shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_) 23974684ddb6SLionel Sambuc {__f.__state_ = nullptr;} 23984684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23994684ddb6SLionel Sambuc shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) 24004684ddb6SLionel Sambuc {__rhs.__state_ = nullptr;} 24014684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 24024684ddb6SLionel Sambuc ~shared_future(); 24034684ddb6SLionel Sambuc shared_future& operator=(const shared_future& __rhs); 24044684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 24054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24064684ddb6SLionel Sambuc shared_future& operator=(shared_future&& __rhs) _NOEXCEPT 24074684ddb6SLionel Sambuc { 24084684ddb6SLionel Sambuc shared_future(std::move(__rhs)).swap(*this); 24094684ddb6SLionel Sambuc return *this; 24104684ddb6SLionel Sambuc } 24114684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 24124684ddb6SLionel Sambuc 24134684ddb6SLionel Sambuc // retrieving the value 24144684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24154684ddb6SLionel Sambuc const _Rp& get() const {return __state_->copy();} 24164684ddb6SLionel Sambuc 24174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24184684ddb6SLionel Sambuc void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 24194684ddb6SLionel Sambuc 24204684ddb6SLionel Sambuc // functions to check state 24214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24224684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __state_ != nullptr;} 24234684ddb6SLionel Sambuc 24244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24254684ddb6SLionel Sambuc void wait() const {__state_->wait();} 24264684ddb6SLionel Sambuc template <class _Rep, class _Period> 24274684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24284684ddb6SLionel Sambuc future_status 24294684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 24304684ddb6SLionel Sambuc {return __state_->wait_for(__rel_time);} 24314684ddb6SLionel Sambuc template <class _Clock, class _Duration> 24324684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24334684ddb6SLionel Sambuc future_status 24344684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 24354684ddb6SLionel Sambuc {return __state_->wait_until(__abs_time);} 24364684ddb6SLionel Sambuc}; 24374684ddb6SLionel Sambuc 24384684ddb6SLionel Sambuctemplate <class _Rp> 24394684ddb6SLionel Sambucshared_future<_Rp>::~shared_future() 24404684ddb6SLionel Sambuc{ 24414684ddb6SLionel Sambuc if (__state_) 24424684ddb6SLionel Sambuc __state_->__release_shared(); 24434684ddb6SLionel Sambuc} 24444684ddb6SLionel Sambuc 24454684ddb6SLionel Sambuctemplate <class _Rp> 24464684ddb6SLionel Sambucshared_future<_Rp>& 24474684ddb6SLionel Sambucshared_future<_Rp>::operator=(const shared_future& __rhs) 24484684ddb6SLionel Sambuc{ 24494684ddb6SLionel Sambuc if (__rhs.__state_) 24504684ddb6SLionel Sambuc __rhs.__state_->__add_shared(); 24514684ddb6SLionel Sambuc if (__state_) 24524684ddb6SLionel Sambuc __state_->__release_shared(); 24534684ddb6SLionel Sambuc __state_ = __rhs.__state_; 24544684ddb6SLionel Sambuc return *this; 24554684ddb6SLionel Sambuc} 24564684ddb6SLionel Sambuc 24574684ddb6SLionel Sambuctemplate <class _Rp> 24584684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY shared_future<_Rp&> 24594684ddb6SLionel Sambuc{ 24604684ddb6SLionel Sambuc __assoc_state<_Rp&>* __state_; 24614684ddb6SLionel Sambuc 24624684ddb6SLionel Sambucpublic: 24634684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24644684ddb6SLionel Sambuc shared_future() _NOEXCEPT : __state_(nullptr) {} 24654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24664684ddb6SLionel Sambuc shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) 24674684ddb6SLionel Sambuc {if (__state_) __state_->__add_shared();} 24684684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 24694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24704684ddb6SLionel Sambuc shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_) 24714684ddb6SLionel Sambuc {__f.__state_ = nullptr;} 24724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24734684ddb6SLionel Sambuc shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) 24744684ddb6SLionel Sambuc {__rhs.__state_ = nullptr;} 24754684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 24764684ddb6SLionel Sambuc ~shared_future(); 24774684ddb6SLionel Sambuc shared_future& operator=(const shared_future& __rhs); 24784684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 24794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24804684ddb6SLionel Sambuc shared_future& operator=(shared_future&& __rhs) _NOEXCEPT 24814684ddb6SLionel Sambuc { 24824684ddb6SLionel Sambuc shared_future(std::move(__rhs)).swap(*this); 24834684ddb6SLionel Sambuc return *this; 24844684ddb6SLionel Sambuc } 24854684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 24864684ddb6SLionel Sambuc 24874684ddb6SLionel Sambuc // retrieving the value 24884684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24894684ddb6SLionel Sambuc _Rp& get() const {return __state_->copy();} 24904684ddb6SLionel Sambuc 24914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24924684ddb6SLionel Sambuc void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 24934684ddb6SLionel Sambuc 24944684ddb6SLionel Sambuc // functions to check state 24954684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24964684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __state_ != nullptr;} 24974684ddb6SLionel Sambuc 24984684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24994684ddb6SLionel Sambuc void wait() const {__state_->wait();} 25004684ddb6SLionel Sambuc template <class _Rep, class _Period> 25014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25024684ddb6SLionel Sambuc future_status 25034684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 25044684ddb6SLionel Sambuc {return __state_->wait_for(__rel_time);} 25054684ddb6SLionel Sambuc template <class _Clock, class _Duration> 25064684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25074684ddb6SLionel Sambuc future_status 25084684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 25094684ddb6SLionel Sambuc {return __state_->wait_until(__abs_time);} 25104684ddb6SLionel Sambuc}; 25114684ddb6SLionel Sambuc 25124684ddb6SLionel Sambuctemplate <class _Rp> 25134684ddb6SLionel Sambucshared_future<_Rp&>::~shared_future() 25144684ddb6SLionel Sambuc{ 25154684ddb6SLionel Sambuc if (__state_) 25164684ddb6SLionel Sambuc __state_->__release_shared(); 25174684ddb6SLionel Sambuc} 25184684ddb6SLionel Sambuc 25194684ddb6SLionel Sambuctemplate <class _Rp> 25204684ddb6SLionel Sambucshared_future<_Rp&>& 25214684ddb6SLionel Sambucshared_future<_Rp&>::operator=(const shared_future& __rhs) 25224684ddb6SLionel Sambuc{ 25234684ddb6SLionel Sambuc if (__rhs.__state_) 25244684ddb6SLionel Sambuc __rhs.__state_->__add_shared(); 25254684ddb6SLionel Sambuc if (__state_) 25264684ddb6SLionel Sambuc __state_->__release_shared(); 25274684ddb6SLionel Sambuc __state_ = __rhs.__state_; 25284684ddb6SLionel Sambuc return *this; 25294684ddb6SLionel Sambuc} 25304684ddb6SLionel Sambuc 25314684ddb6SLionel Sambuctemplate <> 25324684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS shared_future<void> 25334684ddb6SLionel Sambuc{ 25344684ddb6SLionel Sambuc __assoc_sub_state* __state_; 25354684ddb6SLionel Sambuc 25364684ddb6SLionel Sambucpublic: 25374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25384684ddb6SLionel Sambuc shared_future() _NOEXCEPT : __state_(nullptr) {} 25394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25404684ddb6SLionel Sambuc shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) 25414684ddb6SLionel Sambuc {if (__state_) __state_->__add_shared();} 25424684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 25434684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25444684ddb6SLionel Sambuc shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_) 25454684ddb6SLionel Sambuc {__f.__state_ = nullptr;} 25464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25474684ddb6SLionel Sambuc shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) 25484684ddb6SLionel Sambuc {__rhs.__state_ = nullptr;} 25494684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 25504684ddb6SLionel Sambuc ~shared_future(); 25514684ddb6SLionel Sambuc shared_future& operator=(const shared_future& __rhs); 25524684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 25534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25544684ddb6SLionel Sambuc shared_future& operator=(shared_future&& __rhs) _NOEXCEPT 25554684ddb6SLionel Sambuc { 25564684ddb6SLionel Sambuc shared_future(std::move(__rhs)).swap(*this); 25574684ddb6SLionel Sambuc return *this; 25584684ddb6SLionel Sambuc } 25594684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 25604684ddb6SLionel Sambuc 25614684ddb6SLionel Sambuc // retrieving the value 25624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25634684ddb6SLionel Sambuc void get() const {__state_->copy();} 25644684ddb6SLionel Sambuc 25654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25664684ddb6SLionel Sambuc void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} 25674684ddb6SLionel Sambuc 25684684ddb6SLionel Sambuc // functions to check state 25694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25704684ddb6SLionel Sambuc bool valid() const _NOEXCEPT {return __state_ != nullptr;} 25714684ddb6SLionel Sambuc 25724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25734684ddb6SLionel Sambuc void wait() const {__state_->wait();} 25744684ddb6SLionel Sambuc template <class _Rep, class _Period> 25754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25764684ddb6SLionel Sambuc future_status 25774684ddb6SLionel Sambuc wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const 25784684ddb6SLionel Sambuc {return __state_->wait_for(__rel_time);} 25794684ddb6SLionel Sambuc template <class _Clock, class _Duration> 25804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25814684ddb6SLionel Sambuc future_status 25824684ddb6SLionel Sambuc wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const 25834684ddb6SLionel Sambuc {return __state_->wait_until(__abs_time);} 25844684ddb6SLionel Sambuc}; 25854684ddb6SLionel Sambuc 25864684ddb6SLionel Sambuctemplate <class _Rp> 25874684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 25884684ddb6SLionel Sambucvoid 25894684ddb6SLionel Sambucswap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT 25904684ddb6SLionel Sambuc{ 25914684ddb6SLionel Sambuc __x.swap(__y); 25924684ddb6SLionel Sambuc} 25934684ddb6SLionel Sambuc 25944684ddb6SLionel Sambuctemplate <class _Rp> 25954684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 25964684ddb6SLionel Sambucshared_future<_Rp> 25974684ddb6SLionel Sambucfuture<_Rp>::share() 25984684ddb6SLionel Sambuc{ 25994684ddb6SLionel Sambuc return shared_future<_Rp>(_VSTD::move(*this)); 26004684ddb6SLionel Sambuc} 26014684ddb6SLionel Sambuc 26024684ddb6SLionel Sambuctemplate <class _Rp> 26034684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 26044684ddb6SLionel Sambucshared_future<_Rp&> 26054684ddb6SLionel Sambucfuture<_Rp&>::share() 26064684ddb6SLionel Sambuc{ 26074684ddb6SLionel Sambuc return shared_future<_Rp&>(_VSTD::move(*this)); 26084684ddb6SLionel Sambuc} 26094684ddb6SLionel Sambuc 26104684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 26114684ddb6SLionel Sambuc 26124684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 26134684ddb6SLionel Sambucshared_future<void> 26144684ddb6SLionel Sambucfuture<void>::share() 26154684ddb6SLionel Sambuc{ 26164684ddb6SLionel Sambuc return shared_future<void>(_VSTD::move(*this)); 26174684ddb6SLionel Sambuc} 26184684ddb6SLionel Sambuc 26194684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 26204684ddb6SLionel Sambuc 26214684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 26224684ddb6SLionel Sambuc 2623*0a6a1f1dSLionel Sambuc#endif // !_LIBCPP_HAS_NO_THREADS 2624*0a6a1f1dSLionel Sambuc 26254684ddb6SLionel Sambuc#endif // _LIBCPP_FUTURE 2626