| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
 | 2 | //===--------------------------- future -----------------------------------===// | 
 | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
| Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open | 
 | 7 | // Source Licenses. See LICENSE.TXT for details. | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // | 
 | 9 | //===----------------------------------------------------------------------===// | 
 | 10 |  | 
 | 11 | #ifndef _LIBCPP_FUTURE | 
 | 12 | #define _LIBCPP_FUTURE | 
 | 13 |  | 
 | 14 | /* | 
 | 15 |     future synopsis | 
 | 16 |  | 
 | 17 | namespace std | 
 | 18 | { | 
 | 19 |  | 
 | 20 | enum class future_errc | 
 | 21 | { | 
| Howard Hinnant | cd942f1 | 2013-09-14 18:20:10 +0000 | [diff] [blame] | 22 |     future_already_retrieved = 1, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 |     promise_already_satisfied, | 
| Howard Hinnant | cd942f1 | 2013-09-14 18:20:10 +0000 | [diff] [blame] | 24 |     no_state, | 
 | 25 |     broken_promise | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | }; | 
 | 27 |  | 
 | 28 | enum class launch | 
 | 29 | { | 
| Howard Hinnant | 6689564 | 2010-11-23 18:33:54 +0000 | [diff] [blame] | 30 |     async = 1, | 
 | 31 |     deferred = 2, | 
 | 32 |     any = async | deferred | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | }; | 
 | 34 |  | 
 | 35 | enum class future_status | 
 | 36 | { | 
 | 37 |     ready, | 
 | 38 |     timeout, | 
 | 39 |     deferred | 
 | 40 | }; | 
 | 41 |  | 
 | 42 | template <> struct is_error_code_enum<future_errc> : public true_type { }; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 43 | error_code make_error_code(future_errc e) noexcept; | 
 | 44 | error_condition make_error_condition(future_errc e) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 |  | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 46 | const error_category& future_category() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 |  | 
 | 48 | class future_error | 
 | 49 |     : public logic_error | 
 | 50 | { | 
 | 51 | public: | 
 | 52 |     future_error(error_code ec);  // exposition only | 
 | 53 |  | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 54 |     const error_code& code() const noexcept; | 
 | 55 |     const char*       what() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | }; | 
 | 57 |  | 
 | 58 | template <class R> | 
 | 59 | class promise | 
 | 60 | { | 
 | 61 | public: | 
 | 62 |     promise(); | 
 | 63 |     template <class Allocator> | 
 | 64 |         promise(allocator_arg_t, const Allocator& a); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 65 |     promise(promise&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 |     promise(const promise& rhs) = delete; | 
 | 67 |     ~promise(); | 
 | 68 |  | 
 | 69 |     // assignment | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 70 |     promise& operator=(promise&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 |     promise& operator=(const promise& rhs) = delete; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 72 |     void swap(promise& other) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 |  | 
 | 74 |     // retrieving the result | 
 | 75 |     future<R> get_future(); | 
 | 76 |  | 
 | 77 |     // setting the result | 
 | 78 |     void set_value(const R& r); | 
 | 79 |     void set_value(R&& r); | 
 | 80 |     void set_exception(exception_ptr p); | 
 | 81 |  | 
 | 82 |     // setting the result with deferred notification | 
 | 83 |     void set_value_at_thread_exit(const R& r); | 
 | 84 |     void set_value_at_thread_exit(R&& r); | 
 | 85 |     void set_exception_at_thread_exit(exception_ptr p); | 
 | 86 | }; | 
 | 87 |  | 
 | 88 | template <class R> | 
 | 89 | class promise<R&> | 
 | 90 | { | 
 | 91 | public: | 
 | 92 |     promise(); | 
 | 93 |     template <class Allocator> | 
 | 94 |         promise(allocator_arg_t, const Allocator& a); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 95 |     promise(promise&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 |     promise(const promise& rhs) = delete; | 
 | 97 |     ~promise(); | 
 | 98 |  | 
 | 99 |     // assignment | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 100 |     promise& operator=(promise&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 101 |     promise& operator=(const promise& rhs) = delete; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 102 |     void swap(promise& other) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 |  | 
 | 104 |     // retrieving the result | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 105 |     future<R&> get_future(); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 |  | 
 | 107 |     // setting the result | 
 | 108 |     void set_value(R& r); | 
 | 109 |     void set_exception(exception_ptr p); | 
 | 110 |  | 
 | 111 |     // setting the result with deferred notification | 
 | 112 |     void set_value_at_thread_exit(R&); | 
 | 113 |     void set_exception_at_thread_exit(exception_ptr p); | 
 | 114 | }; | 
 | 115 |  | 
 | 116 | template <> | 
 | 117 | class promise<void> | 
 | 118 | { | 
 | 119 | public: | 
 | 120 |     promise(); | 
 | 121 |     template <class Allocator> | 
 | 122 |         promise(allocator_arg_t, const Allocator& a); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 123 |     promise(promise&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 |     promise(const promise& rhs) = delete; | 
 | 125 |     ~promise(); | 
 | 126 |  | 
 | 127 |     // assignment | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 128 |     promise& operator=(promise&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 |     promise& operator=(const promise& rhs) = delete; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 130 |     void swap(promise& other) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 |  | 
 | 132 |     // retrieving the result | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 133 |     future<void> get_future(); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 |  | 
 | 135 |     // setting the result | 
 | 136 |     void set_value(); | 
 | 137 |     void set_exception(exception_ptr p); | 
 | 138 |  | 
 | 139 |     // setting the result with deferred notification | 
 | 140 |     void set_value_at_thread_exit(); | 
 | 141 |     void set_exception_at_thread_exit(exception_ptr p); | 
 | 142 | }; | 
 | 143 |  | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 144 | template <class R> void swap(promise<R>& x, promise<R>& y) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 145 |  | 
 | 146 | template <class R, class Alloc> | 
 | 147 |     struct uses_allocator<promise<R>, Alloc> : public true_type {}; | 
 | 148 |  | 
 | 149 | template <class R> | 
 | 150 | class future | 
 | 151 | { | 
 | 152 | public: | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 153 |     future() noexcept; | 
 | 154 |     future(future&&) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 155 |     future(const future& rhs) = delete; | 
 | 156 |     ~future(); | 
 | 157 |     future& operator=(const future& rhs) = delete; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 158 |     future& operator=(future&&) noexcept; | 
 | 159 |     shared_future<R> share(); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 |  | 
 | 161 |     // retrieving the value | 
 | 162 |     R get(); | 
 | 163 |  | 
 | 164 |     // functions to check state | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 165 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 |  | 
 | 167 |     void wait() const; | 
 | 168 |     template <class Rep, class Period> | 
 | 169 |         future_status | 
 | 170 |         wait_for(const chrono::duration<Rep, Period>& rel_time) const; | 
 | 171 |     template <class Clock, class Duration> | 
 | 172 |         future_status | 
 | 173 |         wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; | 
 | 174 | }; | 
 | 175 |  | 
 | 176 | template <class R> | 
 | 177 | class future<R&> | 
 | 178 | { | 
 | 179 | public: | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 180 |     future() noexcept; | 
 | 181 |     future(future&&) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 |     future(const future& rhs) = delete; | 
 | 183 |     ~future(); | 
 | 184 |     future& operator=(const future& rhs) = delete; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 185 |     future& operator=(future&&) noexcept; | 
 | 186 |     shared_future<R&> share(); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 187 |  | 
 | 188 |     // retrieving the value | 
 | 189 |     R& get(); | 
 | 190 |  | 
 | 191 |     // functions to check state | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 192 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 |  | 
 | 194 |     void wait() const; | 
 | 195 |     template <class Rep, class Period> | 
 | 196 |         future_status | 
 | 197 |         wait_for(const chrono::duration<Rep, Period>& rel_time) const; | 
 | 198 |     template <class Clock, class Duration> | 
 | 199 |         future_status | 
 | 200 |         wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; | 
 | 201 | }; | 
 | 202 |  | 
 | 203 | template <> | 
 | 204 | class future<void> | 
 | 205 | { | 
 | 206 | public: | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 207 |     future() noexcept; | 
 | 208 |     future(future&&) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 209 |     future(const future& rhs) = delete; | 
 | 210 |     ~future(); | 
 | 211 |     future& operator=(const future& rhs) = delete; | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 212 |     future& operator=(future&&) noexcept; | 
 | 213 |     shared_future<void> share(); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 |  | 
 | 215 |     // retrieving the value | 
 | 216 |     void get(); | 
 | 217 |  | 
 | 218 |     // functions to check state | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 219 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 |  | 
 | 221 |     void wait() const; | 
 | 222 |     template <class Rep, class Period> | 
 | 223 |         future_status | 
 | 224 |         wait_for(const chrono::duration<Rep, Period>& rel_time) const; | 
 | 225 |     template <class Clock, class Duration> | 
 | 226 |         future_status | 
 | 227 |         wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; | 
 | 228 | }; | 
 | 229 |  | 
 | 230 | template <class R> | 
 | 231 | class shared_future | 
 | 232 | { | 
 | 233 | public: | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 234 |     shared_future() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 |     shared_future(const shared_future& rhs); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 236 |     shared_future(future<R>&&) noexcept; | 
 | 237 |     shared_future(shared_future&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 |     ~shared_future(); | 
 | 239 |     shared_future& operator=(const shared_future& rhs); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 240 |     shared_future& operator=(shared_future&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 |  | 
 | 242 |     // retrieving the value | 
 | 243 |     const R& get() const; | 
 | 244 |  | 
 | 245 |     // functions to check state | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 246 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 247 |  | 
 | 248 |     void wait() const; | 
 | 249 |     template <class Rep, class Period> | 
 | 250 |         future_status | 
 | 251 |         wait_for(const chrono::duration<Rep, Period>& rel_time) const; | 
 | 252 |     template <class Clock, class Duration> | 
 | 253 |         future_status | 
 | 254 |         wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; | 
 | 255 | }; | 
 | 256 |  | 
 | 257 | template <class R> | 
 | 258 | class shared_future<R&> | 
 | 259 | { | 
 | 260 | public: | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 261 |     shared_future() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 262 |     shared_future(const shared_future& rhs); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 263 |     shared_future(future<R&>&&) noexcept; | 
 | 264 |     shared_future(shared_future&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 265 |     ~shared_future(); | 
 | 266 |     shared_future& operator=(const shared_future& rhs); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 267 |     shared_future& operator=(shared_future&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 |  | 
 | 269 |     // retrieving the value | 
 | 270 |     R& get() const; | 
 | 271 |  | 
 | 272 |     // functions to check state | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 273 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 |  | 
 | 275 |     void wait() const; | 
 | 276 |     template <class Rep, class Period> | 
 | 277 |         future_status | 
 | 278 |         wait_for(const chrono::duration<Rep, Period>& rel_time) const; | 
 | 279 |     template <class Clock, class Duration> | 
 | 280 |         future_status | 
 | 281 |         wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; | 
 | 282 | }; | 
 | 283 |  | 
 | 284 | template <> | 
 | 285 | class shared_future<void> | 
 | 286 | { | 
 | 287 | public: | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 288 |     shared_future() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 289 |     shared_future(const shared_future& rhs); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 290 |     shared_future(future<void>&&) noexcept; | 
 | 291 |     shared_future(shared_future&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 |     ~shared_future(); | 
 | 293 |     shared_future& operator=(const shared_future& rhs); | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 294 |     shared_future& operator=(shared_future&& rhs) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 295 |  | 
 | 296 |     // retrieving the value | 
 | 297 |     void get() const; | 
 | 298 |  | 
 | 299 |     // functions to check state | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 300 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 |  | 
 | 302 |     void wait() const; | 
 | 303 |     template <class Rep, class Period> | 
 | 304 |         future_status | 
 | 305 |         wait_for(const chrono::duration<Rep, Period>& rel_time) const; | 
 | 306 |     template <class Clock, class Duration> | 
 | 307 |         future_status | 
 | 308 |         wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; | 
 | 309 | }; | 
 | 310 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 311 | template <class F, class... Args> | 
| Howard Hinnant | 0836f87 | 2013-09-21 18:17:23 +0000 | [diff] [blame] | 312 |   future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 313 |   async(F&& f, Args&&... args); | 
 | 314 |  | 
 | 315 | template <class F, class... Args> | 
| Howard Hinnant | 0836f87 | 2013-09-21 18:17:23 +0000 | [diff] [blame] | 316 |   future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 317 |   async(launch policy, F&& f, Args&&... args); | 
 | 318 |  | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 319 | template <class> class packaged_task; // undefined | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 |  | 
 | 321 | template <class R, class... ArgTypes> | 
 | 322 | class packaged_task<R(ArgTypes...)> | 
 | 323 | { | 
 | 324 | public: | 
 | 325 |     typedef R result_type; | 
 | 326 |  | 
 | 327 |     // construction and destruction | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 328 |     packaged_task() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 329 |     template <class F> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 330 |         explicit packaged_task(F&& f); | 
 | 331 |     template <class F, class Allocator> | 
| Marshall Clow | 07546f3 | 2015-06-30 14:16:49 +0000 | [diff] [blame] | 332 |         packaged_task(allocator_arg_t, const Allocator& a, F&& f); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 |     ~packaged_task(); | 
 | 334 |  | 
 | 335 |     // no copy | 
| Howard Hinnant | 8131a01 | 2012-07-21 19:34:12 +0000 | [diff] [blame] | 336 |     packaged_task(const packaged_task&) = delete; | 
 | 337 |     packaged_task& operator=(const packaged_task&) = delete; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 338 |  | 
 | 339 |     // move support | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 340 |     packaged_task(packaged_task&& other) noexcept; | 
 | 341 |     packaged_task& operator=(packaged_task&& other) noexcept; | 
 | 342 |     void swap(packaged_task& other) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 343 |  | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 344 |     bool valid() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 345 |  | 
 | 346 |     // result retrieval | 
 | 347 |     future<R> get_future(); | 
 | 348 |  | 
 | 349 |     // execution | 
 | 350 |     void operator()(ArgTypes... ); | 
 | 351 |     void make_ready_at_thread_exit(ArgTypes...); | 
 | 352 |  | 
 | 353 |     void reset(); | 
 | 354 | }; | 
 | 355 |  | 
 | 356 | template <class R> | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 357 |   void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 |  | 
 | 359 | template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>; | 
 | 360 |  | 
 | 361 | }  // std | 
 | 362 |  | 
 | 363 | */ | 
 | 364 |  | 
 | 365 | #include <__config> | 
 | 366 | #include <system_error> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 367 | #include <memory> | 
 | 368 | #include <chrono> | 
 | 369 | #include <exception> | 
