Changeset 50b8885
- Timestamp:
- Feb 13, 2020, 4:40:16 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b0c7419
- Parents:
- 3381ed7
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.h
r3381ed7 r50b8885 94 94 enum coroutine_state { Halted, Start, Primed, Inactive, Active, Rerun, Reschedule }; 95 95 enum __Preemption_Reason { __NO_PREEMPTION, __ALARM_PREEMPTION, __POLL_PREEMPTION }; 96 enum __Owner_Reason { __NO_OWNER, __ENTER_FREE, __ENTER_ACCEPT, __ENTER_DTOR_FREE, __ENTER_DTOR_ACCEPT, __ENTER_SIGNAL_BLOCK, __WAITFOR, __LEAVE, __LEAVE_THREAD, __WAIT };97 96 98 97 struct coroutine_desc { … … 135 134 // current owner of the monitor 136 135 struct thread_desc * owner; 137 138 enum __Owner_Reason owner_reason;139 136 140 137 // queue of threads that are blocked waiting for the monitor -
libcfa/src/concurrency/monitor.cfa
r3381ed7 r50b8885 27 27 //----------------------------------------------------------------------------- 28 28 // Forward declarations 29 static inline void set_owner ( monitor_desc * this, thread_desc * owner , enum __Owner_Reason);30 static inline void set_owner ( monitor_desc * storage [], __lock_size_t count, thread_desc * owner , enum __Owner_Reason);29 static inline void set_owner ( monitor_desc * this, thread_desc * owner ); 30 static inline void set_owner ( monitor_desc * storage [], __lock_size_t count, thread_desc * owner ); 31 31 static inline void set_mask ( monitor_desc * storage [], __lock_size_t count, const __waitfor_mask_t & mask ); 32 32 static inline void reset_mask( monitor_desc * this ); 33 33 34 static inline thread_desc * next_thread( monitor_desc * this , enum __Owner_Reason);34 static inline thread_desc * next_thread( monitor_desc * this ); 35 35 static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors ); 36 36 … … 94 94 if( !this->owner ) { 95 95 // No one has the monitor, just take it 96 set_owner( this, thrd , __ENTER_FREE);96 set_owner( this, thrd ); 97 97 98 98 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" ); … … 106 106 else if( is_accepted( this, group) ) { 107 107 // Some one was waiting for us, enter 108 set_owner( this, thrd , __ENTER_ACCEPT);108 set_owner( this, thrd ); 109 109 110 110 // Reset mask … … 153 153 154 154 // No one has the monitor, just take it 155 set_owner( this, thrd , __ENTER_DTOR_FREE);155 set_owner( this, thrd ); 156 156 157 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 ); … … 239 239 240 240 // Get the next thread, will be null on low contention monitor 241 thread_desc * new_owner = next_thread( this , __LEAVE);241 thread_desc * new_owner = next_thread( this ); 242 242 243 243 // Check the new owner is consistent with who we wake-up … … 289 289 290 290 // Fetch the next thread, can be null 291 thread_desc * new_owner = next_thread( this , __LEAVE_THREAD);291 thread_desc * new_owner = next_thread( this ); 292 292 293 293 // Release the monitor lock … … 449 449 // Remove any duplicate threads 450 450 for( __lock_size_t i = 0; i < count; i++) { 451 thread_desc * new_owner = next_thread( monitors[i] , __WAIT);451 thread_desc * new_owner = next_thread( monitors[i] ); 452 452 insert_unique( threads, thread_count, new_owner ); 453 453 } … … 535 535 thread_desc * signallee = pop_head( this.blocked )->waiting_thread; 536 536 /* paranoid */ verify( signallee->next == 0p ); 537 set_owner( monitors, count, signallee , __ENTER_SIGNAL_BLOCK);537 set_owner( monitors, count, signallee ); 538 538 539 539 __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee ); … … 641 641 642 642 // Set the owners to be the next thread 643 set_owner( monitors, count, next , __WAITFOR);643 set_owner( monitors, count, next ); 644 644 645 645 // unlock all the monitors … … 709 709 // Utilities 710 710 711 static inline void set_owner( monitor_desc * this, thread_desc * owner , enum __Owner_Reason reason) {711 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 712 712 /* paranoid */ verify( this->lock.lock ); 713 713 714 714 //Pass the monitor appropriately 715 715 this->owner = owner; 716 this->owner_reason = reason;717 716 718 717 //We are passing the monitor to someone else, which means recursion level is not 0 … … 720 719 } 721 720 722 static inline void set_owner( monitor_desc * monitors [], __lock_size_t count, thread_desc * owner , enum __Owner_Reason reason) {721 static inline void set_owner( monitor_desc * monitors [], __lock_size_t count, thread_desc * owner ) { 723 722 /* paranoid */ verify ( monitors[0]->lock.lock ); 724 723 /* 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] ); 725 724 monitors[0]->owner = owner; 726 monitors[0]->owner_reason = reason;727 725 monitors[0]->recursion = 1; 728 726 for( __lock_size_t i = 1; i < count; i++ ) { … … 730 728 /* 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 729 monitors[i]->owner = owner; 732 monitors[i]->owner_reason = reason;733 730 monitors[i]->recursion = 0; 734 731 } … … 747 744 } 748 745 749 static inline thread_desc * next_thread( monitor_desc * this , enum __Owner_Reason reason) {746 static inline thread_desc * next_thread( monitor_desc * this ) { 750 747 //Check the signaller stack 751 748 __cfaabi_dbg_print_safe( "Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top); … … 756 753 //we need to set the monitor as in use 757 754 /* 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 ); 758 set_owner( this, urgent->owner->waiting_thread , reason);755 set_owner( this, urgent->owner->waiting_thread ); 759 756 760 757 return check_condition( urgent ); … … 766 763 /* 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 ); 767 764 /* paranoid */ verify( !new_owner || new_owner->next == 0p ); 768 set_owner( this, new_owner , reason);765 set_owner( this, new_owner ); 769 766 770 767 return new_owner; -
libcfa/src/concurrency/monitor.hfa
r3381ed7 r50b8885 32 32 signal_stack{}; 33 33 owner = 0p; 34 owner_reason = __NO_OWNER;35 34 recursion = 0; 36 35 mask.accepted = 0p; -
tests/concurrent/park/force_preempt.cfa
r3381ed7 r50b8885 21 21 22 22 void park_loop(Waiter & this, int id, bool force) { 23 23 24 for(int i = 0; i < 5; i++) { 24 25 // Unpark this thread, don't force a yield
Note: See TracChangeset
for help on using the changeset viewer.