Changeset cfe2f0a for src/libcfa/concurrency/monitor.c
- Timestamp:
- Feb 12, 2018, 11:55:02 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d56ca354, ee2938a
- Parents:
- 827a190 (diff), 43c6dc82 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
r827a190 rcfe2f0a 10 10 // Created On : Thd Feb 23 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 31 14:59:05 201713 // Update Count : 312 // Last Modified On : Thu Feb 8 16:12:20 2018 13 // Update Count : 4 14 14 // 15 15 … … 87 87 thread_desc * thrd = this_thread; 88 88 89 __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);89 __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 90 90 91 91 if( !this->owner ) { … … 93 93 set_owner( this, thrd ); 94 94 95 __cfaabi_dbg_print_safe( "Kernel : mon is free \n");95 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" ); 96 96 } 97 97 else if( this->owner == thrd) { … … 99 99 this->recursion += 1; 100 100 101 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n");101 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" ); 102 102 } 103 103 else if( is_accepted( this, group) ) { … … 108 108 reset_mask( this ); 109 109 110 __cfaabi_dbg_print_safe( "Kernel : mon accepts \n");110 __cfaabi_dbg_print_safe( "Kernel : mon accepts \n" ); 111 111 } 112 112 else { 113 __cfaabi_dbg_print_safe( "Kernel : blocking \n");113 __cfaabi_dbg_print_safe( "Kernel : blocking \n" ); 114 114 115 115 // Some one else has the monitor, wait in line for it … … 118 118 BlockInternal( &this->lock ); 119 119 120 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);120 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 121 121 122 122 // BlockInternal will unlock spinlock, no need to unlock ourselves … … 124 124 } 125 125 126 __cfaabi_dbg_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 // Release the lock and leave … … 136 136 thread_desc * thrd = this_thread; 137 137 138 __cfaabi_dbg_print_safe( "Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);138 __cfaabi_dbg_print_safe( "Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner); 139 139 140 140 141 141 if( !this->owner ) { 142 __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);142 __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this); 143 143 144 144 // No one has the monitor, just take it … … 151 151 // We already have the monitor... but where about to destroy it so the nesting will fail 152 152 // Abort! 153 abort f("Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex.");153 abort( "Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex." ); 154 154 } 155 155 … … 158 158 __monitor_group_t group = { &this, 1, func }; 159 159 if( is_accepted( this, group) ) { 160 __cfaabi_dbg_print_safe( "Kernel : mon accepts dtor, block and signal it \n");160 __cfaabi_dbg_print_safe( "Kernel : mon accepts dtor, block and signal it \n" ); 161 161 162 162 // Wake the thread that is waiting for this … … 177 177 } 178 178 else { 179 __cfaabi_dbg_print_safe( "Kernel : blocking \n");179 __cfaabi_dbg_print_safe( "Kernel : blocking \n" ); 180 180 181 181 wait_ctx( this_thread, 0 ) … … 190 190 } 191 191 192 __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);192 __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this); 193 193 194 194 } … … 199 199 lock( this->lock __cfaabi_dbg_ctx2 ); 200 200 201 __cfaabi_dbg_print_safe( "Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);201 __cfaabi_dbg_print_safe( "Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); 202 202 203 203 verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this ); … … 209 209 // it means we don't need to do anything 210 210 if( this->recursion != 0) { 211 __cfaabi_dbg_print_safe( "Kernel : recursion still %d\n", this->recursion);211 __cfaabi_dbg_print_safe( "Kernel : recursion still %d\n", this->recursion); 212 212 unlock( this->lock ); 213 213 return; … … 228 228 __cfaabi_dbg_debug_do( 229 229 if( this_thread != this->owner ) { 230 abort f("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);230 abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner); 231 231 } 232 232 if( this->recursion != 1 ) { 233 abort f("Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);233 abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1); 234 234 } 235 235 ) … … 256 256 // If we haven't left the last level of recursion 257 257 // it must mean there is an error 258 if( this->recursion != 0) { abort f("Thread internal monitor has unbalanced recursion"); }258 if( this->recursion != 0) { abort( "Thread internal monitor has unbalanced recursion" ); } 259 259 260 260 // Fetch the next thread, can be null … … 302 302 (this_thread->monitors){m, count, func}; 303 303 304 // __cfaabi_dbg_print_safe( "MGUARD : enter %d\n", count);304 // __cfaabi_dbg_print_safe( "MGUARD : enter %d\n", count); 305 305 306 306 // Enter the monitors in order … … 308 308 enter( group ); 309 309 310 // __cfaabi_dbg_print_safe( "MGUARD : entered\n");310 // __cfaabi_dbg_print_safe( "MGUARD : entered\n" ); 311 311 } 312 312 … … 314 314 // Dtor for monitor guard 315 315 void ^?{}( monitor_guard_t & this ) { 316 // __cfaabi_dbg_print_safe( "MGUARD : leaving %d\n", this.count);316 // __cfaabi_dbg_print_safe( "MGUARD : leaving %d\n", this.count); 317 317 318 318 // Leave the monitors in order 319 319 leave( this.m, this.count ); 320 320 321 // __cfaabi_dbg_print_safe( "MGUARD : left\n");321 // __cfaabi_dbg_print_safe( "MGUARD : left\n" ); 322 322 323 323 // Restore thread context … … 427 427 thread_desc * this_thrd = this_thread; 428 428 if ( this.monitor_count != this_thrd->monitors.size ) { 429 abort f( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size );429 abort( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size ); 430 430 } 431 431 432 432 for(int i = 0; i < this.monitor_count; i++) { 433 433 if ( this.monitors[i] != this_thrd->monitors[i] ) { 434 abort f( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );434 abort( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] ); 435 435 } 436 436 } … … 534 534 if(actual_count == 0) return; 535 535 536 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" );536 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" ); 537 537 538 538 // Create storage for monitor context … … 551 551 __acceptable_t& accepted = mask[index]; 552 552 if( accepted.is_dtor ) { 553 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" );553 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" ); 554 554 verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." ); 555 555 … … 563 563 } 564 564 else { 565 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n" );565 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n" ); 566 566 567 567 // Create the node specific to this wait operation … … 577 577 } 578 578 #endif 579 __cfaabi_dbg_print_buffer_local( "\n" );579 __cfaabi_dbg_print_buffer_local( "\n" ); 580 580 581 581 // Set the owners to be the next thread … … 588 588 monitor_restore; 589 589 590 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" );590 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" ); 591 591 } 592 592 … … 598 598 599 599 if( duration == 0 ) { 600 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n" );600 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n" ); 601 601 602 602 unlock_all( locks, count ); … … 607 607 608 608 609 verifyf( duration < 0, "Timeout on waitfor statments not supported yet." );610 611 __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n" );609 verifyf( duration < 0, "Timeout on waitfor statments not supported yet." ); 610 611 __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n" ); 612 612 613 613 // Create the node specific to this wait operation … … 631 631 monitor_restore; 632 632 633 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" );633 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" ); 634 634 635 635 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); … … 640 640 641 641 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 642 // __cfaabi_dbg_print_safe( "Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );642 // __cfaabi_dbg_print_safe( "Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner ); 643 643 644 644 //Pass the monitor appropriately … … 672 672 static inline thread_desc * next_thread( monitor_desc * this ) { 673 673 //Check the signaller stack 674 __cfaabi_dbg_print_safe( "Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top);674 __cfaabi_dbg_print_safe( "Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top); 675 675 __condition_criterion_t * urgent = pop( this->signal_stack ); 676 676 if( urgent ) { … … 814 814 thread_desc * thrd = this_thread; 815 815 if( !this.monitors ) { 816 // __cfaabi_dbg_print_safe( "Branding\n");816 // __cfaabi_dbg_print_safe( "Branding\n" ); 817 817 assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data ); 818 818 this.monitor_count = thrd->monitors.size;
Note: See TracChangeset
for help on using the changeset viewer.