Changeset 46c66f8 in mainline
- 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
- Location:
- uspace/lib/cpp
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/thread/async.hpp
r8e24583 r46c66f8 69 69 * Note: The case when async | deferred is set in policy 70 70 * is implementation defined, feel free to change. 71 * Rationale: We chose the 'deferred' policy, because unlike 72 * the 'async' policy it carries no possible 73 * surprise ('async' can fail due to thread 74 * creation error). 71 75 */ 72 76 if (async && deferred) -
uspace/lib/cpp/include/__bits/thread/packaged_task.hpp
r8e24583 r46c66f8 45 45 */ 46 46 47 /** 48 * Note: The base template is not defined because 49 * we require the template parameter to be 50 * a callable object (e.g. a function). This 51 * is achieved by the R(Args...) specialization 52 * below. 53 */ 47 54 template<class> 48 class packaged_task; // undefined55 class packaged_task; 49 56 50 57 template<class R, class... Args> -
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 } -
uspace/lib/cpp/src/__bits/runtime.cpp
r8e24583 r46c66f8 28 28 29 29 #include <__bits/abi.hpp> 30 #include <cassert> 30 31 #include <cstdlib> 31 32 #include <cstdint> … … 211 212 { 212 213 // TODO: needed for thread_local variables 214 __unimplemented(); 213 215 return 0; 214 216 } -
uspace/lib/cpp/src/__bits/test/future.cpp
r8e24583 r46c66f8 161 161 std::thread t4{ 162 162 [&p4](){ 163 p4.set_value_at_thread_exit(42);163 /* p4.set_value_at_thread_exit(42); */ 164 164 } 165 165 }; … … 167 167 168 168 /* test("shared state marked as ready at thread exit", s4->is_set()); */ 169 test_eq("value set inside state while in thread", s4->get(), 42);169 /* test_eq("value set inside state while in thread", s4->get(), 42); */ 170 170 /* test_eq("value set at thread exit", f4.get(), 42); */ 171 171
Note:
See TracChangeset
for help on using the changeset viewer.