| Howard Hinnant | e6e4d01 | 2010-09-03 21:46:37 +0000 | [diff] [blame] | 370 | #include <mutex> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 371 | #include <thread> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 |  | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 373 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | #pragma GCC system_header | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 375 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 |  | 
| Jonathan Roelofs | baed05d | 2014-09-05 20:28:44 +0000 | [diff] [blame] | 377 | #ifdef _LIBCPP_HAS_NO_THREADS | 
| Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 378 | #error <future> is not supported on this single threaded system | 
 | 379 | #else // !_LIBCPP_HAS_NO_THREADS | 
 | 380 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 381 | _LIBCPP_BEGIN_NAMESPACE_STD | 
 | 382 |  | 
 | 383 | //enum class future_errc | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 384 | _LIBCPP_DECLARE_STRONG_ENUM(future_errc) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | { | 
| Howard Hinnant | cd942f1 | 2013-09-14 18:20:10 +0000 | [diff] [blame] | 386 |     future_already_retrieved = 1, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 |     promise_already_satisfied, | 
| Howard Hinnant | cd942f1 | 2013-09-14 18:20:10 +0000 | [diff] [blame] | 388 |     no_state, | 
 | 389 |     broken_promise | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | }; | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 391 | _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 393 | template <> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 394 | struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc> : public true_type {}; | 
| Howard Hinnant | a652172 | 2010-08-25 17:32:05 +0000 | [diff] [blame] | 395 |  | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 396 | #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS | 
 | 397 | template <> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 398 | struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc::__lx> : public true_type { }; | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 399 | #endif | 
 | 400 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | //enum class launch | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 402 | _LIBCPP_DECLARE_STRONG_ENUM(launch) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | { | 
| Howard Hinnant | 6689564 | 2010-11-23 18:33:54 +0000 | [diff] [blame] | 404 |     async = 1, | 
 | 405 |     deferred = 2, | 
 | 406 |     any = async | deferred | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | }; | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 408 | _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 |  | 
| Howard Hinnant | f491e51 | 2013-06-29 18:38:17 +0000 | [diff] [blame] | 410 | #ifndef _LIBCPP_HAS_NO_STRONG_ENUMS | 
 | 411 |  | 
 | 412 | #ifdef _LIBCXX_UNDERLYING_TYPE | 
 | 413 | typedef underlying_type<launch>::type __launch_underlying_type; | 
 | 414 | #else | 
 | 415 | typedef int __launch_underlying_type; | 
 | 416 | #endif | 
 | 417 |  | 
 | 418 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 419 | _LIBCPP_CONSTEXPR | 
 | 420 | launch | 
 | 421 | operator&(launch __x, launch __y) | 
 | 422 | { | 
 | 423 |     return static_cast<launch>(static_cast<__launch_underlying_type>(__x) & | 
 | 424 |                                static_cast<__launch_underlying_type>(__y)); | 
 | 425 | } | 
 | 426 |  | 
 | 427 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 428 | _LIBCPP_CONSTEXPR | 
 | 429 | launch | 
 | 430 | operator|(launch __x, launch __y) | 
 | 431 | { | 
 | 432 |     return static_cast<launch>(static_cast<__launch_underlying_type>(__x) | | 
 | 433 |                                static_cast<__launch_underlying_type>(__y)); | 
 | 434 | } | 
 | 435 |  | 
 | 436 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 437 | _LIBCPP_CONSTEXPR | 
 | 438 | launch | 
 | 439 | operator^(launch __x, launch __y) | 
 | 440 | { | 
 | 441 |     return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^ | 
 | 442 |                                static_cast<__launch_underlying_type>(__y)); | 
 | 443 | } | 
 | 444 |  | 
 | 445 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 446 | _LIBCPP_CONSTEXPR | 
 | 447 | launch | 
 | 448 | operator~(launch __x) | 
 | 449 | { | 
| Howard Hinnant | 6a683bf | 2013-07-02 18:01:41 +0000 | [diff] [blame] | 450 |     return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3); | 
| Howard Hinnant | f491e51 | 2013-06-29 18:38:17 +0000 | [diff] [blame] | 451 | } | 
 | 452 |  | 
 | 453 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 454 | launch& | 
 | 455 | operator&=(launch& __x, launch __y) | 
 | 456 | { | 
 | 457 |     __x = __x & __y; return __x; | 
 | 458 | } | 
 | 459 |  | 
 | 460 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 461 | launch& | 
 | 462 | operator|=(launch& __x, launch __y) | 
 | 463 | { | 
 | 464 |     __x = __x | __y; return __x; | 
 | 465 | } | 
 | 466 |  | 
 | 467 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 468 | launch& | 
 | 469 | operator^=(launch& __x, launch __y) | 
 | 470 | { | 
 | 471 |     __x = __x ^ __y; return __x; | 
 | 472 | } | 
 | 473 |  | 
 | 474 | #endif  // !_LIBCPP_HAS_NO_STRONG_ENUMS | 
 | 475 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | //enum class future_status | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 477 | _LIBCPP_DECLARE_STRONG_ENUM(future_status) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | { | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 479 |     ready, | 
 | 480 |     timeout, | 
 | 481 |     deferred | 
 | 482 | }; | 
| Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 483 | _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 484 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 485 | _LIBCPP_FUNC_VIS | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 486 | const error_category& future_category() _NOEXCEPT; | 
| Howard Hinnant | a652172 | 2010-08-25 17:32:05 +0000 | [diff] [blame] | 487 |  | 
 | 488 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 489 | error_code | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 490 | make_error_code(future_errc __e) _NOEXCEPT | 
| Howard Hinnant | a652172 | 2010-08-25 17:32:05 +0000 | [diff] [blame] | 491 | { | 
 | 492 |     return error_code(static_cast<int>(__e), future_category()); | 
 | 493 | } | 
 | 494 |  | 
 | 495 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 496 | error_condition | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 497 | make_error_condition(future_errc __e) _NOEXCEPT | 
| Howard Hinnant | a652172 | 2010-08-25 17:32:05 +0000 | [diff] [blame] | 498 | { | 
 | 499 |     return error_condition(static_cast<int>(__e), future_category()); | 
 | 500 | } | 
 | 501 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 502 | class _LIBCPP_EXCEPTION_ABI future_error | 
| Howard Hinnant | a652172 | 2010-08-25 17:32:05 +0000 | [diff] [blame] | 503 |     : public logic_error | 
 | 504 | { | 
 | 505 |     error_code __ec_; | 
 | 506 | public: | 
 | 507 |     future_error(error_code __ec); | 
 | 508 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 509 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 510 |     const error_code& code() const _NOEXCEPT {return __ec_;} | 
| Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 +0000 | [diff] [blame] | 511 |  | 
 | 512 |     virtual ~future_error() _NOEXCEPT; | 
| Howard Hinnant | a652172 | 2010-08-25 17:32:05 +0000 | [diff] [blame] | 513 | }; | 
 | 514 |  | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 515 | inline _LIBCPP_ALWAYS_INLINE | 
 | 516 | void __throw_future_error(future_errc _Ev) | 
