Changeset 0f43be5 in mainline
- Timestamp:
- 2019-07-01T13:19:05Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0d299c93
- Parents:
- 396b234
- Location:
- uspace/lib/cpp/include/__bits/thread
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/thread/future.hpp
r396b234 r0f43be5 192 192 193 193 template<class R> 194 class future<R&>: public aux::future_base<R &>194 class future<R&>: public aux::future_base<R*> 195 195 { 196 196 public: 197 197 future() noexcept 198 : aux::future_base<R &>{}198 : aux::future_base<R*>{} 199 199 { /* DUMMY BODY */ } 200 200 … … 202 202 203 203 future(future&& rhs) noexcept 204 : aux::future_base<R &>{move(rhs.state_)}205 { /* DUMMY BODY */ } 206 207 future(aux::shared_state<R &>* state)208 : aux::future_base<R &>{state}204 : aux::future_base<R*>{move(rhs.state_)} 205 { /* DUMMY BODY */ } 206 207 future(aux::shared_state<R*>* state) 208 : aux::future_base<R*>{state} 209 209 { /* DUMMY BODY */ } 210 210 … … 227 227 this->state_->throw_stored_exception(); 228 228 229 return this->state_->get(); 229 assert(this->state_->get()); 230 return *this->state_->get(); 230 231 } 231 232 }; -
uspace/lib/cpp/include/__bits/thread/promise.hpp
r396b234 r0f43be5 75 75 { 76 76 abandon_state_(); 77 promise_base{ std::move(rhs)}.swap(*this);77 promise_base{move(rhs)}.swap(*this); 78 78 79 79 return *this; … … 85 85 { 86 86 std::swap(state_, other.state_); 87 }88 89 future<R> get_future()90 {91 return future<R>{state_};92 87 } 93 88 … … 165 160 promise& operator=(const promise&) = delete; 166 161 162 future<R> get_future() 163 { 164 return future<R>{this->state_}; 165 } 166 167 167 void set_value(const R& val) 168 168 { … … 190 190 } 191 191 192 this->state_->set_value( std::forward<R>(val), true);192 this->state_->set_value(forward<R>(val), true); 193 193 } 194 194 … … 219 219 } 220 220 221 this->state_->set_value( std::forward<R>(val), false);221 this->state_->set_value(forward<R>(val), false); 222 222 // TODO: schedule it to be set as ready when thread exits 223 223 } … … 225 225 226 226 template<class R> 227 class promise<R&>: public aux::promise_base<R >228 { // TODO: I'm afraid we will need aux::shared_state<R&> specialization for this :/227 class promise<R&>: public aux::promise_base<R*> 228 { 229 229 public: 230 230 promise() 231 : aux::promise_base<R &>{}231 : aux::promise_base<R*>{} 232 232 { /* DUMMY BODY */ } 233 233 234 234 template<class Allocator> 235 235 promise(allocator_arg_t, const Allocator& a) 236 : aux::promise_base<R &>{}236 : aux::promise_base<R*>{} 237 237 { 238 238 // TODO: Use the allocator. … … 240 240 241 241 promise(promise&& rhs) noexcept 242 : aux::promise_base<R &>{move(rhs)}242 : aux::promise_base<R*>{move(rhs)} 243 243 { /* DUMMY BODY */ } 244 244 … … 250 250 251 251 promise& operator=(const promise&) = delete; 252 253 future<R&> get_future() 254 { 255 return future<R&>{this->state_}; 256 } 257 258 void set_value(R& val) 259 { 260 if (!this->state_) 261 throw future_error{make_error_code(future_errc::no_state)}; 262 if (this->state_->is_set()) 263 { 264 throw future_error{ 265 make_error_code(future_errc::promise_already_satisfied) 266 }; 267 } 268 269 this->state_->set_value(&val, true); 270 } 271 272 void set_value_at_thread_exit(R& val) 273 { 274 if (!this->state_) 275 throw future_error{make_error_code(future_errc::no_state)}; 276 if (this->state_->is_set()) 277 { 278 throw future_error{ 279 make_error_code(future_errc::promise_already_satisfied) 280 }; 281 } 282 283 this->state_->set_value(&val, false); 284 // TODO: schedule it to be set as ready when thread exits 285 } 252 286 }; 253 287 … … 278 312 279 313 promise& operator=(const promise&) = delete; 314 315 future<void> get_future() 316 { 317 return future<void>{this->state_}; 318 } 280 319 281 320 void set_value()
Note:
See TracChangeset
for help on using the changeset viewer.