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