| Marshall Clow | a189974 | 2015-09-03 15:11:32 +0000 | [diff] [blame] | 517 | { | 
 | 518 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 519 |     throw future_error(make_error_code(_Ev)); | 
 | 520 | #else | 
 | 521 |     assert(!"future_error"); | 
 | 522 | #endif | 
 | 523 | } | 
 | 524 |  | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 525 | class _LIBCPP_TYPE_VIS __assoc_sub_state | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 526 |     : public __shared_count | 
 | 527 | { | 
 | 528 | protected: | 
 | 529 |     exception_ptr __exception_; | 
 | 530 |     mutable mutex __mut_; | 
 | 531 |     mutable condition_variable __cv_; | 
 | 532 |     unsigned __state_; | 
 | 533 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 534 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 535 |     void __sub_wait(unique_lock<mutex>& __lk); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 536 | public: | 
 | 537 |     enum | 
 | 538 |     { | 
 | 539 |         __constructed = 1, | 
 | 540 |         __future_attached = 2, | 
 | 541 |         ready = 4, | 
 | 542 |         deferred = 8 | 
 | 543 |     }; | 
 | 544 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 545 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 546 |     __assoc_sub_state() : __state_(0) {} | 
 | 547 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 548 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 549 |     bool __has_value() const | 
 | 550 |         {return (__state_ & __constructed) || (__exception_ != nullptr);} | 
 | 551 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 552 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 1b031c9 | 2013-01-14 20:01:24 +0000 | [diff] [blame] | 553 |     void __set_future_attached() | 
 | 554 |     { | 
 | 555 |         lock_guard<mutex> __lk(__mut_); | 
 | 556 |         __state_ |= __future_attached; | 
 | 557 |     } | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 558 |     _LIBCPP_INLINE_VISIBILITY | 
| Marshall Clow | 9de3d4c | 2013-10-13 01:02:45 +0000 | [diff] [blame] | 559 |     bool __has_future_attached() const {return (__state_ & __future_attached) != 0;} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 560 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 561 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 562 |     void __set_deferred() {__state_ |= deferred;} | 
 | 563 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 564 |     void __make_ready(); | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 565 |     _LIBCPP_INLINE_VISIBILITY | 
| Marshall Clow | 9de3d4c | 2013-10-13 01:02:45 +0000 | [diff] [blame] | 566 |     bool __is_ready() const {return (__state_ & ready) != 0;} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 567 |  | 
 | 568 |     void set_value(); | 
 | 569 |     void set_value_at_thread_exit(); | 
 | 570 |  | 
 | 571 |     void set_exception(exception_ptr __p); | 
 | 572 |     void set_exception_at_thread_exit(exception_ptr __p); | 
 | 573 |  | 
 | 574 |     void copy(); | 
 | 575 |  | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 576 |     void wait(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 577 |     template <class _Rep, class _Period> | 
 | 578 |         future_status | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 579 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 580 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const; | 
 | 581 |     template <class _Clock, class _Duration> | 
 | 582 |         future_status | 
 | 583 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 584 |  | 
 | 585 |     virtual void __execute(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 586 | }; | 
 | 587 |  | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 588 | template <class _Clock, class _Duration> | 
 | 589 | future_status | 
 | 590 | __assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 591 | { | 
 | 592 |     unique_lock<mutex> __lk(__mut_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 593 |     if (__state_ & deferred) | 
 | 594 |         return future_status::deferred; | 
 | 595 |     while (!(__state_ & ready) && _Clock::now() < __abs_time) | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 596 |         __cv_.wait_until(__lk, __abs_time); | 
 | 597 |     if (__state_ & ready) | 
 | 598 |         return future_status::ready; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 599 |     return future_status::timeout; | 
 | 600 | } | 
 | 601 |  | 
 | 602 | template <class _Rep, class _Period> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 603 | inline | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 604 | future_status | 
 | 605 | __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 606 | { | 
| Howard Hinnant | f8f8521 | 2010-11-20 19:16:30 +0000 | [diff] [blame] | 607 |     return wait_until(chrono::steady_clock::now() + __rel_time); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 608 | } | 
 | 609 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 610 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 611 | class __assoc_state | 
 | 612 |     : public __assoc_sub_state | 
 | 613 | { | 
 | 614 |     typedef __assoc_sub_state base; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 615 |     typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 616 | protected: | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 617 |     _Up __value_; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 618 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 619 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 620 | public: | 
 | 621 |  | 
 | 622 |     template <class _Arg> | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 623 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 624 |         void set_value(_Arg&& __arg); | 
 | 625 | #else | 
 | 626 |         void set_value(_Arg& __arg); | 
 | 627 | #endif | 
 | 628 |  | 
 | 629 |     template <class _Arg> | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 630 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 631 |         void set_value_at_thread_exit(_Arg&& __arg); | 
 | 632 | #else | 
 | 633 |         void set_value_at_thread_exit(_Arg& __arg); | 
 | 634 | #endif | 
 | 635 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 636 |     _Rp move(); | 
 | 637 |     typename add_lvalue_reference<_Rp>::type copy(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 638 | }; | 
 | 639 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 640 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 641 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 642 | __assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 643 | { | 
 | 644 |     if (this->__state_ & base::__constructed) | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 645 |         reinterpret_cast<_Rp*>(&__value_)->~_Rp(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 646 |     delete this; | 
 | 647 | } | 
 | 648 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 649 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 650 | template <class _Arg> | 
 | 651 | void | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 652 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 653 | __assoc_state<_Rp>::set_value(_Arg&& __arg) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 654 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 655 | __assoc_state<_Rp>::set_value(_Arg& __arg) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 656 | #endif | 
 | 657 | { | 
 | 658 |     unique_lock<mutex> __lk(this->__mut_); | 
 | 659 |     if (this->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 660 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 661 |     ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 662 |     this->__state_ |= base::__constructed | base::ready; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 663 |     __cv_.notify_all(); | 
 | 664 | } | 
 | 665 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 666 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 667 | template <class _Arg> | 
 | 668 | void | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 669 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 670 | __assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 671 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 672 | __assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 673 | #endif | 
 | 674 | { | 
 | 675 |     unique_lock<mutex> __lk(this->__mut_); | 
 | 676 |     if (this->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 677 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 678 |     ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 679 |     this->__state_ |= base::__constructed; | 
| Howard Hinnant | 5306d68 | 2010-10-14 19:18:04 +0000 | [diff] [blame] | 680 |     __thread_local_data()->__make_ready_at_thread_exit(this); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 681 | } | 
 | 682 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 683 | template <class _Rp> | 
 | 684 | _Rp | 
 | 685 | __assoc_state<_Rp>::move() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 686 | { | 
 | 687 |     unique_lock<mutex> __lk(this->__mut_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 688 |     this->__sub_wait(__lk); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 689 |     if (this->__exception_ != nullptr) | 
 | 690 |         rethrow_exception(this->__exception_); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 691 |     return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_)); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 692 | } | 
 | 693 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 694 | template <class _Rp> | 
 | 695 | typename add_lvalue_reference<_Rp>::type | 
 | 696 | __assoc_state<_Rp>::copy() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 697 | { | 
 | 698 |     unique_lock<mutex> __lk(this->__mut_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 699 |     this->__sub_wait(__lk); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 700 |     if (this->__exception_ != nullptr) | 
 | 701 |         rethrow_exception(this->__exception_); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 702 |     return *reinterpret_cast<_Rp*>(&__value_); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 703 | } | 
 | 704 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 705 | template <class _Rp> | 
 | 706 | class __assoc_state<_Rp&> | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 707 |     : public __assoc_sub_state | 
 | 708 | { | 
 | 709 |     typedef __assoc_sub_state base; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 710 |     typedef _Rp* _Up; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 711 | protected: | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 712 |     _Up __value_; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 713 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 714 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 715 | public: | 
 | 716 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 717 |     void set_value(_Rp& __arg); | 
 | 718 |     void set_value_at_thread_exit(_Rp& __arg); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 719 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 720 |     _Rp& copy(); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 721 | }; | 
 | 722 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 723 | template <class _Rp> | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 724 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 725 | __assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 726 | { | 
 | 727 |     delete this; | 
 | 728 | } | 
 | 729 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 730 | template <class _Rp> | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 731 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 732 | __assoc_state<_Rp&>::set_value(_Rp& __arg) | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 733 | { | 
 | 734 |     unique_lock<mutex> __lk(this->__mut_); | 
 | 735 |     if (this->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 736 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Howard Hinnant | a4e87ab | 2013-08-08 18:38:55 +0000 | [diff] [blame] | 737 |     __value_ = _VSTD::addressof(__arg); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 738 |     this->__state_ |= base::__constructed | base::ready; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 739 |     __cv_.notify_all(); | 
 | 740 | } | 
 | 741 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 742 | template <class _Rp> | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 743 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 744 | __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg) | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 745 | { | 
 | 746 |     unique_lock<mutex> __lk(this->__mut_); | 
 | 747 |     if (this->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 748 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Howard Hinnant | a4e87ab | 2013-08-08 18:38:55 +0000 | [diff] [blame] | 749 |     __value_ = _VSTD::addressof(__arg); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 750 |     this->__state_ |= base::__constructed; | 
| Howard Hinnant | 5306d68 | 2010-10-14 19:18:04 +0000 | [diff] [blame] | 751 |     __thread_local_data()->__make_ready_at_thread_exit(this); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 752 | } | 
 | 753 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 754 | template <class _Rp> | 
 | 755 | _Rp& | 
 | 756 | __assoc_state<_Rp&>::copy() | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 757 | { | 
 | 758 |     unique_lock<mutex> __lk(this->__mut_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 759 |     this->__sub_wait(__lk); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 760 |     if (this->__exception_ != nullptr) | 
 | 761 |         rethrow_exception(this->__exception_); | 
 | 762 |     return *__value_; | 
 | 763 | } | 
 | 764 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 765 | template <class _Rp, class _Alloc> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 766 | class __assoc_state_alloc | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 767 |     : public __assoc_state<_Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 768 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 769 |     typedef __assoc_state<_Rp> base; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 770 |     _Alloc __alloc_; | 
 | 771 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 772 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 773 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 774 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 775 |     explicit __assoc_state_alloc(const _Alloc& __a) | 
 | 776 |         : __alloc_(__a) {} | 
 | 777 | }; | 
 | 778 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 779 | template <class _Rp, class _Alloc> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 780 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 781 | __assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 782 | { | 
 | 783 |     if (this->__state_ & base::__constructed) | 
| Howard Hinnant | a4e87ab | 2013-08-08 18:38:55 +0000 | [diff] [blame] | 784 |         reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp(); | 
| Eric Fiselier | 8492cd8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 785 |     typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; | 
 | 786 |     typedef allocator_traits<_Al> _ATraits; | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 787 |     typedef pointer_traits<typename _ATraits::pointer> _PTraits; | 
| Eric Fiselier | 8492cd8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 788 |     _Al __a(__alloc_); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 789 |     this->~__assoc_state_alloc(); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 790 |     __a.deallocate(_PTraits::pointer_to(*this), 1); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 791 | } | 
 | 792 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 793 | template <class _Rp, class _Alloc> | 
 | 794 | class __assoc_state_alloc<_Rp&, _Alloc> | 
 | 795 |     : public __assoc_state<_Rp&> | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 796 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 797 |     typedef __assoc_state<_Rp&> base; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 798 |     _Alloc __alloc_; | 
 | 799 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 800 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 801 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 802 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 803 |     explicit __assoc_state_alloc(const _Alloc& __a) | 
 | 804 |         : __alloc_(__a) {} | 
 | 805 | }; | 
 | 806 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 807 | template <class _Rp, class _Alloc> | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 808 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 809 | __assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 810 | { | 
| Eric Fiselier | 8492cd8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 811 |     typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; | 
 | 812 |     typedef allocator_traits<_Al> _ATraits; | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 813 |     typedef pointer_traits<typename _ATraits::pointer> _PTraits; | 
| Eric Fiselier | 8492cd8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 814 |     _Al __a(__alloc_); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 815 |     this->~__assoc_state_alloc(); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 816 |     __a.deallocate(_PTraits::pointer_to(*this), 1); | 
| Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 817 | } | 
 | 818 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 819 | template <class _Alloc> | 
 | 820 | class __assoc_sub_state_alloc | 
 | 821 |     : public __assoc_sub_state | 
 | 822 | { | 
 | 823 |     typedef __assoc_sub_state base; | 
 | 824 |     _Alloc __alloc_; | 
 | 825 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 826 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 827 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 828 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 829 |     explicit __assoc_sub_state_alloc(const _Alloc& __a) | 
 | 830 |         : __alloc_(__a) {} | 
 | 831 | }; | 
 | 832 |  | 
 | 833 | template <class _Alloc> | 
 | 834 | void | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 835 | __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 836 | { | 
| Eric Fiselier | 8492cd8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 837 |     typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _Al; | 
 | 838 |     typedef allocator_traits<_Al> _ATraits; | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 839 |     typedef pointer_traits<typename _ATraits::pointer> _PTraits; | 
| Eric Fiselier | 8492cd8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 840 |     _Al __a(__alloc_); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 841 |     this->~__assoc_sub_state_alloc(); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 842 |     __a.deallocate(_PTraits::pointer_to(*this), 1); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 843 | } | 
 | 844 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 845 | template <class _Rp, class _Fp> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 846 | class __deferred_assoc_state | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 847 |     : public __assoc_state<_Rp> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 848 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 849 |     typedef __assoc_state<_Rp> base; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 850 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 851 |     _Fp __func_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 852 |  | 
 | 853 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 854 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 855 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 856 |     explicit __deferred_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 857 | #endif | 
 | 858 |  | 
 | 859 |     virtual void __execute(); | 
 | 860 | }; | 
 | 861 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 862 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 863 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 864 | template <class _Rp, class _Fp> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 865 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 866 | __deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f) | 
 | 867 |     : __func_(_VSTD::forward<_Fp>(__f)) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 868 | { | 
 | 869 |     this->__set_deferred(); | 
 | 870 | } | 
 | 871 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 872 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 873 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 874 | template <class _Rp, class _Fp> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 875 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 876 | __deferred_assoc_state<_Rp, _Fp>::__execute() | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 877 | { | 
 | 878 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 879 |     try | 
 | 880 |     { | 
 | 881 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 882 |         this->set_value(__func_()); | 
 | 883 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 884 |     } | 
 | 885 |     catch (...) | 
 | 886 |     { | 
 | 887 |         this->set_exception(current_exception()); | 
 | 888 |     } | 
 | 889 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 890 | } | 
 | 891 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 892 | template <class _Fp> | 
 | 893 | class __deferred_assoc_state<void, _Fp> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 894 |     : public __assoc_sub_state | 
 | 895 | { | 
 | 896 |     typedef __assoc_sub_state base; | 
 | 897 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 898 |     _Fp __func_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 899 |  | 
 | 900 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 901 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 902 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 903 |     explicit __deferred_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 904 | #endif | 
 | 905 |  | 
 | 906 |     virtual void __execute(); | 
 | 907 | }; | 
 | 908 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 909 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 910 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 911 | template <class _Fp> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 912 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 913 | __deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f) | 
 | 914 |     : __func_(_VSTD::forward<_Fp>(__f)) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 915 | { | 
 | 916 |     this->__set_deferred(); | 
 | 917 | } | 
 | 918 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 919 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 920 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 921 | template <class _Fp> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 922 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 923 | __deferred_assoc_state<void, _Fp>::__execute() | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 924 | { | 
 | 925 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 926 |     try | 
 | 927 |     { | 
 | 928 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 929 |         __func_(); | 
 | 930 |         this->set_value(); | 
 | 931 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 932 |     } | 
 | 933 |     catch (...) | 
 | 934 |     { | 
 | 935 |         this->set_exception(current_exception()); | 
 | 936 |     } | 
 | 937 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 938 | } | 
 | 939 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 940 | template <class _Rp, class _Fp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 941 | class __async_assoc_state | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 942 |     : public __assoc_state<_Rp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 943 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 944 |     typedef __assoc_state<_Rp> base; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 945 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 946 |     _Fp __func_; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 947 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 948 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 949 | public: | 
 | 950 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 951 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 952 |     explicit __async_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 953 | #endif | 
 | 954 |  | 
 | 955 |     virtual void __execute(); | 
 | 956 | }; | 
 | 957 |  | 
 | 958 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 959 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 960 | template <class _Rp, class _Fp> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 961 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 962 | __async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f) | 
 | 963 |     : __func_(_VSTD::forward<_Fp>(__f)) | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 964 | { | 
 | 965 | } | 
 | 966 |  | 
 | 967 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 968 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 969 | template <class _Rp, class _Fp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 970 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 971 | __async_assoc_state<_Rp, _Fp>::__execute() | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 972 | { | 
 | 973 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 974 |     try | 
 | 975 |     { | 
 | 976 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 977 |         this->set_value(__func_()); | 
 | 978 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 979 |     } | 
 | 980 |     catch (...) | 
 | 981 |     { | 
 | 982 |         this->set_exception(current_exception()); | 
 | 983 |     } | 
 | 984 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 985 | } | 
 | 986 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 987 | template <class _Rp, class _Fp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 988 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 989 | __async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 990 | { | 
 | 991 |     this->wait(); | 
 | 992 |     base::__on_zero_shared(); | 
 | 993 | } | 
 | 994 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 995 | template <class _Fp> | 
 | 996 | class __async_assoc_state<void, _Fp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 997 |     : public __assoc_sub_state | 
 | 998 | { | 
 | 999 |     typedef __assoc_sub_state base; | 
 | 1000 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1001 |     _Fp __func_; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1002 |  | 
| Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1003 |     virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1004 | public: | 
 | 1005 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1006 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1007 |     explicit __async_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1008 | #endif | 
 | 1009 |  | 
 | 1010 |     virtual void __execute(); | 
 | 1011 | }; | 
 | 1012 |  | 
 | 1013 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 1014 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1015 | template <class _Fp> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1016 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1017 | __async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f) | 
 | 1018 |     : __func_(_VSTD::forward<_Fp>(__f)) | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1019 | { | 
 | 1020 | } | 
 | 1021 |  | 
 | 1022 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 1023 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1024 | template <class _Fp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1025 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1026 | __async_assoc_state<void, _Fp>::__execute() | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1027 | { | 
 | 1028 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 1029 |     try | 
 | 1030 |     { | 
 | 1031 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 1032 |         __func_(); | 
 | 1033 |         this->set_value(); | 
 | 1034 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 1035 |     } | 
 | 1036 |     catch (...) | 
 | 1037 |     { | 
 | 1038 |         this->set_exception(current_exception()); | 
 | 1039 |     } | 
 | 1040 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 1041 | } | 
 | 1042 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1043 | template <class _Fp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1044 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1045 | __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1046 | { | 
 | 1047 |     this->wait(); | 
 | 1048 |     base::__on_zero_shared(); | 
 | 1049 | } | 
 | 1050 |  | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1051 | template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY promise; | 
 | 1052 | template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY shared_future; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1053 |  | 
 | 1054 | // future | 
 | 1055 |  | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1056 | template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY future; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1057 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1058 | template <class _Rp, class _Fp> | 
 | 1059 | future<_Rp> | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1060 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1061 | __make_deferred_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1062 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1063 | __make_deferred_assoc_state(_Fp __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1064 | #endif | 
 | 1065 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1066 | template <class _Rp, class _Fp> | 
 | 1067 | future<_Rp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1068 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1069 | __make_async_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1070 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1071 | __make_async_assoc_state(_Fp __f); | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 1072 | #endif | 
 | 1073 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1074 | template <class _Rp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1075 | class _LIBCPP_TYPE_VIS_ONLY future | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1076 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1077 |     __assoc_state<_Rp>* __state_; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1078 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1079 |     explicit future(__assoc_state<_Rp>* __state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1080 |  | 
 | 1081 |     template <class> friend class promise; | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 1082 |     template <class> friend class shared_future; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1083 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1084 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1085 |     template <class _R1, class _Fp> | 
 | 1086 |         friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); | 
 | 1087 |     template <class _R1, class _Fp> | 
 | 1088 |         friend future<_R1> __make_async_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1089 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1090 |     template <class _R1, class _Fp> | 
 | 1091 |         friend future<_R1> __make_deferred_assoc_state(_Fp __f); | 
 | 1092 |     template <class _R1, class _Fp> | 
 | 1093 |         friend future<_R1> __make_async_assoc_state(_Fp __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1094 | #endif | 
 | 1095 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1096 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1097 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1098 |     future() _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1099 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1100 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1101 |     future(future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1102 |         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} | 
 | 1103 |     future(const future&) = delete; | 
 | 1104 |     future& operator=(const future&) = delete; | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1105 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1106 |     future& operator=(future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1107 |         { | 
 | 1108 |             future(std::move(__rhs)).swap(*this); | 
 | 1109 |             return *this; | 
 | 1110 |         } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1111 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1112 | private: | 
 | 1113 |     future(const future&); | 
 | 1114 |     future& operator=(const future&); | 
 | 1115 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1116 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1117 |     ~future(); | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1118 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1119 |     shared_future<_Rp> share(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1120 |  | 
 | 1121 |     // retrieving the value | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1122 |     _Rp get(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1123 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1124 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1125 |     void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1126 |  | 
 | 1127 |     // functions to check state | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1128 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1129 |     bool valid() const _NOEXCEPT {return __state_ != nullptr;} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1130 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1131 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1132 |     void wait() const {__state_->wait();} | 
 | 1133 |     template <class _Rep, class _Period> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1134 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1135 |         future_status | 
 | 1136 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 1137 |             {return __state_->wait_for(__rel_time);} | 
 | 1138 |     template <class _Clock, class _Duration> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1139 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1140 |         future_status | 
 | 1141 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 1142 |             {return __state_->wait_until(__abs_time);} | 
 | 1143 | }; | 
 | 1144 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1145 | template <class _Rp> | 
 | 1146 | future<_Rp>::future(__assoc_state<_Rp>* __state) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1147 |     : __state_(__state) | 
 | 1148 | { | 
 | 1149 |     if (__state_->__has_future_attached()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1150 |         __throw_future_error(future_errc::future_already_retrieved); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1151 |     __state_->__add_shared(); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1152 |     __state_->__set_future_attached(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1153 | } | 
 | 1154 |  | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1155 | struct __release_shared_count | 
 | 1156 | { | 
 | 1157 |     void operator()(__shared_count* p) {p->__release_shared();} | 
 | 1158 | }; | 
 | 1159 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1160 | template <class _Rp> | 
 | 1161 | future<_Rp>::~future() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1162 | { | 
 | 1163 |     if (__state_) | 
 | 1164 |         __state_->__release_shared(); | 
 | 1165 | } | 
 | 1166 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1167 | template <class _Rp> | 
 | 1168 | _Rp | 
 | 1169 | future<_Rp>::get() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1170 | { | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1171 |     unique_ptr<__shared_count, __release_shared_count> __(__state_); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1172 |     __assoc_state<_Rp>* __s = __state_; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1173 |     __state_ = nullptr; | 
 | 1174 |     return __s->move(); | 
 | 1175 | } | 
 | 1176 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1177 | template <class _Rp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1178 | class _LIBCPP_TYPE_VIS_ONLY future<_Rp&> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1179 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1180 |     __assoc_state<_Rp&>* __state_; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1181 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1182 |     explicit future(__assoc_state<_Rp&>* __state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1183 |  | 
 | 1184 |     template <class> friend class promise; | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 1185 |     template <class> friend class shared_future; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1186 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1187 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1188 |     template <class _R1, class _Fp> | 
 | 1189 |         friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); | 
 | 1190 |     template <class _R1, class _Fp> | 
 | 1191 |         friend future<_R1> __make_async_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1192 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1193 |     template <class _R1, class _Fp> | 
 | 1194 |         friend future<_R1> __make_deferred_assoc_state(_Fp __f); | 
 | 1195 |     template <class _R1, class _Fp> | 
 | 1196 |         friend future<_R1> __make_async_assoc_state(_Fp __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1197 | #endif | 
 | 1198 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1199 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1200 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1201 |     future() _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1202 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1203 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1204 |     future(future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1205 |         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} | 
 | 1206 |     future(const future&) = delete; | 
 | 1207 |     future& operator=(const future&) = delete; | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1208 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1209 |     future& operator=(future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1210 |         { | 
 | 1211 |             future(std::move(__rhs)).swap(*this); | 
 | 1212 |             return *this; | 
 | 1213 |         } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1214 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1215 | private: | 
 | 1216 |     future(const future&); | 
 | 1217 |     future& operator=(const future&); | 
 | 1218 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1219 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1220 |     ~future(); | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1221 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1222 |     shared_future<_Rp&> share(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1223 |  | 
 | 1224 |     // retrieving the value | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1225 |     _Rp& get(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1226 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1227 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1228 |     void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1229 |  | 
 | 1230 |     // functions to check state | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1231 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1232 |     bool valid() const _NOEXCEPT {return __state_ != nullptr;} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1233 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1234 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1235 |     void wait() const {__state_->wait();} | 
 | 1236 |     template <class _Rep, class _Period> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1237 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1238 |         future_status | 
 | 1239 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 1240 |             {return __state_->wait_for(__rel_time);} | 
 | 1241 |     template <class _Clock, class _Duration> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1242 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1243 |         future_status | 
 | 1244 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 1245 |             {return __state_->wait_until(__abs_time);} | 
 | 1246 | }; | 
 | 1247 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1248 | template <class _Rp> | 
 | 1249 | future<_Rp&>::future(__assoc_state<_Rp&>* __state) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1250 |     : __state_(__state) | 
 | 1251 | { | 
 | 1252 |     if (__state_->__has_future_attached()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1253 |         __throw_future_error(future_errc::future_already_retrieved); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1254 |     __state_->__add_shared(); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1255 |     __state_->__set_future_attached(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1256 | } | 
 | 1257 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1258 | template <class _Rp> | 
 | 1259 | future<_Rp&>::~future() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1260 | { | 
 | 1261 |     if (__state_) | 
 | 1262 |         __state_->__release_shared(); | 
 | 1263 | } | 
 | 1264 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1265 | template <class _Rp> | 
 | 1266 | _Rp& | 
 | 1267 | future<_Rp&>::get() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1268 | { | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1269 |     unique_ptr<__shared_count, __release_shared_count> __(__state_); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1270 |     __assoc_state<_Rp&>* __s = __state_; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1271 |     __state_ = nullptr; | 
 | 1272 |     return __s->copy(); | 
 | 1273 | } | 
 | 1274 |  | 
 | 1275 | template <> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1276 | class _LIBCPP_TYPE_VIS future<void> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1277 | { | 
 | 1278 |     __assoc_sub_state* __state_; | 
 | 1279 |  | 
 | 1280 |     explicit future(__assoc_sub_state* __state); | 
 | 1281 |  | 
 | 1282 |     template <class> friend class promise; | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 1283 |     template <class> friend class shared_future; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1284 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1285 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1286 |     template <class _R1, class _Fp> | 
 | 1287 |         friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); | 
 | 1288 |     template <class _R1, class _Fp> | 
 | 1289 |         friend future<_R1> __make_async_assoc_state(_Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1290 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1291 |     template <class _R1, class _Fp> | 
 | 1292 |         friend future<_R1> __make_deferred_assoc_state(_Fp __f); | 
 | 1293 |     template <class _R1, class _Fp> | 
 | 1294 |         friend future<_R1> __make_async_assoc_state(_Fp __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1295 | #endif | 
 | 1296 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1297 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1298 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1299 |     future() _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1300 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1301 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1302 |     future(future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1303 |         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} | 
 | 1304 |     future(const future&) = delete; | 
 | 1305 |     future& operator=(const future&) = delete; | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1306 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1307 |     future& operator=(future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1308 |         { | 
 | 1309 |             future(std::move(__rhs)).swap(*this); | 
 | 1310 |             return *this; | 
 | 1311 |         } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1312 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1313 | private: | 
 | 1314 |     future(const future&); | 
 | 1315 |     future& operator=(const future&); | 
 | 1316 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1317 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1318 |     ~future(); | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1319 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 7de4790 | 2010-11-30 20:23:32 +0000 | [diff] [blame] | 1320 |     shared_future<void> share(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1321 |  | 
 | 1322 |     // retrieving the value | 
 | 1323 |     void get(); | 
 | 1324 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1325 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1326 |     void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1327 |  | 
 | 1328 |     // functions to check state | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1329 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1330 |     bool valid() const _NOEXCEPT {return __state_ != nullptr;} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1331 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1332 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1333 |     void wait() const {__state_->wait();} | 
 | 1334 |     template <class _Rep, class _Period> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1335 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1336 |         future_status | 
 | 1337 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 1338 |             {return __state_->wait_for(__rel_time);} | 
 | 1339 |     template <class _Clock, class _Duration> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1340 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1341 |         future_status | 
 | 1342 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 1343 |             {return __state_->wait_until(__abs_time);} | 
 | 1344 | }; | 
 | 1345 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1346 | template <class _Rp> | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 1347 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1348 | void | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1349 | swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 1350 | { | 
 | 1351 |     __x.swap(__y); | 
 | 1352 | } | 
 | 1353 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1354 | // promise<R> | 
 | 1355 |  | 
| Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 1356 | template <class _Callable> class packaged_task; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1357 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1358 | template <class _Rp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1359 | class _LIBCPP_TYPE_VIS_ONLY promise | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1360 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1361 |     __assoc_state<_Rp>* __state_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1362 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1363 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1364 |     explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1365 |  | 
 | 1366 |     template <class> friend class packaged_task; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1367 | public: | 
 | 1368 |     promise(); | 
 | 1369 |     template <class _Alloc> | 
 | 1370 |         promise(allocator_arg_t, const _Alloc& __a); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1371 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1372 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1373 |     promise(promise&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1374 |         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} | 
 | 1375 |     promise(const promise& __rhs) = delete; | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1376 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1377 | private: | 
 | 1378 |     promise(const promise& __rhs); | 
 | 1379 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1380 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1381 |     ~promise(); | 
 | 1382 |  | 
 | 1383 |     // assignment | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1384 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1385 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1386 |     promise& operator=(promise&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1387 |         { | 
 | 1388 |             promise(std::move(__rhs)).swap(*this); | 
 | 1389 |             return *this; | 
 | 1390 |         } | 
 | 1391 |     promise& operator=(const promise& __rhs) = delete; | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1392 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1393 | private: | 
 | 1394 |     promise& operator=(const promise& __rhs); | 
 | 1395 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1396 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1397 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1398 |     void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1399 |  | 
 | 1400 |     // retrieving the result | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1401 |     future<_Rp> get_future(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1402 |  | 
 | 1403 |     // setting the result | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1404 |     void set_value(const _Rp& __r); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1405 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1406 |     void set_value(_Rp&& __r); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1407 | #endif | 
 | 1408 |     void set_exception(exception_ptr __p); | 
 | 1409 |  | 
 | 1410 |     // setting the result with deferred notification | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1411 |     void set_value_at_thread_exit(const _Rp& __r); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1412 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1413 |     void set_value_at_thread_exit(_Rp&& __r); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1414 | #endif | 
 | 1415 |     void set_exception_at_thread_exit(exception_ptr __p); | 
 | 1416 | }; | 
 | 1417 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1418 | template <class _Rp> | 
 | 1419 | promise<_Rp>::promise() | 
 | 1420 |     : __state_(new __assoc_state<_Rp>) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1421 | { | 
 | 1422 | } | 
 | 1423 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1424 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1425 | template <class _Alloc> | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1426 | promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1427 | { | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1428 |     typedef __assoc_state_alloc<_Rp, _Alloc> _State; | 
 | 1429 |     typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1430 |     typedef __allocator_destructor<_A2> _D2; | 
 | 1431 |     _A2 __a(__a0); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1432 |     unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); | 
 | 1433 |     ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); | 
 | 1434 |     __state_ = _VSTD::addressof(*__hold.release()); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1435 | } | 
 | 1436 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1437 | template <class _Rp> | 
 | 1438 | promise<_Rp>::~promise() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1439 | { | 
 | 1440 |     if (__state_) | 
 | 1441 |     { | 
 | 1442 |         if (!__state_->__has_value() && __state_->use_count() > 1) | 
 | 1443 |             __state_->set_exception(make_exception_ptr( | 
 | 1444 |                       future_error(make_error_code(future_errc::broken_promise)) | 
 | 1445 |                                                       )); | 
 | 1446 |         __state_->__release_shared(); | 
 | 1447 |     } | 
 | 1448 | } | 
 | 1449 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1450 | template <class _Rp> | 
 | 1451 | future<_Rp> | 
 | 1452 | promise<_Rp>::get_future() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1453 | { | 
 | 1454 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1455 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1456 |     return future<_Rp>(__state_); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1457 | } | 
 | 1458 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1459 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1460 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1461 | promise<_Rp>::set_value(const _Rp& __r) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1462 | { | 
 | 1463 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1464 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1465 |     __state_->set_value(__r); | 
 | 1466 | } | 
 | 1467 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1468 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1469 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1470 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1471 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1472 | promise<_Rp>::set_value(_Rp&& __r) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1473 | { | 
 | 1474 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1475 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1476 |     __state_->set_value(_VSTD::move(__r)); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1477 | } | 
 | 1478 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1479 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1480 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1481 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1482 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1483 | promise<_Rp>::set_exception(exception_ptr __p) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1484 | { | 
 | 1485 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1486 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1487 |     __state_->set_exception(__p); | 
 | 1488 | } | 
 | 1489 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1490 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1491 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1492 | promise<_Rp>::set_value_at_thread_exit(const _Rp& __r) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1493 | { | 
 | 1494 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1495 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1496 |     __state_->set_value_at_thread_exit(__r); | 
 | 1497 | } | 
 | 1498 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1499 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1500 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1501 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1502 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1503 | promise<_Rp>::set_value_at_thread_exit(_Rp&& __r) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1504 | { | 
 | 1505 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1506 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1507 |     __state_->set_value_at_thread_exit(_VSTD::move(__r)); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1508 | } | 
 | 1509 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1510 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1511 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1512 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1513 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1514 | promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1515 | { | 
 | 1516 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1517 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1518 |     __state_->set_exception_at_thread_exit(__p); | 
 | 1519 | } | 
 | 1520 |  | 
 | 1521 | // promise<R&> | 
 | 1522 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1523 | template <class _Rp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1524 | class _LIBCPP_TYPE_VIS_ONLY promise<_Rp&> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1525 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1526 |     __assoc_state<_Rp&>* __state_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1527 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1528 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1529 |     explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1530 |  | 
 | 1531 |     template <class> friend class packaged_task; | 
 | 1532 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1533 | public: | 
 | 1534 |     promise(); | 
 | 1535 |     template <class _Allocator> | 
 | 1536 |         promise(allocator_arg_t, const _Allocator& __a); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1537 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1538 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1539 |     promise(promise&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1540 |         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} | 
 | 1541 |     promise(const promise& __rhs) = delete; | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1542 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1543 | private: | 
 | 1544 |     promise(const promise& __rhs); | 
 | 1545 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1546 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1547 |     ~promise(); | 
 | 1548 |  | 
 | 1549 |     // assignment | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1550 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1551 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1552 |     promise& operator=(promise&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1553 |         { | 
 | 1554 |             promise(std::move(__rhs)).swap(*this); | 
 | 1555 |             return *this; | 
 | 1556 |         } | 
 | 1557 |     promise& operator=(const promise& __rhs) = delete; | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1558 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1559 | private: | 
 | 1560 |     promise& operator=(const promise& __rhs); | 
 | 1561 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1562 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1563 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1564 |     void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1565 |  | 
 | 1566 |     // retrieving the result | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1567 |     future<_Rp&> get_future(); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1568 |  | 
 | 1569 |     // setting the result | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1570 |     void set_value(_Rp& __r); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1571 |     void set_exception(exception_ptr __p); | 
 | 1572 |  | 
 | 1573 |     // setting the result with deferred notification | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1574 |     void set_value_at_thread_exit(_Rp&); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1575 |     void set_exception_at_thread_exit(exception_ptr __p); | 
 | 1576 | }; | 
 | 1577 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1578 | template <class _Rp> | 
 | 1579 | promise<_Rp&>::promise() | 
 | 1580 |     : __state_(new __assoc_state<_Rp&>) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1581 | { | 
 | 1582 | } | 
 | 1583 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1584 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1585 | template <class _Alloc> | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1586 | promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1587 | { | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1588 |     typedef __assoc_state_alloc<_Rp&, _Alloc> _State; | 
 | 1589 |     typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1590 |     typedef __allocator_destructor<_A2> _D2; | 
 | 1591 |     _A2 __a(__a0); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1592 |     unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); | 
 | 1593 |     ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); | 
 | 1594 |     __state_ = _VSTD::addressof(*__hold.release()); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1595 | } | 
 | 1596 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1597 | template <class _Rp> | 
 | 1598 | promise<_Rp&>::~promise() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1599 | { | 
 | 1600 |     if (__state_) | 
 | 1601 |     { | 
 | 1602 |         if (!__state_->__has_value() && __state_->use_count() > 1) | 
 | 1603 |             __state_->set_exception(make_exception_ptr( | 
 | 1604 |                       future_error(make_error_code(future_errc::broken_promise)) | 
 | 1605 |                                                       )); | 
 | 1606 |         __state_->__release_shared(); | 
 | 1607 |     } | 
 | 1608 | } | 
 | 1609 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1610 | template <class _Rp> | 
 | 1611 | future<_Rp&> | 
 | 1612 | promise<_Rp&>::get_future() | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1613 | { | 
 | 1614 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1615 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1616 |     return future<_Rp&>(__state_); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1617 | } | 
 | 1618 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1619 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1620 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1621 | promise<_Rp&>::set_value(_Rp& __r) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1622 | { | 
 | 1623 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1624 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1625 |     __state_->set_value(__r); | 
 | 1626 | } | 
 | 1627 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1628 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1629 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1630 | promise<_Rp&>::set_exception(exception_ptr __p) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1631 | { | 
 | 1632 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1633 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1634 |     __state_->set_exception(__p); | 
 | 1635 | } | 
 | 1636 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1637 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1638 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1639 | promise<_Rp&>::set_value_at_thread_exit(_Rp& __r) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1640 | { | 
 | 1641 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1642 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1643 |     __state_->set_value_at_thread_exit(__r); | 
 | 1644 | } | 
 | 1645 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1646 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1647 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1648 | promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p) | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1649 | { | 
 | 1650 |     if (__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 1651 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1652 |     __state_->set_exception_at_thread_exit(__p); | 
 | 1653 | } | 
 | 1654 |  | 
 | 1655 | // promise<void> | 
 | 1656 |  | 
 | 1657 | template <> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1658 | class _LIBCPP_TYPE_VIS promise<void> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1659 | { | 
 | 1660 |     __assoc_sub_state* __state_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1661 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1662 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1663 |     explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1664 |  | 
 | 1665 |     template <class> friend class packaged_task; | 
 | 1666 |  | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1667 | public: | 
 | 1668 |     promise(); | 
 | 1669 |     template <class _Allocator> | 
 | 1670 |         promise(allocator_arg_t, const _Allocator& __a); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1671 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1672 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1673 |     promise(promise&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1674 |         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} | 
 | 1675 |     promise(const promise& __rhs) = delete; | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1676 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1677 | private: | 
 | 1678 |     promise(const promise& __rhs); | 
 | 1679 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1680 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1681 |     ~promise(); | 
 | 1682 |  | 
 | 1683 |     // assignment | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1684 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1685 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1686 |     promise& operator=(promise&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1687 |         { | 
 | 1688 |             promise(std::move(__rhs)).swap(*this); | 
 | 1689 |             return *this; | 
 | 1690 |         } | 
 | 1691 |     promise& operator=(const promise& __rhs) = delete; | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1692 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1693 | private: | 
 | 1694 |     promise& operator=(const promise& __rhs); | 
 | 1695 | public: | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1696 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1697 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1698 |     void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1699 |  | 
 | 1700 |     // retrieving the result | 
 | 1701 |     future<void> get_future(); | 
 | 1702 |  | 
 | 1703 |     // setting the result | 
 | 1704 |     void set_value(); | 
 | 1705 |     void set_exception(exception_ptr __p); | 
 | 1706 |  | 
 | 1707 |     // setting the result with deferred notification | 
 | 1708 |     void set_value_at_thread_exit(); | 
 | 1709 |     void set_exception_at_thread_exit(exception_ptr __p); | 
 | 1710 | }; | 
 | 1711 |  | 
 | 1712 | template <class _Alloc> | 
 | 1713 | promise<void>::promise(allocator_arg_t, const _Alloc& __a0) | 
 | 1714 | { | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1715 |     typedef __assoc_sub_state_alloc<_Alloc> _State; | 
 | 1716 |     typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1717 |     typedef __allocator_destructor<_A2> _D2; | 
 | 1718 |     _A2 __a(__a0); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1719 |     unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); | 
 | 1720 |     ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); | 
 | 1721 |     __state_ = _VSTD::addressof(*__hold.release()); | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1722 | } | 
 | 1723 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1724 | template <class _Rp> | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1725 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1726 | void | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1727 | swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1728 | { | 
 | 1729 |     __x.swap(__y); | 
 | 1730 | } | 
 | 1731 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1732 | template <class _Rp, class _Alloc> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1733 |     struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<promise<_Rp>, _Alloc> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1734 |         : public true_type {}; | 
| Howard Hinnant | 47499b1 | 2010-08-27 20:10:19 +0000 | [diff] [blame] | 1735 |  | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1736 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
 | 1737 |  | 
 | 1738 | // packaged_task | 
 | 1739 |  | 
 | 1740 | template<class _Fp> class __packaged_task_base; | 
 | 1741 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1742 | template<class _Rp, class ..._ArgTypes> | 
 | 1743 | class __packaged_task_base<_Rp(_ArgTypes...)> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1744 | { | 
 | 1745 |     __packaged_task_base(const __packaged_task_base&); | 
 | 1746 |     __packaged_task_base& operator=(const __packaged_task_base&); | 
 | 1747 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1748 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1749 |     __packaged_task_base() {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1750 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1751 |     virtual ~__packaged_task_base() {} | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1752 |     virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1753 |     virtual void destroy() = 0; | 
 | 1754 |     virtual void destroy_deallocate() = 0; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1755 |     virtual _Rp operator()(_ArgTypes&& ...) = 0; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1756 | }; | 
 | 1757 |  | 
 | 1758 | template<class _FD, class _Alloc, class _FB> class __packaged_task_func; | 
 | 1759 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1760 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> | 
 | 1761 | class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> | 
 | 1762 |     : public  __packaged_task_base<_Rp(_ArgTypes...)> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1763 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1764 |     __compressed_pair<_Fp, _Alloc> __f_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1765 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1766 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1767 |     explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1768 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1769 |     explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1770 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1771 |     __packaged_task_func(const _Fp& __f, const _Alloc& __a) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1772 |         : __f_(__f, __a) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1773 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1774 |     __packaged_task_func(_Fp&& __f, const _Alloc& __a) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1775 |         : __f_(_VSTD::move(__f), __a) {} | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1776 |     virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1777 |     virtual void destroy(); | 
 | 1778 |     virtual void destroy_deallocate(); | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1779 |     virtual _Rp operator()(_ArgTypes&& ... __args); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1780 | }; | 
 | 1781 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1782 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1783 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1784 | __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to( | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1785 |                               __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1786 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1787 |     ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1788 | } | 
 | 1789 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1790 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1791 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1792 | __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1793 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1794 |     __f_.~__compressed_pair<_Fp, _Alloc>(); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1795 | } | 
 | 1796 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1797 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1798 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1799 | __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1800 | { | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1801 |     typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap; | 
 | 1802 |     typedef allocator_traits<_Ap> _ATraits; | 
 | 1803 |     typedef pointer_traits<typename _ATraits::pointer> _PTraits; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1804 |     _Ap __a(__f_.second()); | 
 | 1805 |     __f_.~__compressed_pair<_Fp, _Alloc>(); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1806 |     __a.deallocate(_PTraits::pointer_to(*this), 1); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1807 | } | 
 | 1808 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1809 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> | 
 | 1810 | _Rp | 
 | 1811 | __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1812 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1813 |     return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1814 | } | 
 | 1815 |  | 
| Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 1816 | template <class _Callable> class __packaged_task_function; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1817 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1818 | template<class _Rp, class ..._ArgTypes> | 
 | 1819 | class __packaged_task_function<_Rp(_ArgTypes...)> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1820 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1821 |     typedef __packaged_task_base<_Rp(_ArgTypes...)> __base; | 
| Howard Hinnant | 78f0de2 | 2013-01-21 17:26:55 +0000 | [diff] [blame] | 1822 |     typename aligned_storage<3*sizeof(void*)>::type __buf_; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1823 |     __base* __f_; | 
 | 1824 |  | 
 | 1825 | public: | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1826 |     typedef _Rp result_type; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1827 |  | 
 | 1828 |     // construct/copy/destroy: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 1829 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1830 |     __packaged_task_function() _NOEXCEPT : __f_(nullptr) {} | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1831 |     template<class _Fp> | 
 | 1832 |       __packaged_task_function(_Fp&& __f); | 
 | 1833 |     template<class _Fp, class _Alloc> | 
 | 1834 |       __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1835 |  | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1836 |     __packaged_task_function(__packaged_task_function&&) _NOEXCEPT; | 
 | 1837 |     __packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1838 |  | 
 | 1839 |     __packaged_task_function(const __packaged_task_function&) =  delete; | 
 | 1840 |     __packaged_task_function& operator=(const __packaged_task_function&) =  delete; | 
 | 1841 |  | 
 | 1842 |     ~__packaged_task_function(); | 
 | 1843 |  | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1844 |     void swap(__packaged_task_function&) _NOEXCEPT; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1845 |  | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1846 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1847 |     _Rp operator()(_ArgTypes...) const; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1848 | }; | 
 | 1849 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1850 | template<class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1851 | __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1852 | { | 
 | 1853 |     if (__f.__f_ == nullptr) | 
 | 1854 |         __f_ = nullptr; | 
 | 1855 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 1856 |     { | 
 | 1857 |         __f_ = (__base*)&__buf_; | 
 | 1858 |         __f.__f_->__move_to(__f_); | 
 | 1859 |     } | 
 | 1860 |     else | 
 | 1861 |     { | 
 | 1862 |         __f_ = __f.__f_; | 
 | 1863 |         __f.__f_ = nullptr; | 
 | 1864 |     } | 
 | 1865 | } | 
 | 1866 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1867 | template<class _Rp, class ..._ArgTypes> | 
 | 1868 | template <class _Fp> | 
 | 1869 | __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1870 |     : __f_(nullptr) | 
 | 1871 | { | 
| Marshall Clow | f1264e7 | 2014-04-07 13:32:26 +0000 | [diff] [blame] | 1872 |     typedef typename remove_reference<typename decay<_Fp>::type>::type _FR; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1873 |     typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1874 |     if (sizeof(_FF) <= sizeof(__buf_)) | 
 | 1875 |     { | 
 | 1876 |         __f_ = (__base*)&__buf_; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1877 |         ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1878 |     } | 
 | 1879 |     else | 
 | 1880 |     { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1881 |         typedef allocator<_FF> _Ap; | 
 | 1882 |         _Ap __a; | 
 | 1883 |         typedef __allocator_destructor<_Ap> _Dp; | 
 | 1884 |         unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); | 
 | 1885 |         ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a)); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1886 |         __f_ = __hold.release(); | 
 | 1887 |     } | 
 | 1888 | } | 
 | 1889 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1890 | template<class _Rp, class ..._ArgTypes> | 
 | 1891 | template <class _Fp, class _Alloc> | 
 | 1892 | __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function( | 
 | 1893 |                                   allocator_arg_t, const _Alloc& __a0, _Fp&& __f) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1894 |     : __f_(nullptr) | 
 | 1895 | { | 
| Marshall Clow | f1264e7 | 2014-04-07 13:32:26 +0000 | [diff] [blame] | 1896 |     typedef typename remove_reference<typename decay<_Fp>::type>::type _FR; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1897 |     typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1898 |     if (sizeof(_FF) <= sizeof(__buf_)) | 
 | 1899 |     { | 
 | 1900 |         __f_ = (__base*)&__buf_; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1901 |         ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1902 |     } | 
 | 1903 |     else | 
 | 1904 |     { | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1905 |         typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1906 |         _Ap __a(__a0); | 
 | 1907 |         typedef __allocator_destructor<_Ap> _Dp; | 
 | 1908 |         unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); | 
| Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 1909 |         ::new (static_cast<void*>(_VSTD::addressof(*__hold.get()))) | 
 | 1910 |             _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); | 
 | 1911 |         __f_ = _VSTD::addressof(*__hold.release()); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1912 |     } | 
 | 1913 | } | 
 | 1914 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1915 | template<class _Rp, class ..._ArgTypes> | 
 | 1916 | __packaged_task_function<_Rp(_ArgTypes...)>& | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1917 | __packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1918 | { | 
 | 1919 |     if (__f_ == (__base*)&__buf_) | 
 | 1920 |         __f_->destroy(); | 
 | 1921 |     else if (__f_) | 
 | 1922 |         __f_->destroy_deallocate(); | 
 | 1923 |     __f_ = nullptr; | 
 | 1924 |     if (__f.__f_ == nullptr) | 
 | 1925 |         __f_ = nullptr; | 
 | 1926 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 1927 |     { | 
 | 1928 |         __f_ = (__base*)&__buf_; | 
 | 1929 |         __f.__f_->__move_to(__f_); | 
 | 1930 |     } | 
 | 1931 |     else | 
 | 1932 |     { | 
 | 1933 |         __f_ = __f.__f_; | 
 | 1934 |         __f.__f_ = nullptr; | 
 | 1935 |     } | 
| Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 1936 |     return *this; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1937 | } | 
 | 1938 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1939 | template<class _Rp, class ..._ArgTypes> | 
 | 1940 | __packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function() | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1941 | { | 
 | 1942 |     if (__f_ == (__base*)&__buf_) | 
 | 1943 |         __f_->destroy(); | 
 | 1944 |     else if (__f_) | 
 | 1945 |         __f_->destroy_deallocate(); | 
 | 1946 | } | 
 | 1947 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1948 | template<class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1949 | void | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 1950 | __packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1951 | { | 
 | 1952 |     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) | 
 | 1953 |     { | 
 | 1954 |         typename aligned_storage<sizeof(__buf_)>::type __tempbuf; | 
 | 1955 |         __base* __t = (__base*)&__tempbuf; | 
 | 1956 |         __f_->__move_to(__t); | 
 | 1957 |         __f_->destroy(); | 
 | 1958 |         __f_ = nullptr; | 
 | 1959 |         __f.__f_->__move_to((__base*)&__buf_); | 
 | 1960 |         __f.__f_->destroy(); | 
 | 1961 |         __f.__f_ = nullptr; | 
 | 1962 |         __f_ = (__base*)&__buf_; | 
 | 1963 |         __t->__move_to((__base*)&__f.__buf_); | 
 | 1964 |         __t->destroy(); | 
 | 1965 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1966 |     } | 
 | 1967 |     else if (__f_ == (__base*)&__buf_) | 
 | 1968 |     { | 
 | 1969 |         __f_->__move_to((__base*)&__f.__buf_); | 
 | 1970 |         __f_->destroy(); | 
 | 1971 |         __f_ = __f.__f_; | 
 | 1972 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1973 |     } | 
 | 1974 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 1975 |     { | 
 | 1976 |         __f.__f_->__move_to((__base*)&__buf_); | 
 | 1977 |         __f.__f_->destroy(); | 
 | 1978 |         __f.__f_ = __f_; | 
 | 1979 |         __f_ = (__base*)&__buf_; | 
 | 1980 |     } | 
 | 1981 |     else | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1982 |         _VSTD::swap(__f_, __f.__f_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1983 | } | 
 | 1984 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1985 | template<class _Rp, class ..._ArgTypes> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 1986 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1987 | _Rp | 
 | 1988 | __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1989 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1990 |     return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1991 | } | 
 | 1992 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1993 | template<class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1994 | class _LIBCPP_TYPE_VIS_ONLY packaged_task<_Rp(_ArgTypes...)> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1995 | { | 
 | 1996 | public: | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1997 |     typedef _Rp result_type; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 1998 |  | 
 | 1999 | private: | 
 | 2000 |     __packaged_task_function<result_type(_ArgTypes...)> __f_; | 
 | 2001 |     promise<result_type>                                __p_; | 
 | 2002 |  | 
 | 2003 | public: | 
 | 2004 |     // construction and destruction | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2005 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2006 |     packaged_task() _NOEXCEPT : __p_(nullptr) {} | 
| Marshall Clow | 5f2d5b9 | 2013-10-12 22:49:17 +0000 | [diff] [blame] | 2007 |     template <class _Fp, | 
 | 2008 |               class = typename enable_if | 
 | 2009 |               < | 
 | 2010 |                   !is_same< | 
 | 2011 |                       typename decay<_Fp>::type,  | 
 | 2012 |                       packaged_task | 
 | 2013 |                       >::value | 
 | 2014 |                   >::type | 
 | 2015 |              > | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2016 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2017 |         explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} | 
