- File:
-
- 1 edited
-
libcfa/src/concurrency/monitor.cfa (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/monitor.cfa
rb0c7419 r09f357ec 117 117 118 118 // Some one else has the monitor, wait in line for it 119 /* paranoid */ verify( thrd->next == 0p );120 119 append( this->entry_queue, thrd ); 121 /* paranoid */ verify( thrd->next == 1p ); 122 123 unlock( this->lock ); 124 park(); 120 121 BlockInternal( &this->lock ); 125 122 126 123 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 127 124 128 / * paranoid */ verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );125 // BlockInternal will unlock spinlock, no need to unlock ourselves 129 126 return; 130 127 } 131 128 132 129 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 133 134 /* paranoid */ verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );135 /* paranoid */ verify( this->lock.lock );136 130 137 131 // Release the lock and leave … … 155 149 set_owner( this, thrd ); 156 150 157 verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );158 159 151 unlock( this->lock ); 160 152 return; … … 174 166 // Wake the thread that is waiting for this 175 167 __condition_criterion_t * urgent = pop( this->signal_stack ); 176 /* paranoid */verify( urgent );168 verify( urgent ); 177 169 178 170 // Reset mask … … 183 175 184 176 // Some one else has the monitor, wait for him to finish and then run 185 unlock( this->lock ); 186 187 // Release the next thread 188 /* paranoid */ verifyf( urgent->owner->waiting_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this ); 189 unpark( urgent->owner->waiting_thread ); 190 191 // Park current thread waiting 192 park(); 177 BlockInternal( &this->lock, urgent->owner->waiting_thread ); 193 178 194 179 // Some one was waiting for us, enter 195 /* paranoid */ verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this);180 set_owner( this, thrd ); 196 181 } 197 182 else { … … 202 187 203 188 // Some one else has the monitor, wait in line for it 204 /* paranoid */ verify( thrd->next == 0p );205 189 append( this->entry_queue, thrd ); 206 /* paranoid */ verify( thrd->next == 1p ); 207 unlock( this->lock ); 208 209 // Park current thread waiting 210 park(); 211 212 /* paranoid */ verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this ); 190 BlockInternal( &this->lock ); 191 192 // BlockInternal will unlock spinlock, no need to unlock ourselves 213 193 return; 214 194 } … … 225 205 __cfaabi_dbg_print_safe( "Kernel : %10p Leaving mon %p (%p)\n", kernelTLS.this_thread, this, this->owner); 226 206 227 /* paranoid */verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );207 verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this ); 228 208 229 209 // Leaving a recursion level, decrement the counter … … 241 221 thread_desc * new_owner = next_thread( this ); 242 222 243 // Check the new owner is consistent with who we wake-up244 // new_owner might be null even if someone owns the monitor when the owner is still waiting for another monitor245 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );246 247 223 // We can now let other threads in safely 248 224 unlock( this->lock ); 249 225 250 226 //We need to wake-up the thread 251 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this ); 252 unpark( new_owner ); 227 WakeThread( new_owner ); 253 228 } 254 229 … … 277 252 disable_interrupts(); 278 253 279 thrd->s tate = Halted;280 281 /* paranoid */verifyf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", thrd, this->owner, this->recursion, this );254 thrd->self_cor.state = Halted; 255 256 verifyf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", thrd, this->owner, this->recursion, this ); 282 257 283 258 // Leaving a recursion level, decrement the counter … … 291 266 thread_desc * new_owner = next_thread( this ); 292 267 293 // Release the monitor lock 294 unlock( this->lock ); 295 296 // Unpark the next owner if needed 297 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this ); 298 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 299 /* paranoid */ verify( ! kernelTLS.this_processor->destroyer ); 300 /* paranoid */ verify( thrd->state == Halted ); 301 302 kernelTLS.this_processor->destroyer = new_owner; 303 304 // Leave the thread 305 __leave_thread(); 268 // Leave the thread, this will unlock the spinlock 269 // Use leave thread instead of BlockInternal which is 270 // specialized for this case and supports null new_owner 271 LeaveThread( &this->lock, new_owner ); 306 272 307 273 // Control flow should never reach here! … … 434 400 // Append the current wait operation to the ones already queued on the condition 435 401 // We don't need locks for that since conditions must always be waited on inside monitor mutual exclusion 436 /* paranoid */ verify( waiter.next == 0p );437 402 append( this.blocked, &waiter ); 438 /* paranoid */ verify( waiter.next == 1p );439 403 440 404 // Lock all monitors (aggregates the locks as well) … … 455 419 } 456 420 457 // Unlock the locks, we don't need them anymore458 for(int i = 0; i < count; i++) {459 unlock( *locks[i] );460 }461 462 // Wake the threads463 for(int i = 0; i < thread_count; i++) {464 unpark( threads[i] );465 }466 467 421 // Everything is ready to go to sleep 468 park();422 BlockInternal( locks, count, threads, thread_count ); 469 423 470 424 // We are back, restore the owners and recursions … … 536 490 //Find the thread to run 537 491 thread_desc * signallee = pop_head( this.blocked )->waiting_thread; 538 /* paranoid */ verify( signallee->next == 0p );539 492 set_owner( monitors, count, signallee ); 540 493 541 494 __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee ); 542 495 543 // unlock all the monitors544 unlock_all( locks, count );545 546 // unpark the thread we signalled547 unpark( signallee );548 549 496 //Everything is ready to go to sleep 550 park();497 BlockInternal( locks, count, &signallee, 1 ); 551 498 552 499 … … 645 592 set_owner( monitors, count, next ); 646 593 647 // unlock all the monitors 648 unlock_all( locks, count ); 649 650 // unpark the thread we signalled 651 unpark( next ); 652 653 //Everything is ready to go to sleep 654 park(); 594 // Everything is ready to go to sleep 595 BlockInternal( locks, count, &next, 1 ); 655 596 656 597 // We are back, restore the owners and recursions … … 690 631 } 691 632 692 // unlock all the monitors693 unlock_all( locks, count );694 695 633 //Everything is ready to go to sleep 696 park();634 BlockInternal( locks, count ); 697 635 698 636 … … 712 650 713 651 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 714 / * paranoid */ verify( this->lock.lock);652 // __cfaabi_dbg_print_safe( "Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner ); 715 653 716 654 //Pass the monitor appropriately … … 722 660 723 661 static inline void set_owner( monitor_desc * monitors [], __lock_size_t count, thread_desc * owner ) { 724 /* paranoid */ verify ( monitors[0]->lock.lock ); 725 /* paranoid */ verifyf( monitors[0]->owner == kernelTLS.this_thread, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, monitors[0]->owner, monitors[0]->recursion, monitors[0] ); 726 monitors[0]->owner = owner; 727 monitors[0]->recursion = 1; 662 monitors[0]->owner = owner; 663 monitors[0]->recursion = 1; 728 664 for( __lock_size_t i = 1; i < count; i++ ) { 729 /* paranoid */ verify ( monitors[i]->lock.lock ); 730 /* paranoid */ verifyf( monitors[i]->owner == kernelTLS.this_thread, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, monitors[i]->owner, monitors[i]->recursion, monitors[i] ); 731 monitors[i]->owner = owner; 732 monitors[i]->recursion = 0; 665 monitors[i]->owner = owner; 666 monitors[i]->recursion = 0; 733 667 } 734 668 } … … 754 688 //regardless of if we are ready to baton pass, 755 689 //we need to set the monitor as in use 756 /* paranoid */ verifyf( !this->owner || kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );757 690 set_owner( this, urgent->owner->waiting_thread ); 758 691 … … 763 696 // Get the next thread in the entry_queue 764 697 thread_desc * new_owner = pop_head( this->entry_queue ); 765 /* paranoid */ verifyf( !this->owner || kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );766 /* paranoid */ verify( !new_owner || new_owner->next == 0p );767 698 set_owner( this, new_owner ); 768 699 … … 910 841 // For each thread in the entry-queue 911 842 for( thread_desc ** thrd_it = &entry_queue.head; 912 *thrd_it != 1p;843 *thrd_it; 913 844 thrd_it = &(*thrd_it)->next 914 845 ) {
Note:
See TracChangeset
for help on using the changeset viewer.