- File:
-
- 1 edited
-
libcfa/src/concurrency/locks.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r454f478 rac5816d 7 7 //----------------------------------------------------------------------------- 8 8 // info_thread 9 forall( L &| is_blocking_lock(L)) {9 forall(dtype L | is_blocking_lock(L)) { 10 10 struct info_thread { 11 11 // used to put info_thread on a dl queue (aka sequence) … … 195 195 //----------------------------------------------------------------------------- 196 196 // alarm node wrapper 197 forall( L &| is_blocking_lock(L)) {197 forall(dtype L | is_blocking_lock(L)) { 198 198 struct alarm_node_wrap { 199 199 alarm_node_t alarm_node; … … 239 239 //----------------------------------------------------------------------------- 240 240 // condition variable 241 forall( L &| is_blocking_lock(L)) {241 forall(dtype L | is_blocking_lock(L)) { 242 242 243 243 void ?{}( condition_variable(L) & this ){ … … 356 356 bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) { WAIT_TIME( info, &l , time ) } 357 357 } 358 359 //-----------------------------------------------------------------------------360 // Semaphore361 void ?{}( semaphore & this, int count = 1 ) {362 (this.lock){};363 this.count = count;364 (this.waiting){};365 }366 void ^?{}(semaphore & this) {}367 368 bool P(semaphore & this) with( this ){369 lock( lock __cfaabi_dbg_ctx2 );370 count -= 1;371 if ( count < 0 ) {372 // queue current task373 append( waiting, active_thread() );374 375 // atomically release spin lock and block376 unlock( lock );377 park();378 return true;379 }380 else {381 unlock( lock );382 return false;383 }384 }385 386 bool V(semaphore & this) with( this ) {387 $thread * thrd = 0p;388 lock( lock __cfaabi_dbg_ctx2 );389 count += 1;390 if ( count <= 0 ) {391 // remove task at head of waiting list392 thrd = pop_head( waiting );393 }394 395 unlock( lock );396 397 // make new owner398 unpark( thrd );399 400 return thrd != 0p;401 }402 403 bool V(semaphore & this, unsigned diff) with( this ) {404 $thread * thrd = 0p;405 lock( lock __cfaabi_dbg_ctx2 );406 int release = max(-count, (int)diff);407 count += diff;408 for(release) {409 unpark( pop_head( waiting ) );410 }411 412 unlock( lock );413 414 return thrd != 0p;415 }
Note:
See TracChangeset
for help on using the changeset viewer.