Changeset 74ec742 for libcfa/src/concurrency/locks.cfa
- Timestamp:
- May 20, 2022, 10:36:45 AM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 25fa20a
- Parents:
- 29d8c02 (diff), 7831e8fb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r29d8c02 r74ec742 24 24 #include <stdlib.hfa> 25 25 26 #pragma GCC visibility push(default) 27 26 28 //----------------------------------------------------------------------------- 27 29 // info_thread … … 116 118 } 117 119 118 void pop_and_set_new_owner( blocking_lock & this ) with( this ) {120 static void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 119 121 thread$ * t = &try_pop_front( blocked_threads ); 120 122 owner = t; … … 192 194 void ^?{}( alarm_node_wrap(L) & this ) { } 193 195 194 void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {196 static void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) { 195 197 // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin. 196 198 lock( cond->lock __cfaabi_dbg_ctx2 ); … … 216 218 217 219 // this casts the alarm node to our wrapped type since we used type erasure 218 void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); }220 static void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); } 219 221 } 220 222 221 223 //----------------------------------------------------------------------------- 222 // condition variable224 // Synchronization Locks 223 225 forall(L & | is_blocking_lock(L)) { 224 226 227 //----------------------------------------------------------------------------- 228 // condition variable 225 229 void ?{}( condition_variable(L) & this ){ 226 230 this.lock{}; … … 231 235 void ^?{}( condition_variable(L) & this ){ } 232 236 233 void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {237 static void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) { 234 238 if(&popped != 0p) { 235 239 popped.signalled = true; … … 276 280 int counter( condition_variable(L) & this ) with(this) { return count; } 277 281 278 s ize_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {282 static size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) { 279 283 // add info_thread to waiting queue 280 284 insert_last( blocked_threads, *i ); … … 289 293 290 294 // helper for wait()'s' with no timeout 291 void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {295 static void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) { 292 296 lock( lock __cfaabi_dbg_ctx2 ); 293 297 size_t recursion_count = queue_and_get_recursion(this, &i); … … 306 310 307 311 // helper for wait()'s' with a timeout 308 void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {312 static void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) { 309 313 lock( lock __cfaabi_dbg_ctx2 ); 310 314 size_t recursion_count = queue_and_get_recursion(this, &info); … … 337 341 bool wait( condition_variable(L) & this, L & l, Duration duration ) with(this) { WAIT_TIME( 0 , &l , duration ) } 338 342 bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { WAIT_TIME( info, &l , duration ) } 343 344 //----------------------------------------------------------------------------- 345 // fast_cond_var 346 void ?{}( fast_cond_var(L) & this ){ 347 this.blocked_threads{}; 348 #ifdef __CFA_DEBUG__ 349 this.lock_used = 0p; 350 #endif 351 } 352 void ^?{}( fast_cond_var(L) & this ){ } 353 354 bool notify_one( fast_cond_var(L) & this ) with(this) { 355 bool ret = ! blocked_threads`isEmpty; 356 if ( ret ) { 357 info_thread(L) & popped = try_pop_front( blocked_threads ); 358 on_notify(*popped.lock, popped.t); 359 } 360 return ret; 361 } 362 bool notify_all( fast_cond_var(L) & this ) with(this) { 363 bool ret = ! blocked_threads`isEmpty; 364 while( ! blocked_threads`isEmpty ) { 365 info_thread(L) & popped = try_pop_front( blocked_threads ); 366 on_notify(*popped.lock, popped.t); 367 } 368 return ret; 369 } 370 371 uintptr_t front( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; } 372 bool empty ( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty; } 373 374 void wait( fast_cond_var(L) & this, L & l ) { 375 wait( this, l, 0 ); 376 } 377 378 void wait( fast_cond_var(L) & this, L & l, uintptr_t info ) with(this) { 379 // brand cond lock with lock 380 #ifdef __CFA_DEBUG__ 381 if ( lock_used == 0p ) lock_used = &l; 382 else { assert(lock_used == &l); } 383 #endif 384 info_thread( L ) i = { active_thread(), info, &l }; 385 insert_last( blocked_threads, i ); 386 size_t recursion_count = on_wait( *i.lock ); 387 park( ); 388 on_wakeup(*i.lock, recursion_count); 389 } 339 390 } 340 391
Note:
See TracChangeset
for help on using the changeset viewer.