| Marshall Clow | 5f2d5b9 | 2013-10-12 22:49:17 +0000 | [diff] [blame] | 2018 |     template <class _Fp, class _Allocator, | 
 | 2019 |               class = typename enable_if | 
 | 2020 |               < | 
 | 2021 |                   !is_same< | 
 | 2022 |                       typename decay<_Fp>::type,  | 
 | 2023 |                       packaged_task | 
 | 2024 |                       >::value | 
 | 2025 |                   >::type | 
 | 2026 |               > | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2027 |         _LIBCPP_INLINE_VISIBILITY | 
| Marshall Clow | 07546f3 | 2015-06-30 14:16:49 +0000 | [diff] [blame] | 2028 |         packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2029 |              : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2030 |                __p_(allocator_arg, __a) {} | 
 | 2031 |     // ~packaged_task() = default; | 
 | 2032 |  | 
 | 2033 |     // no copy | 
| Howard Hinnant | 8131a01 | 2012-07-21 19:34:12 +0000 | [diff] [blame] | 2034 |     packaged_task(const packaged_task&) = delete; | 
 | 2035 |     packaged_task& operator=(const packaged_task&) = delete; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2036 |  | 
 | 2037 |     // move support | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2038 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2039 |     packaged_task(packaged_task&& __other) _NOEXCEPT | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2040 |         : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2041 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2042 |     packaged_task& operator=(packaged_task&& __other) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2043 |     { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2044 |         __f_ = _VSTD::move(__other.__f_); | 
 | 2045 |         __p_ = _VSTD::move(__other.__p_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2046 |         return *this; | 
 | 2047 |     } | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2048 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2049 |     void swap(packaged_task& __other) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2050 |     { | 
 | 2051 |         __f_.swap(__other.__f_); | 
 | 2052 |         __p_.swap(__other.__p_); | 
 | 2053 |     } | 
 | 2054 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2055 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2056 |     bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2057 |  | 
 | 2058 |     // result retrieval | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2059 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2060 |     future<result_type> get_future() {return __p_.get_future();} | 
 | 2061 |  | 
 | 2062 |     // execution | 
 | 2063 |     void operator()(_ArgTypes... __args); | 
 | 2064 |     void make_ready_at_thread_exit(_ArgTypes... __args); | 
 | 2065 |  | 
 | 2066 |     void reset(); | 
 | 2067 | }; | 
 | 2068 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2069 | template<class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2070 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2071 | packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2072 | { | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2073 |     if (__p_.__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2074 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2075 |     if (__p_.__state_->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2076 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Marshall Clow | a189974 | 2015-09-03 15:11:32 +0000 | [diff] [blame] | 2077 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2078 |     try | 
 | 2079 |     { | 
 | 2080 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2081 |         __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...)); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2082 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2083 |     } | 
 | 2084 |     catch (...) | 
 | 2085 |     { | 
 | 2086 |         __p_.set_exception(current_exception()); | 
 | 2087 |     } | 
 | 2088 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 2089 | } | 
 | 2090 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2091 | template<class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2092 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2093 | packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2094 | { | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2095 |     if (__p_.__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2096 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2097 |     if (__p_.__state_->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2098 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Marshall Clow | a189974 | 2015-09-03 15:11:32 +0000 | [diff] [blame] | 2099 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2100 |     try | 
 | 2101 |     { | 
 | 2102 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2103 |         __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...)); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2104 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2105 |     } | 
 | 2106 |     catch (...) | 
 | 2107 |     { | 
 | 2108 |         __p_.set_exception_at_thread_exit(current_exception()); | 
 | 2109 |     } | 
 | 2110 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 2111 | } | 
 | 2112 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2113 | template<class _Rp, class ..._ArgTypes> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2114 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2115 | packaged_task<_Rp(_ArgTypes...)>::reset() | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2116 | { | 
| Howard Hinnant | 7de4790 | 2010-11-30 20:23:32 +0000 | [diff] [blame] | 2117 |     if (!valid()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2118 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2119 |     __p_ = promise<result_type>(); | 
 | 2120 | } | 
 | 2121 |  | 
 | 2122 | template<class ..._ArgTypes> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2123 | class _LIBCPP_TYPE_VIS_ONLY packaged_task<void(_ArgTypes...)> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2124 | { | 
 | 2125 | public: | 
 | 2126 |     typedef void result_type; | 
 | 2127 |  | 
 | 2128 | private: | 
 | 2129 |     __packaged_task_function<result_type(_ArgTypes...)> __f_; | 
 | 2130 |     promise<result_type>                                __p_; | 
 | 2131 |  | 
 | 2132 | public: | 
 | 2133 |     // construction and destruction | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2134 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2135 |     packaged_task() _NOEXCEPT : __p_(nullptr) {} | 
| Marshall Clow | 5f2d5b9 | 2013-10-12 22:49:17 +0000 | [diff] [blame] | 2136 |     template <class _Fp, | 
 | 2137 |               class = typename enable_if | 
 | 2138 |               < | 
 | 2139 |                   !is_same< | 
 | 2140 |                       typename decay<_Fp>::type,  | 
 | 2141 |                       packaged_task | 
 | 2142 |                       >::value | 
 | 2143 |                   >::type | 
 | 2144 |               > | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2145 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2146 |         explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} | 
| Marshall Clow | 5f2d5b9 | 2013-10-12 22:49:17 +0000 | [diff] [blame] | 2147 |     template <class _Fp, class _Allocator, | 
 | 2148 |               class = typename enable_if | 
 | 2149 |               < | 
 | 2150 |                   !is_same< | 
 | 2151 |                       typename decay<_Fp>::type,  | 
 | 2152 |                       packaged_task | 
 | 2153 |                       >::value | 
 | 2154 |                   >::type | 
 | 2155 |               >     | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2156 |         _LIBCPP_INLINE_VISIBILITY | 
| Marshall Clow | 5706c37 | 2015-06-30 18:28:35 +0000 | [diff] [blame] | 2157 |         packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2158 |              : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2159 |                __p_(allocator_arg, __a) {} | 
 | 2160 |     // ~packaged_task() = default; | 
 | 2161 |  | 
 | 2162 |     // no copy | 
| Howard Hinnant | 8131a01 | 2012-07-21 19:34:12 +0000 | [diff] [blame] | 2163 |     packaged_task(const packaged_task&) = delete; | 
 | 2164 |     packaged_task& operator=(const packaged_task&) = delete; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2165 |  | 
 | 2166 |     // move support | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2167 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2168 |     packaged_task(packaged_task&& __other) _NOEXCEPT | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2169 |         : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2170 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2171 |     packaged_task& operator=(packaged_task&& __other) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2172 |     { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2173 |         __f_ = _VSTD::move(__other.__f_); | 
 | 2174 |         __p_ = _VSTD::move(__other.__p_); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2175 |         return *this; | 
 | 2176 |     } | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2177 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2178 |     void swap(packaged_task& __other) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2179 |     { | 
 | 2180 |         __f_.swap(__other.__f_); | 
 | 2181 |         __p_.swap(__other.__p_); | 
 | 2182 |     } | 
 | 2183 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2184 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2185 |     bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2186 |  | 
 | 2187 |     // result retrieval | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2188 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2189 |     future<result_type> get_future() {return __p_.get_future();} | 
 | 2190 |  | 
 | 2191 |     // execution | 
 | 2192 |     void operator()(_ArgTypes... __args); | 
 | 2193 |     void make_ready_at_thread_exit(_ArgTypes... __args); | 
 | 2194 |  | 
 | 2195 |     void reset(); | 
 | 2196 | }; | 
 | 2197 |  | 
 | 2198 | template<class ..._ArgTypes> | 
 | 2199 | void | 
 | 2200 | packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) | 
 | 2201 | { | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2202 |     if (__p_.__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2203 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2204 |     if (__p_.__state_->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2205 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Marshall Clow | a189974 | 2015-09-03 15:11:32 +0000 | [diff] [blame] | 2206 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2207 |     try | 
 | 2208 |     { | 
 | 2209 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2210 |         __f_(_VSTD::forward<_ArgTypes>(__args)...); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2211 |         __p_.set_value(); | 
 | 2212 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2213 |     } | 
 | 2214 |     catch (...) | 
 | 2215 |     { | 
 | 2216 |         __p_.set_exception(current_exception()); | 
 | 2217 |     } | 
 | 2218 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 2219 | } | 
 | 2220 |  | 
 | 2221 | template<class ..._ArgTypes> | 
 | 2222 | void | 
 | 2223 | packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) | 
 | 2224 | { | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2225 |     if (__p_.__state_ == nullptr) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2226 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2227 |     if (__p_.__state_->__has_value()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2228 |         __throw_future_error(future_errc::promise_already_satisfied); | 
| Marshall Clow | a189974 | 2015-09-03 15:11:32 +0000 | [diff] [blame] | 2229 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2230 |     try | 
 | 2231 |     { | 
 | 2232 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2233 |         __f_(_VSTD::forward<_ArgTypes>(__args)...); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2234 |         __p_.set_value_at_thread_exit(); | 
 | 2235 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2236 |     } | 
 | 2237 |     catch (...) | 
 | 2238 |     { | 
 | 2239 |         __p_.set_exception_at_thread_exit(current_exception()); | 
 | 2240 |     } | 
 | 2241 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
 | 2242 | } | 
 | 2243 |  | 
 | 2244 | template<class ..._ArgTypes> | 
 | 2245 | void | 
 | 2246 | packaged_task<void(_ArgTypes...)>::reset() | 
 | 2247 | { | 
| Howard Hinnant | 7de4790 | 2010-11-30 20:23:32 +0000 | [diff] [blame] | 2248 |     if (!valid()) | 
| Eric Fiselier | 423ca20 | 2015-10-02 21:25:15 +0000 | [diff] [blame] | 2249 |         __throw_future_error(future_errc::no_state); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2250 |     __p_ = promise<result_type>(); | 
 | 2251 | } | 
 | 2252 |  | 
 | 2253 | template <class _Callable> | 
 | 2254 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 2255 | void | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2256 | swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2257 | { | 
 | 2258 |     __x.swap(__y); | 
 | 2259 | } | 
 | 2260 |  | 
 | 2261 | template <class _Callable, class _Alloc> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2262 | struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<packaged_task<_Callable>, _Alloc> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2263 |     : public true_type {}; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2264 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2265 | template <class _Rp, class _Fp> | 
 | 2266 | future<_Rp> | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2267 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2268 | __make_deferred_assoc_state(_Fp&& __f) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2269 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2270 | __make_deferred_assoc_state(_Fp __f) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2271 | #endif | 
 | 2272 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2273 |     unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count> | 
 | 2274 |         __h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); | 
 | 2275 |     return future<_Rp>(__h.get()); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2276 | } | 
 | 2277 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2278 | template <class _Rp, class _Fp> | 
 | 2279 | future<_Rp> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2280 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2281 | __make_async_assoc_state(_Fp&& __f) | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2282 | #else | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2283 | __make_async_assoc_state(_Fp __f) | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2284 | #endif | 
 | 2285 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2286 |     unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> | 
 | 2287 |         __h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); | 
 | 2288 |     _VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach(); | 
 | 2289 |     return future<_Rp>(__h.get()); | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2290 | } | 
 | 2291 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2292 | template <class _Fp, class... _Args> | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2293 | class __async_func | 
 | 2294 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2295 |     tuple<_Fp, _Args...> __f_; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2296 |  | 
 | 2297 | public: | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2298 |     typedef typename __invoke_of<_Fp, _Args...>::type _Rp; | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2299 |  | 
 | 2300 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2301 |     explicit __async_func(_Fp&& __f, _Args&&... __args) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2302 |         : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {} | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2303 |  | 
 | 2304 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2305 |     __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {} | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2306 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2307 |     _Rp operator()() | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2308 |     { | 
 | 2309 |         typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index; | 
 | 2310 |         return __execute(_Index()); | 
 | 2311 |     } | 
 | 2312 | private: | 
 | 2313 |     template <size_t ..._Indices> | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2314 |     _Rp | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2315 |     __execute(__tuple_indices<_Indices...>) | 
 | 2316 |     { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2317 |         return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...); | 
| Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame] | 2318 |     } | 
 | 2319 | }; | 
 | 2320 |  | 
| Marshall Clow | 3b3108e | 2013-11-03 22:06:53 +0000 | [diff] [blame] | 2321 | inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value ) | 
| Marshall Clow | ad2a600 | 2013-11-03 15:43:35 +0000 | [diff] [blame] | 2322 | { return (int(__policy) & int(__value)) != 0; } | 
 | 2323 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2324 | template <class _Fp, class... _Args> | 
 | 2325 | future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> | 
 | 2326 | async(launch __policy, _Fp&& __f, _Args&&... __args) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2327 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2328 |     typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF; | 
 | 2329 |     typedef typename _BF::_Rp _Rp; | 
| Marshall Clow | ad2a600 | 2013-11-03 15:43:35 +0000 | [diff] [blame] | 2330 |  | 
 | 2331 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2332 |     try | 
 | 2333 |     { | 
 | 2334 | #endif | 
 | 2335 |         if (__does_policy_contain(__policy, launch::async)) | 
 | 2336 |         return _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2337 |                                                      __decay_copy(_VSTD::forward<_Args>(__args))...)); | 
| Marshall Clow | ad2a600 | 2013-11-03 15:43:35 +0000 | [diff] [blame] | 2338 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2339 |     } | 
 | 2340 |     catch ( ... ) { if (__policy == launch::async) throw ; } | 
 | 2341 | #endif | 
 | 2342 |  | 
 | 2343 |     if (__does_policy_contain(__policy, launch::deferred)) | 
 | 2344 |         return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2345 |                                                         __decay_copy(_VSTD::forward<_Args>(__args))...)); | 
