Changeset a6c3bf3 in mainline for uspace/lib/cpp/include/__bits/thread/shared_future.hpp
- Timestamp:
- 2019-07-01T15:33:01Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8660ad0
- Parents:
- a552044
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/thread/shared_future.hpp
ra552044 ra6c3bf3 31 31 32 32 #include <__bits/thread/future.hpp> 33 #include <__bits/thread/future_common.hpp> 34 #include <type_traits> 33 35 34 36 /** … … 49 51 50 52 template<class R> 51 class shared_future: public aux::future_base< R>53 class shared_future: public aux::future_base<aux::future_inner_t<R>> 52 54 { 53 55 public: … … 59 61 60 62 shared_future(future<R>&& rhs) 61 : aux::future_base< R>{move(rhs.state_)}63 : aux::future_base<aux::future_inner_t<R>>{move(rhs.state_)} 62 64 { 63 65 rhs.state_ = nullptr; … … 68 70 shared_future& operator=(shared_future&&) noexcept = default; 69 71 70 const R&get() const72 aux::future_return_t<R> get() const 71 73 { 72 74 assert(this->state_); … … 77 79 this->state_->throw_stored_exception(); 78 80 79 return move(this->state_->get()); 80 } 81 }; 81 /** 82 * Using constexpr if and the future_inner and future_result 83 * metafunctions we can actually avoid having to create specializations 84 * for R& and void in this case. 85 */ 86 if constexpr (!is_same_v<R, void>) 87 { 88 if constexpr (is_reference_v<R>) 89 { 90 assert(this->state_->get()); 82 91 83 template<class R> 84 class shared_future<R&>: public aux::future_base<R*> 85 { 86 public: 87 shared_future() noexcept = default; 88 89 shared_future(const shared_future&) = default; 90 91 shared_future(shared_future&&) noexcept = default; 92 93 shared_future(future<R&>&& rhs) 94 : aux::future_base<R*>{move(rhs.state_)} 95 { 96 rhs.state_ = nullptr; 97 } 98 99 shared_future& operator=(const shared_future&) = default; 100 101 shared_future& operator=(shared_future&&) noexcept = default; 102 103 R& get() const 104 { 105 assert(this->state_); 106 107 this->wait(); 108 109 if (this->state_->has_exception()) 110 this->state_->throw_stored_exception(); 111 112 assert(this->state_->get()); 113 return *this->state_->get(); 114 } 115 }; 116 117 template<> 118 class shared_future<void>: public aux::future_base<void> 119 { 120 public: 121 shared_future() noexcept = default; 122 123 shared_future(const shared_future&) = default; 124 125 shared_future(shared_future&&) noexcept = default; 126 127 shared_future(future<void>&& rhs) 128 : aux::future_base<void>{move(rhs.state_)} 129 { 130 rhs.state_ = nullptr; 131 } 132 133 shared_future& operator=(const shared_future&) = default; 134 135 shared_future& operator=(shared_future&&) noexcept = default; 136 137 void get() const 138 { 139 assert(this->state_); 140 141 this->wait(); 142 143 if (this->state_->has_exception()) 144 this->state_->throw_stored_exception(); 92 return *this->state_->get(); 93 } 94 else 95 return this->state_->get(); 96 } 145 97 } 146 98 };
Note:
See TracChangeset
for help on using the changeset viewer.