Changeset a552044 in mainline
- Timestamp:
- 2019-07-01T15:10:08Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a6c3bf3
- Parents:
- 0fc6b6c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/thread/shared_future.hpp
r0fc6b6c ra552044 30 30 #define LIBCPP_BITS_THREAD_SHARED_FUTURE 31 31 32 #include <__bits/thread/future.hpp> 33 34 /** 35 * Note: We do synchronization directly on the shared 36 * state, this means that with the exception of 37 * some member functions (which are only defined 38 * for specializations anyway) our future and 39 * shared_future are basically identical. Because 40 * of that, we can use aux::future_base for 41 * shared_future as well. 42 */ 43 32 44 namespace std 33 45 { … … 36 48 */ 37 49 38 // TODO: Make sure the move-future constructor of shared_future39 // invalidates the state (i.e. sets to nullptr).40 50 template<class R> 41 class shared_future 51 class shared_future: public aux::future_base<R> 42 52 { 43 // TODO: Copy & modify once future is done. 53 public: 54 shared_future() noexcept = default; 55 56 shared_future(const shared_future&) = default; 57 58 shared_future(shared_future&&) noexcept = default; 59 60 shared_future(future<R>&& rhs) 61 : aux::future_base<R>{move(rhs.state_)} 62 { 63 rhs.state_ = nullptr; 64 } 65 66 shared_future& operator=(const shared_future&) = default; 67 68 shared_future& operator=(shared_future&&) noexcept = default; 69 70 const R& get() const 71 { 72 assert(this->state_); 73 74 this->wait(); 75 76 if (this->state_->has_exception()) 77 this->state_->throw_stored_exception(); 78 79 return move(this->state_->get()); 80 } 44 81 }; 45 82 46 83 template<class R> 47 class shared_future<R&> 84 class shared_future<R&>: public aux::future_base<R*> 48 85 { 49 // TODO: Copy & modify once future is done. 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 } 50 115 }; 51 116 52 117 template<> 53 class shared_future<void> 118 class shared_future<void>: public aux::future_base<void> 54 119 { 55 // TODO: Copy & modify once future is done. 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(); 145 } 56 146 }; 147 148 shared_future<void> future<void>::share() 149 { 150 return shared_future<void>{move(*this)}; 151 } 57 152 } 58 153
Note:
See TracChangeset
for help on using the changeset viewer.