Changeset e426c6f
- Timestamp:
- Mar 26, 2026, 10:40:39 PM (3 hours ago)
- Branches:
- master
- Parents:
- 6cbc5a62
- File:
-
- 1 edited
-
libcfa/src/concurrency/monitor.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/monitor.cfa
r6cbc5a62 re426c6f 10 10 // Created On : Thd Feb 23 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Nov 4 22:03:41 202513 // Update Count : 8212 // Last Modified On : Thu Mar 26 22:37:42 2026 13 // Update Count : 91 14 14 // 15 15 … … 493 493 } 494 494 495 bool signal( condition & this ) libcfa_public { 496 if ( empty( this ) ) { return false; } 497 498 //Check that everything is as expected 499 verify( this.monitors ); 500 verify( this.monitor_count != 0 ); 501 502 //Some more checking in debug 503 __cfaabi_dbg_debug_do( 495 bool signal( condition & this ) libcfa_public with( this ) { 496 if ( empty( this ) ) { return false; } 497 498 verifyf( monitors != 0p, "Waiting with no monitors (%p)", monitors ); 499 verifyf( monitor_count != 0, "Waiting with 0 monitors (%"PRIiFAST16")", monitor_count ); 500 501 __cfaabi_dbg_debug_do( // more checking in debug 504 502 thread$ * this_thrd = active_thread(); 505 if ( this.monitor_count != this_thrd->monitors.size ) { 506 abort( "Signal on condition %p made with different number of monitor(s), expected %zi got %zi", &this, this.monitor_count, this_thrd->monitors.size ); 507 } 508 509 for ( i; this.monitor_count ) { 510 if ( this.monitors[i] != this_thrd->monitors[i] ) { 511 abort( "Signal on condition %p made with different monitor, expected %p got %p", &this, this.monitors[i], this_thrd->monitors[i] ); 512 } 513 } 503 if ( monitor_count != this_thrd->monitors.size ) { 504 abort( "Signal on condition %p made with different number of monitor(s), expected %zi got %zi", 505 &this, monitor_count, this_thrd->monitors.size ); 506 } // if 507 508 for ( i; monitor_count ) { 509 if ( monitors[i] != this_thrd->monitors[i] ) { 510 abort( "Signal on condition %p made with different monitor, expected %p got %p", 511 &this, monitors[i], this_thrd->monitors[i] ); 512 } // if 513 } // for 514 514 ); 515 515 516 __lock_size_t count = this.monitor_count; 517 518 // Lock all monitors 519 lock_all( this.monitors, 0p, count ); 520 521 //Pop the head of the waiting queue 522 __condition_node_t * node = pop_head( this.blocked ); 523 524 //Add the thread to the proper AS stack 525 for ( i; count ) { 516 __lock_size_t count = monitor_count; 517 lock_all( monitors, 0p, count ); // lock all monitors 518 __condition_node_t * node = pop_head( blocked ); // pop head of waiting queue 519 520 for ( i; count ) { // add threads to the proper AS stack 526 521 __condition_criterion_t * crit = &node->criteria[i]; 527 522 assert( ! crit->ready ); 528 523 push( crit->target->signal_stack, crit ); 529 } 530 531 //Release 532 unlock_all( this.monitors, count ); 533 524 } // for 525 526 unlock_all( monitors, count ); // release 534 527 return true; 535 } 528 } // signal 536 529 537 530 bool signal_block( condition & this ) libcfa_public { 538 if ( ! this.blocked.head ) { return false; } 539 540 //Check that everything is as expected 531 if ( empty( this ) ) { return false; } 532 541 533 verifyf( this.monitors != 0p, "Waiting with no monitors (%p)", this.monitors ); 542 534 verifyf( this.monitor_count != 0, "Waiting with 0 monitors (%"PRIiFAST16")", this.monitor_count ); … … 551 543 wait_ctx_primed( active_thread(), 0 ) 552 544 553 //save contexts 554 monitor_save; 545 monitor_save; // save contexts 555 546 556 547 //Find the thread to run … … 560 551 __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee ); 561 552 562 // unlock all the monitors 563 unlock_all( locks, count ); 564 565 // unpark the thread we signalled 566 unpark( signallee ); 567 568 //Everything is ready to go to sleep 569 park(); 570 571 // WE WOKE UP 553 unlock_all( locks, count ); // unlock all the monitors 554 unpark( signallee ); // unpark the thread we signalled 555 park(); // everything is ready to go to sleep 556 557 // WOKE UP 572 558 573 559 __cfaabi_dbg_print_buffer_local( "Kernel : signal_block returned\n" ); 574 560 575 //We are back, restore the masks and recursions 576 monitor_restore; 561 monitor_restore; // restore the masks and recursions 577 562 578 563 return true; 579 } 564 } // signal_block 580 565 581 566 // Access the user_info of the thread waiting at the front of the queue
Note:
See TracChangeset
for help on using the changeset viewer.