Changeset 8660ad0 in mainline
- Timestamp:
- 2019-07-01T15:42:54Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1621f91
- Parents:
- a6c3bf3
- Location:
- uspace/lib/cpp/include/__bits/thread
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/thread/future.hpp
ra6c3bf3 r8660ad0 171 171 172 172 template<class R> 173 class future: public aux::future_base< R>173 class future: public aux::future_base<aux::future_inner_t<R>> 174 174 { 175 175 friend class shared_future<R>; … … 177 177 public: 178 178 future() noexcept 179 : aux::future_base< R>{}179 : aux::future_base<aux::future_inner_t<R>>{} 180 180 { /* DUMMY BODY */ } 181 181 … … 183 183 184 184 future(future&& rhs) noexcept 185 : aux::future_base< R>{move(rhs.state_)}185 : aux::future_base<aux::future_inner_t<R>>{move(rhs.state_)} 186 186 { /* DUMMY BODY */ } 187 187 188 future(aux::shared_state< R>* state)189 : aux::future_base< R>{state}188 future(aux::shared_state<aux::future_inner_t<R>>* state) 189 : aux::future_base<aux::future_inner_t<R>>{state} 190 190 { /* DUMMY BODY */ } 191 191 … … 199 199 } 200 200 201 Rget()201 aux::future_return_t<R> get() 202 202 { 203 203 assert(this->state_); … … 208 208 this->state_->throw_stored_exception(); 209 209 210 return move(this->state_->get()); 211 } 212 }; 213 214 template<class R> 215 class future<R&>: public aux::future_base<R*> 216 { 217 friend class shared_future<R&>; 218 219 public: 220 future() noexcept 221 : aux::future_base<R*>{} 222 { /* DUMMY BODY */ } 223 224 future(const future&) = delete; 225 226 future(future&& rhs) noexcept 227 : aux::future_base<R*>{move(rhs.state_)} 228 { /* DUMMY BODY */ } 229 230 future(aux::shared_state<R*>* state) 231 : aux::future_base<R*>{state} 232 { /* DUMMY BODY */ } 233 234 future& operator=(const future&) = delete; 235 236 future& operator=(future&& rhs) noexcept = default; 237 238 shared_future<R&> share() 239 { 240 return shared_future<R&>{move(*this)}; 241 } 242 243 R& get() 244 { 245 assert(this->state_); 246 247 this->wait(); 248 249 if (this->state_->has_exception()) 250 this->state_->throw_stored_exception(); 251 252 assert(this->state_->get()); 253 return *this->state_->get(); 254 } 255 }; 256 257 template<> 258 class future<void>: public aux::future_base<void> 259 { 260 friend class shared_future<void>; 261 262 public: 263 future() noexcept 264 : aux::future_base<void>{} 265 { /* DUMMY BODY */ } 266 267 future(const future&) = delete; 268 269 future(future&& rhs) noexcept 270 : aux::future_base<void>{move(rhs.state_)} 271 { /* DUMMY BODY */ } 272 273 future(aux::shared_state<void>* state) 274 : aux::future_base<void>{state} 275 { /* DUMMY BODY */ } 276 277 future& operator=(const future&) = delete; 278 279 future& operator=(future&& rhs) noexcept = default; 280 281 /** 282 * Note: This is just forward declaration, implementation 283 * provided in shared_future.hpp to avoid problems 284 * with incomplete types. 285 */ 286 shared_future<void> share(); 287 288 void get() 289 { 290 assert(this->state_); 291 292 this->wait(); 293 294 if (this->state_->has_exception()) 295 this->state_->throw_stored_exception(); 210 if constexpr (!is_same_v<R, void>) 211 { 212 if constexpr (is_reference_v<R>) 213 { 214 assert(this->state_->get()); 215 216 return *this->state_->get(); 217 } 218 else 219 return this->state_->get(); 220 } 296 221 } 297 222 }; -
uspace/lib/cpp/include/__bits/thread/shared_future.hpp
ra6c3bf3 r8660ad0 97 97 } 98 98 }; 99 100 shared_future<void> future<void>::share()101 {102 return shared_future<void>{move(*this)};103 }104 99 } 105 100
Note:
See TracChangeset
for help on using the changeset viewer.