Changeset 46c66f8 in mainline for uspace/lib/cpp/include/__bits/thread/shared_state.hpp
- Timestamp:
- 2019-07-07T12:59:11Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8c0b781
- Parents:
- 8e24583
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/thread/shared_state.hpp
r8e24583 r46c66f8 93 93 } 94 94 95 /** 96 * TODO: This member function is supposed to be marked 97 * as 'const'. In such a case, however, we cannot 98 * use the underlying fibril API because these 99 * references get converted to pointers and the API 100 * does not accept e.g. 'const fibril_condvar_t*'. 101 * 102 * The same applies to the wait_for and wait_until 103 * functions. 104 */ 105 virtual void wait() 106 { 107 aux::threading::mutex::lock(mutex_); 95 virtual void wait() const 96 { 97 aux::threading::mutex::lock( 98 const_cast<aux::mutex_t&>(mutex_) 99 ); 100 108 101 while (!value_set_) 109 aux::threading::condvar::wait(condvar_, mutex_); 110 aux::threading::mutex::unlock(mutex_); 102 { 103 aux::threading::condvar::wait( 104 const_cast<aux::condvar_t&>(condvar_), 105 const_cast<aux::mutex_t&>(mutex_) 106 ); 107 } 108 109 aux::threading::mutex::unlock( 110 const_cast<aux::mutex_t&>(mutex_) 111 ); 111 112 } 112 113 113 114 template<class Rep, class Period> 114 115 future_status 115 wait_for(const chrono::duration<Rep, Period>& rel_time) 116 wait_for(const chrono::duration<Rep, Period>& rel_time) const 116 117 { 117 118 if (value_set_) 118 119 return future_status::ready; 119 120 120 aux::threading::mutex::lock(mutex_); 121 aux::threading::mutex::lock( 122 const_cast<aux::mutex_t&>(mutex_) 123 ); 124 121 125 auto res = timed_wait_( 122 126 aux::threading::time::convert(rel_time) 123 127 ); 124 aux::threading::mutex::unlock(mutex_); 128 129 aux::threading::mutex::unlock( 130 const_cast<aux::mutex_t&>(mutex_) 131 ); 125 132 126 133 return res; … … 134 141 return future_status::ready; 135 142 136 aux::threading::mutex::lock(mutex_); 143 aux::threading::mutex::lock( 144 const_cast<aux::mutex_t&>(mutex_) 145 ); 146 137 147 auto res = timed_wait_( 138 148 aux::threading::time::convert(abs_time - Clock::now()) 139 149 ); 140 aux::threading::mutex::unlock(mutex_); 150 151 aux::threading::mutex::unlock( 152 const_cast<aux::mutex_t&>(mutex_) 153 ); 141 154 142 155 return res; … … 164 177 * children). 165 178 */ 166 virtual future_status timed_wait_(aux::time_unit_t time) 179 virtual future_status timed_wait_(aux::time_unit_t time) const 167 180 { 168 181 auto res = aux::threading::condvar::wait_for( 169 condvar_, mutex_, time 182 const_cast<aux::condvar_t&>(condvar_), 183 const_cast<aux::mutex_t&>(mutex_), time 170 184 ); 171 185 … … 289 303 } 290 304 291 void wait() override305 void wait() const override 292 306 { 293 307 if (!this->is_set()) 294 thread_.join();308 const_cast<thread&>(thread_).join(); 295 309 } 296 310 … … 301 315 302 316 protected: 303 future_status timed_wait_(aux::time_unit_t time) override317 future_status timed_wait_(aux::time_unit_t time) const override 304 318 { 305 319 /** … … 336 350 } 337 351 338 void wait() override352 void wait() const override 339 353 { 340 354 /** … … 342 356 */ 343 357 if (!this->is_set()) 344 invoke_(make_index_sequence<sizeof...(Args)>{}); 358 { 359 const_cast< 360 deferred_shared_state<R, F, Args...>* 361 >(this)->invoke_(make_index_sequence<sizeof...(Args)>{}); 362 } 345 363 } 346 364 … … 373 391 } 374 392 375 future_status timed_wait_(aux::time_unit_t) override393 future_status timed_wait_(aux::time_unit_t) const override 376 394 { 377 395 /** … … 398 416 { 399 417 // TODO: implement 418 __unimplemented(); 400 419 } 401 420 … … 404 423 { 405 424 // TODO: implement 425 __unimplemented(); 406 426 } 407 427 }
Note:
See TracChangeset
for help on using the changeset viewer.