- File:
-
- 1 edited
-
libcfa/src/concurrency/locks.cfa (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
re84ab3d r43784ac 28 28 forall(L & | is_blocking_lock(L)) { 29 29 struct info_thread { 30 // used to put info_thread on a dl queue 31 inline dlink(info_thread(L));30 // used to put info_thread on a dl queue (aka sequence) 31 inline Seqable; 32 32 33 33 // waiting thread 34 struct thread$* t;34 struct $thread * t; 35 35 36 36 // shadow field … … 43 43 bool signalled; 44 44 }; 45 P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) ) 46 47 void ?{}( info_thread(L) & this, thread$ * t, uintptr_t info, L * l ) {45 46 void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) { 47 ((Seqable &) this){}; 48 48 this.t = t; 49 49 this.info = info; … … 52 52 53 53 void ^?{}( info_thread(L) & this ) {} 54 55 info_thread(L) *& Back( info_thread(L) * this ) { 56 return (info_thread(L) *)Back( (Seqable *)this ); 57 } 58 59 info_thread(L) *& Next( info_thread(L) * this ) { 60 return (info_thread(L) *)Next( (Colable *)this ); 61 } 54 62 } 55 63 … … 71 79 void lock( blocking_lock & this ) with( this ) { 72 80 lock( lock __cfaabi_dbg_ctx2 ); 73 thread$* thrd = active_thread();81 $thread * thrd = active_thread(); 74 82 75 83 // single acquisition lock is held by current thread … … 78 86 // lock is held by some other thread 79 87 if ( owner != 0p && owner != thrd ) { 80 insert_last( blocked_threads, *thrd );88 addTail( blocked_threads, *thrd ); 81 89 wait_count++; 82 90 unlock( lock ); … … 117 125 118 126 void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 119 thread$ * t = &try_pop_front( blocked_threads );127 $thread * t = &dropHead( blocked_threads ); 120 128 owner = t; 121 129 recursion_count = ( t ? 1 : 0 ); … … 142 150 } 143 151 144 void on_notify( blocking_lock & this, thread$* t ) with( this ) {152 void on_notify( blocking_lock & this, $thread * t ) with( this ) { 145 153 lock( lock __cfaabi_dbg_ctx2 ); 146 154 // lock held 147 155 if ( owner != 0p ) { 148 insert_last( blocked_threads, *t );156 addTail( blocked_threads, *t ); 149 157 wait_count++; 150 158 unlock( lock ); … … 199 207 // may still be called after a thread has been removed from the queue but 200 208 // before the alarm is unregistered 201 if ( (*info_thd)`isListed) { // is thread on queue209 if ( listed(info_thd) ) { // is thread on queue 202 210 info_thd->signalled = false; 203 211 // remove this thread O(1) 204 remove( *info_thd );212 remove( cond->blocked_threads, *info_thd ); 205 213 cond->count--; 206 214 if( info_thd->lock ) { … … 247 255 bool notify_one( condition_variable(L) & this ) with( this ) { 248 256 lock( lock __cfaabi_dbg_ctx2 ); 249 bool ret = ! blocked_threads`isEmpty;250 process_popped(this, try_pop_front( blocked_threads ));257 bool ret = !empty(blocked_threads); 258 process_popped(this, dropHead( blocked_threads )); 251 259 unlock( lock ); 252 260 return ret; … … 255 263 bool notify_all( condition_variable(L) & this ) with(this) { 256 264 lock( lock __cfaabi_dbg_ctx2 ); 257 bool ret = ! blocked_threads`isEmpty;258 while( ! blocked_threads`isEmpty) {259 process_popped(this, try_pop_front( blocked_threads ));265 bool ret = !empty(blocked_threads); 266 while( !empty(blocked_threads) ) { 267 process_popped(this, dropHead( blocked_threads )); 260 268 } 261 269 unlock( lock ); … … 264 272 265 273 uintptr_t front( condition_variable(L) & this ) with(this) { 266 return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;274 return empty(blocked_threads) ? NULL : head(blocked_threads).info; 267 275 } 268 276 269 277 bool empty( condition_variable(L) & this ) with(this) { 270 278 lock( lock __cfaabi_dbg_ctx2 ); 271 bool ret = blocked_threads`isEmpty;279 bool ret = empty(blocked_threads); 272 280 unlock( lock ); 273 281 return ret; … … 278 286 size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) { 279 287 // add info_thread to waiting queue 280 insert_last( blocked_threads, *i );288 addTail( blocked_threads, *i ); 281 289 count++; 282 290 size_t recursion_count = 0; … … 366 374 } 367 375 368 thread$* V (semaphore & this, const bool doUnpark ) with( this ) {369 thread$* thrd = 0p;376 $thread * V (semaphore & this, const bool doUnpark ) with( this ) { 377 $thread * thrd = 0p; 370 378 lock( lock __cfaabi_dbg_ctx2 ); 371 379 count += 1; … … 384 392 385 393 bool V(semaphore & this) with( this ) { 386 thread$* thrd = V(this, true);394 $thread * thrd = V(this, true); 387 395 return thrd != 0p; 388 396 } 389 397 390 398 bool V(semaphore & this, unsigned diff) with( this ) { 391 thread$* thrd = 0p;399 $thread * thrd = 0p; 392 400 lock( lock __cfaabi_dbg_ctx2 ); 393 401 int release = max(-count, (int)diff);
Note:
See TracChangeset
for help on using the changeset viewer.