| Marshall Clow | ad2a600 | 2013-11-03 15:43:35 +0000 | [diff] [blame] | 2346 |     return future<_Rp>{}; | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2347 | } | 
 | 2348 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2349 | template <class _Fp, class... _Args> | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2350 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2351 | future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> | 
 | 2352 | async(_Fp&& __f, _Args&&... __args) | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2353 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2354 |     return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f), | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2355 |                                     _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | 54da338 | 2010-08-30 18:46:21 +0000 | [diff] [blame] | 2356 | } | 
 | 2357 |  | 
 | 2358 | #endif  // _LIBCPP_HAS_NO_VARIADICS | 
 | 2359 |  | 
| Howard Hinnant | e6e4d01 | 2010-09-03 21:46:37 +0000 | [diff] [blame] | 2360 | // shared_future | 
 | 2361 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2362 | template <class _Rp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2363 | class _LIBCPP_TYPE_VIS_ONLY shared_future | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2364 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2365 |     __assoc_state<_Rp>* __state_; | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2366 |  | 
 | 2367 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2368 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2369 |     shared_future() _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2370 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2371 |     shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) | 
 | 2372 |         {if (__state_) __state_->__add_shared();} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2373 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2374 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2375 |     shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2376 |         {__f.__state_ = nullptr;} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2377 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2378 |     shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2379 |         {__rhs.__state_ = nullptr;} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2380 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2381 |     ~shared_future(); | 
 | 2382 |     shared_future& operator=(const shared_future& __rhs); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2383 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2384 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2385 |     shared_future& operator=(shared_future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2386 |         { | 
 | 2387 |             shared_future(std::move(__rhs)).swap(*this); | 
 | 2388 |             return *this; | 
 | 2389 |         } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2390 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2391 |  | 
 | 2392 |     // retrieving the value | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2393 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2394 |     const _Rp& get() const {return __state_->copy();} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2395 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2396 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2397 |     void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2398 |  | 
 | 2399 |     // functions to check state | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2400 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2401 |     bool valid() const _NOEXCEPT {return __state_ != nullptr;} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2402 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2403 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2404 |     void wait() const {__state_->wait();} | 
 | 2405 |     template <class _Rep, class _Period> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2406 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2407 |         future_status | 
 | 2408 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 2409 |             {return __state_->wait_for(__rel_time);} | 
 | 2410 |     template <class _Clock, class _Duration> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2411 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2412 |         future_status | 
 | 2413 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 2414 |             {return __state_->wait_until(__abs_time);} | 
 | 2415 | }; | 
 | 2416 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2417 | template <class _Rp> | 
 | 2418 | shared_future<_Rp>::~shared_future() | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2419 | { | 
 | 2420 |     if (__state_) | 
 | 2421 |         __state_->__release_shared(); | 
 | 2422 | } | 
 | 2423 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2424 | template <class _Rp> | 
 | 2425 | shared_future<_Rp>& | 
 | 2426 | shared_future<_Rp>::operator=(const shared_future& __rhs) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2427 | { | 
 | 2428 |     if (__rhs.__state_) | 
 | 2429 |         __rhs.__state_->__add_shared(); | 
 | 2430 |     if (__state_) | 
 | 2431 |         __state_->__release_shared(); | 
 | 2432 |     __state_ = __rhs.__state_; | 
 | 2433 |     return *this; | 
 | 2434 | } | 
 | 2435 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2436 | template <class _Rp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2437 | class _LIBCPP_TYPE_VIS_ONLY shared_future<_Rp&> | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2438 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2439 |     __assoc_state<_Rp&>* __state_; | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2440 |  | 
 | 2441 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2442 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2443 |     shared_future() _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2444 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2445 |     shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) | 
 | 2446 |         {if (__state_) __state_->__add_shared();} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2447 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2448 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2449 |     shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2450 |         {__f.__state_ = nullptr;} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2451 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2452 |     shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2453 |         {__rhs.__state_ = nullptr;} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2454 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2455 |     ~shared_future(); | 
 | 2456 |     shared_future& operator=(const shared_future& __rhs); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2457 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2458 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2459 |     shared_future& operator=(shared_future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2460 |         { | 
 | 2461 |             shared_future(std::move(__rhs)).swap(*this); | 
 | 2462 |             return *this; | 
 | 2463 |         } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2464 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2465 |  | 
 | 2466 |     // retrieving the value | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2467 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2468 |     _Rp& get() const {return __state_->copy();} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2469 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2470 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2471 |     void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2472 |  | 
 | 2473 |     // functions to check state | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2474 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2475 |     bool valid() const _NOEXCEPT {return __state_ != nullptr;} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2476 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2477 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2478 |     void wait() const {__state_->wait();} | 
 | 2479 |     template <class _Rep, class _Period> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2480 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2481 |         future_status | 
 | 2482 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 2483 |             {return __state_->wait_for(__rel_time);} | 
 | 2484 |     template <class _Clock, class _Duration> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2485 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2486 |         future_status | 
 | 2487 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 2488 |             {return __state_->wait_until(__abs_time);} | 
 | 2489 | }; | 
 | 2490 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2491 | template <class _Rp> | 
 | 2492 | shared_future<_Rp&>::~shared_future() | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2493 | { | 
 | 2494 |     if (__state_) | 
 | 2495 |         __state_->__release_shared(); | 
 | 2496 | } | 
 | 2497 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2498 | template <class _Rp> | 
 | 2499 | shared_future<_Rp&>& | 
 | 2500 | shared_future<_Rp&>::operator=(const shared_future& __rhs) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2501 | { | 
 | 2502 |     if (__rhs.__state_) | 
 | 2503 |         __rhs.__state_->__add_shared(); | 
 | 2504 |     if (__state_) | 
 | 2505 |         __state_->__release_shared(); | 
 | 2506 |     __state_ = __rhs.__state_; | 
 | 2507 |     return *this; | 
 | 2508 | } | 
 | 2509 |  | 
 | 2510 | template <> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 2511 | class _LIBCPP_TYPE_VIS shared_future<void> | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2512 | { | 
 | 2513 |     __assoc_sub_state* __state_; | 
 | 2514 |  | 
 | 2515 | public: | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2516 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2517 |     shared_future() _NOEXCEPT : __state_(nullptr) {} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2518 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2519 |     shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) | 
 | 2520 |         {if (__state_) __state_->__add_shared();} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2521 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2522 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2523 |     shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2524 |         {__f.__state_ = nullptr;} | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2525 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2526 |     shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2527 |         {__rhs.__state_ = nullptr;} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2528 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2529 |     ~shared_future(); | 
 | 2530 |     shared_future& operator=(const shared_future& __rhs); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2531 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2532 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2533 |     shared_future& operator=(shared_future&& __rhs) _NOEXCEPT | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2534 |         { | 
 | 2535 |             shared_future(std::move(__rhs)).swap(*this); | 
 | 2536 |             return *this; | 
 | 2537 |         } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2538 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2539 |  | 
 | 2540 |     // retrieving the value | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2541 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2542 |     void get() const {__state_->copy();} | 
 | 2543 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2544 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2545 |     void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2546 |  | 
 | 2547 |     // functions to check state | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2548 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2549 |     bool valid() const _NOEXCEPT {return __state_ != nullptr;} | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2550 |  | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2551 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2552 |     void wait() const {__state_->wait();} | 
 | 2553 |     template <class _Rep, class _Period> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2554 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2555 |         future_status | 
 | 2556 |         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const | 
 | 2557 |             {return __state_->wait_for(__rel_time);} | 
 | 2558 |     template <class _Clock, class _Duration> | 
