- File:
-
- 1 edited
-
src/libcfa/concurrency/monitor.c (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
r0cf5b79 r36982fc 91 91 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 92 92 // Lock the monitor spinlock 93 DO_LOCK( this->lock DEBUG_CTX2 );93 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 94 94 thread_desc * thrd = this_thread; 95 95 96 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);96 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 97 97 98 98 if( !this->owner ) { … … 100 100 set_owner( this, thrd ); 101 101 102 LIB_DEBUG_PRINT_SAFE("Kernel : mon is free \n");102 __cfaabi_dbg_print_safe("Kernel : mon is free \n"); 103 103 } 104 104 else if( this->owner == thrd) { … … 106 106 this->recursion += 1; 107 107 108 LIB_DEBUG_PRINT_SAFE("Kernel : mon already owned \n");108 __cfaabi_dbg_print_safe("Kernel : mon already owned \n"); 109 109 } 110 110 else if( is_accepted( this, group) ) { … … 115 115 reset_mask( this ); 116 116 117 LIB_DEBUG_PRINT_SAFE("Kernel : mon accepts \n");117 __cfaabi_dbg_print_safe("Kernel : mon accepts \n"); 118 118 } 119 119 else { 120 LIB_DEBUG_PRINT_SAFE("Kernel : blocking \n");120 __cfaabi_dbg_print_safe("Kernel : blocking \n"); 121 121 122 122 // Some one else has the monitor, wait in line for it … … 124 124 BlockInternal( &this->lock ); 125 125 126 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered mon %p\n", thrd, this);126 __cfaabi_dbg_print_safe("Kernel : %10p Entered mon %p\n", thrd, this); 127 127 128 128 // BlockInternal will unlock spinlock, no need to unlock ourselves … … 130 130 } 131 131 132 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered mon %p\n", thrd, this);132 __cfaabi_dbg_print_safe("Kernel : %10p Entered mon %p\n", thrd, this); 133 133 134 134 // Release the lock and leave … … 139 139 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 140 140 // Lock the monitor spinlock 141 DO_LOCK( this->lock DEBUG_CTX2 );141 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 142 142 thread_desc * thrd = this_thread; 143 143 144 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);144 __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner); 145 145 146 146 147 147 if( !this->owner ) { 148 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying free mon %p\n", this);148 __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this); 149 149 150 150 // No one has the monitor, just take it … … 164 164 __monitor_group_t group = { &this, 1, func }; 165 165 if( is_accepted( this, group) ) { 166 LIB_DEBUG_PRINT_SAFE("Kernel : mon accepts dtor, block and signal it \n");166 __cfaabi_dbg_print_safe("Kernel : mon accepts dtor, block and signal it \n"); 167 167 168 168 // Wake the thread that is waiting for this … … 183 183 } 184 184 else { 185 LIB_DEBUG_PRINT_SAFE("Kernel : blocking \n");185 __cfaabi_dbg_print_safe("Kernel : blocking \n"); 186 186 187 187 wait_ctx( this_thread, 0 ) … … 196 196 } 197 197 198 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying %p\n", this);198 __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this); 199 199 200 200 } … … 203 203 void __leave_monitor_desc( monitor_desc * this ) { 204 204 // Lock the monitor spinlock, DO_LOCK to reduce contention 205 DO_LOCK( this->lock DEBUG_CTX2 );206 207 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);205 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 206 207 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); 208 208 209 209 verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this ); … … 215 215 // it means we don't need to do anything 216 216 if( this->recursion != 0) { 217 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion);217 __cfaabi_dbg_print_safe("Kernel : recursion still %d\n", this->recursion); 218 218 unlock( this->lock ); 219 219 return; … … 232 232 // Leave single monitor for the last time 233 233 void __leave_dtor_monitor_desc( monitor_desc * this ) { 234 LIB_DEBUG_DO(234 __cfaabi_dbg_debug_do( 235 235 if( this_thread != this->owner ) { 236 236 abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner); … … 249 249 250 250 // Lock the monitor now 251 DO_LOCK( this->lock DEBUG_CTX2 );251 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 252 252 253 253 disable_interrupts(); … … 308 308 (this_thread->monitors){m, count, func}; 309 309 310 // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);310 // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count); 311 311 312 312 // Enter the monitors in order … … 314 314 enter( group ); 315 315 316 // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");316 // __cfaabi_dbg_print_safe("MGUARD : entered\n"); 317 317 } 318 318 … … 320 320 // Dtor for monitor guard 321 321 void ^?{}( monitor_guard_t & this ) { 322 // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);322 // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count); 323 323 324 324 // Leave the monitors in order 325 325 leave( this.m, this.count ); 326 326 327 // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");327 // __cfaabi_dbg_print_safe("MGUARD : left\n"); 328 328 329 329 // Restore thread context … … 430 430 431 431 //Some more checking in debug 432 LIB_DEBUG_DO(432 __cfaabi_dbg_debug_do( 433 433 thread_desc * this_thrd = this_thread; 434 434 if ( this.monitor_count != this_thrd->monitors.size ) { … … 487 487 set_owner( monitors, count, signallee ); 488 488 489 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );489 __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee ); 490 490 491 491 //Everything is ready to go to sleep … … 496 496 497 497 498 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : signal_block returned\n" );498 __cfaabi_dbg_print_buffer_local( "Kernel : signal_block returned\n" ); 499 499 500 500 //We are back, restore the masks and recursions … … 535 535 __lock_size_t actual_count = aggregate( mon_storage, mask ); 536 536 537 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);537 __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max); 538 538 539 539 if(actual_count == 0) return; 540 540 541 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");541 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n"); 542 542 543 543 // Create storage for monitor context … … 556 556 __acceptable_t& accepted = mask[index]; 557 557 if( accepted.is_dtor ) { 558 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");558 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n"); 559 559 verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." ); 560 560 … … 568 568 } 569 569 else { 570 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");570 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n"); 571 571 572 572 // Create the node specific to this wait operation … … 576 576 monitor_save; 577 577 578 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : baton of %d monitors : ", count );578 __cfaabi_dbg_print_buffer_local( "Kernel : baton of %d monitors : ", count ); 579 579 #ifdef __CFA_DEBUG_PRINT__ 580 580 for( int i = 0; i < count; i++) { 581 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );581 __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top ); 582 582 } 583 583 #endif 584 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");584 __cfaabi_dbg_print_buffer_local( "\n"); 585 585 586 586 // Set the owners to be the next thread … … 593 593 monitor_restore; 594 594 595 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");595 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n"); 596 596 } 597 597 598 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);598 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); 599 599 return; 600 600 } … … 603 603 604 604 if( duration == 0 ) { 605 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");605 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n"); 606 606 607 607 unlock_all( locks, count ); 608 608 609 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);609 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); 610 610 return; 611 611 } … … 614 614 verifyf( duration < 0, "Timeout on waitfor statments not supported yet."); 615 615 616 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");616 __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n"); 617 617 618 618 // Create the node specific to this wait operation … … 636 636 monitor_restore; 637 637 638 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");639 640 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);638 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n"); 639 640 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); 641 641 } 642 642 … … 645 645 646 646 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 647 // LIB_DEBUG_PRINT_SAFE("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );647 // __cfaabi_dbg_print_safe("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner ); 648 648 649 649 //Pass the monitor appropriately … … 677 677 static inline thread_desc * next_thread( monitor_desc * this ) { 678 678 //Check the signaller stack 679 LIB_DEBUG_PRINT_SAFE("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top);679 __cfaabi_dbg_print_safe("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top); 680 680 __condition_criterion_t * urgent = pop( this->signal_stack ); 681 681 if( urgent ) { … … 729 729 for( __lock_size_t i = 0; i < count; i++) { 730 730 (criteria[i]){ monitors[i], waiter }; 731 LIB_DEBUG_PRINT_SAFE( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] );731 __cfaabi_dbg_print_safe( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] ); 732 732 push( criteria[i].target->signal_stack, &criteria[i] ); 733 733 } … … 738 738 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 739 739 for( __lock_size_t i = 0; i < count; i++ ) { 740 DO_LOCK( *locks[i] DEBUG_CTX2 );740 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 ); 741 741 } 742 742 } … … 745 745 for( __lock_size_t i = 0; i < count; i++ ) { 746 746 __spinlock_t * l = &source[i]->lock; 747 DO_LOCK( *l DEBUG_CTX2 );747 DO_LOCK( *l __cfaabi_dbg_ctx2 ); 748 748 if(locks) locks[i] = l; 749 749 } … … 803 803 for( int i = 0; i < count; i++ ) { 804 804 805 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );805 // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target ); 806 806 if( &criteria[i] == target ) { 807 807 criteria[i].ready = true; 808 // LIB_DEBUG_PRINT_SAFE( "True\n" );808 // __cfaabi_dbg_print_safe( "True\n" ); 809 809 } 810 810 … … 812 812 } 813 813 814 LIB_DEBUG_PRINT_SAFE( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );814 __cfaabi_dbg_print_safe( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL ); 815 815 return ready2run ? node->waiting_thread : NULL; 816 816 } … … 819 819 thread_desc * thrd = this_thread; 820 820 if( !this.monitors ) { 821 // LIB_DEBUG_PRINT_SAFE("Branding\n");821 // __cfaabi_dbg_print_safe("Branding\n"); 822 822 assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data ); 823 823 this.monitor_count = thrd->monitors.size; 824 824 825 this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );825 this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) ); 826 826 for( int i = 0; i < this.monitor_count; i++ ) { 827 827 this.monitors[i] = thrd->monitors[i];
Note:
See TracChangeset
for help on using the changeset viewer.