Changeset ea7d2b0 for src/libcfa/concurrency/monitor.c
- Timestamp:
- Nov 9, 2017, 1:58:39 PM (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:
- 34c6c767
- Parents:
- 3351cc0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
r3351cc0 rea7d2b0 34 34 static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors ); 35 35 36 static inline void lock_all ( spinlock* locks [], __lock_size_t count );37 static inline void lock_all ( monitor_desc * source [], spinlock* /*out*/ locks [], __lock_size_t count );38 static inline void unlock_all( spinlock* locks [], __lock_size_t count );36 static inline void lock_all ( __spinlock_t * locks [], __lock_size_t count ); 37 static inline void lock_all ( monitor_desc * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count ); 38 static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count ); 39 39 static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ); 40 40 41 static inline void save ( monitor_desc * ctx [], __lock_size_t count, spinlock* locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );42 static inline void restore( monitor_desc * ctx [], __lock_size_t count, spinlock* locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );41 static inline void save ( monitor_desc * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] ); 42 static inline void restore( monitor_desc * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] ); 43 43 44 44 static inline void init ( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ); … … 71 71 unsigned int recursions[ count ]; /* Save the current recursion levels to restore them later */ \ 72 72 __waitfor_mask_t masks [ count ]; /* Save the current waitfor masks to restore them later */ \ 73 spinlock * locks[ count ]; /* We need to pass-in an array of locks to BlockInternal */ \73 __spinlock_t * locks [ count ]; /* We need to pass-in an array of locks to BlockInternal */ \ 74 74 75 75 #define monitor_save save ( monitors, count, locks, recursions, masks ) … … 85 85 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 86 86 // Lock the monitor spinlock, lock_yield to reduce contention 87 lock_yield( &this->lock DEBUG_CTX2 );87 lock_yield( this->lock DEBUG_CTX2 ); 88 88 thread_desc * thrd = this_thread; 89 89 … … 127 127 128 128 // Release the lock and leave 129 unlock( &this->lock );129 unlock( this->lock ); 130 130 return; 131 131 } … … 133 133 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 134 134 // Lock the monitor spinlock, lock_yield to reduce contention 135 lock_yield( &this->lock DEBUG_CTX2 );135 lock_yield( this->lock DEBUG_CTX2 ); 136 136 thread_desc * thrd = this_thread; 137 137 … … 145 145 set_owner( this, thrd ); 146 146 147 unlock( &this->lock );147 unlock( this->lock ); 148 148 return; 149 149 } … … 197 197 void __leave_monitor_desc( monitor_desc * this ) { 198 198 // Lock the monitor spinlock, lock_yield to reduce contention 199 lock_yield( &this->lock DEBUG_CTX2 );199 lock_yield( this->lock DEBUG_CTX2 ); 200 200 201 201 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); … … 210 210 if( this->recursion != 0) { 211 211 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion); 212 unlock( &this->lock );212 unlock( this->lock ); 213 213 return; 214 214 } … … 218 218 219 219 // We can now let other threads in safely 220 unlock( &this->lock );220 unlock( this->lock ); 221 221 222 222 //We need to wake-up the thread … … 243 243 244 244 // Lock the monitor now 245 lock_yield( &this->lock DEBUG_CTX2 );245 lock_yield( this->lock DEBUG_CTX2 ); 246 246 247 247 disable_interrupts(); … … 730 730 } 731 731 732 static inline void lock_all( spinlock* locks [], __lock_size_t count ) {732 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 733 733 for( __lock_size_t i = 0; i < count; i++ ) { 734 lock_yield( locks[i] DEBUG_CTX2 );735 } 736 } 737 738 static inline void lock_all( monitor_desc * source [], spinlock* /*out*/ locks [], __lock_size_t count ) {734 lock_yield( *locks[i] DEBUG_CTX2 ); 735 } 736 } 737 738 static inline void lock_all( monitor_desc * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count ) { 739 739 for( __lock_size_t i = 0; i < count; i++ ) { 740 spinlock* l = &source[i]->lock;741 lock_yield( l DEBUG_CTX2 );740 __spinlock_t * l = &source[i]->lock; 741 lock_yield( *l DEBUG_CTX2 ); 742 742 if(locks) locks[i] = l; 743 743 } 744 744 } 745 745 746 static inline void unlock_all( spinlock* locks [], __lock_size_t count ) {746 static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count ) { 747 747 for( __lock_size_t i = 0; i < count; i++ ) { 748 unlock( locks[i] );748 unlock( *locks[i] ); 749 749 } 750 750 } … … 752 752 static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ) { 753 753 for( __lock_size_t i = 0; i < count; i++ ) { 754 unlock( &locks[i]->lock );754 unlock( locks[i]->lock ); 755 755 } 756 756 } … … 759 759 monitor_desc * ctx [], 760 760 __lock_size_t count, 761 __attribute((unused)) spinlock* locks [],761 __attribute((unused)) __spinlock_t * locks [], 762 762 unsigned int /*out*/ recursions [], 763 763 __waitfor_mask_t /*out*/ masks [] … … 772 772 monitor_desc * ctx [], 773 773 __lock_size_t count, 774 spinlock* locks [],774 __spinlock_t * locks [], 775 775 unsigned int /*out*/ recursions [], 776 776 __waitfor_mask_t /*out*/ masks []
Note: See TracChangeset
for help on using the changeset viewer.