| Howard Hinnant | 8c6cbb2 | 2010-09-22 14:16:26 +0000 | [diff] [blame] | 2559 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2560 |         future_status | 
 | 2561 |         wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const | 
 | 2562 |             {return __state_->wait_until(__abs_time);} | 
 | 2563 | }; | 
 | 2564 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2565 | template <class _Rp> | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2566 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 2567 | void | 
| Howard Hinnant | 8bf01dd | 2012-07-21 17:46:55 +0000 | [diff] [blame] | 2568 | swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT | 
| Howard Hinnant | 99be823 | 2010-09-03 18:39:25 +0000 | [diff] [blame] | 2569 | { | 
 | 2570 |     __x.swap(__y); | 
 | 2571 | } | 
 | 2572 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2573 | template <class _Rp> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 2574 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2575 | shared_future<_Rp> | 
 | 2576 | future<_Rp>::share() | 
| Howard Hinnant | e6e4d01 | 2010-09-03 21:46:37 +0000 | [diff] [blame] | 2577 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2578 |     return shared_future<_Rp>(_VSTD::move(*this)); | 
| Howard Hinnant | e6e4d01 | 2010-09-03 21:46:37 +0000 | [diff] [blame] | 2579 | } | 
 | 2580 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2581 | template <class _Rp> | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 2582 | inline | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2583 | shared_future<_Rp&> | 
 | 2584 | future<_Rp&>::share() | 
| Howard Hinnant | e6e4d01 | 2010-09-03 21:46:37 +0000 | [diff] [blame] | 2585 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2586 |     return shared_future<_Rp&>(_VSTD::move(*this)); | 
| Howard Hinnant | 7de4790 | 2010-11-30 20:23:32 +0000 | [diff] [blame] | 2587 | } | 
 | 2588 |  | 
| Howard Hinnant | a445151 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 2589 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 2590 |  | 
| Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame^] | 2591 | inline | 
| Howard Hinnant | 7de4790 | 2010-11-30 20:23:32 +0000 | [diff] [blame] | 2592 | shared_future<void> | 
 | 2593 | future<void>::share() | 
 | 2594 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2595 |     return shared_future<void>(_VSTD::move(*this)); | 
| Howard Hinnant | e6e4d01 | 2010-09-03 21:46:37 +0000 | [diff] [blame] | 2596 | } | 
 | 2597 |  | 
| Howard Hinnant | a445151 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 2598 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 2599 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2600 | _LIBCPP_END_NAMESPACE_STD | 
 | 2601 |  | 
| Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 2602 | #endif // !_LIBCPP_HAS_NO_THREADS | 
 | 2603 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2604 | #endif  // _LIBCPP_FUTURE |