- File:
-
- 1 edited
-
src/libcfa/concurrency/monitor.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
r34c6c767 r2f6a7e93 34 34 static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors ); 35 35 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 );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 ); 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_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 [] );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 [] ); 43 43 44 44 static inline void init ( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ); … … 53 53 static inline __lock_size_t count_max ( const __waitfor_mask_t & mask ); 54 54 static inline __lock_size_t aggregate ( monitor_desc * storage [], const __waitfor_mask_t & mask ); 55 56 #ifndef __CFA_LOCK_NO_YIELD57 #define DO_LOCK lock_yield58 #else59 #define DO_LOCK lock60 #endif61 55 62 56 //----------------------------------------------------------------------------- … … 77 71 unsigned int recursions[ count ]; /* Save the current recursion levels to restore them later */ \ 78 72 __waitfor_mask_t masks [ count ]; /* Save the current waitfor masks to restore them later */ \ 79 __spinlock_t * locks[ count ]; /* We need to pass-in an array of locks to BlockInternal */ \73 spinlock * locks [ count ]; /* We need to pass-in an array of locks to BlockInternal */ \ 80 74 81 75 #define monitor_save save ( monitors, count, locks, recursions, masks ) … … 90 84 // Enter single monitor 91 85 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 92 // Lock the monitor spinlock 93 DO_LOCK(this->lock DEBUG_CTX2 );86 // Lock the monitor spinlock, lock_yield to reduce contention 87 lock_yield( &this->lock DEBUG_CTX2 ); 94 88 thread_desc * thrd = this_thread; 95 89 … … 133 127 134 128 // Release the lock and leave 135 unlock( this->lock );129 unlock( &this->lock ); 136 130 return; 137 131 } 138 132 139 133 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 140 // Lock the monitor spinlock 141 DO_LOCK(this->lock DEBUG_CTX2 );134 // Lock the monitor spinlock, lock_yield to reduce contention 135 lock_yield( &this->lock DEBUG_CTX2 ); 142 136 thread_desc * thrd = this_thread; 143 137 … … 151 145 set_owner( this, thrd ); 152 146 153 unlock( this->lock );147 unlock( &this->lock ); 154 148 return; 155 149 } … … 202 196 // Leave single monitor 203 197 void __leave_monitor_desc( monitor_desc * this ) { 204 // Lock the monitor spinlock, DO_LOCKto reduce contention205 DO_LOCK(this->lock DEBUG_CTX2 );198 // Lock the monitor spinlock, lock_yield to reduce contention 199 lock_yield( &this->lock DEBUG_CTX2 ); 206 200 207 201 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); … … 216 210 if( this->recursion != 0) { 217 211 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion); 218 unlock( this->lock );212 unlock( &this->lock ); 219 213 return; 220 214 } … … 224 218 225 219 // We can now let other threads in safely 226 unlock( this->lock );220 unlock( &this->lock ); 227 221 228 222 //We need to wake-up the thread … … 249 243 250 244 // Lock the monitor now 251 DO_LOCK(this->lock DEBUG_CTX2 );245 lock_yield( &this->lock DEBUG_CTX2 ); 252 246 253 247 disable_interrupts(); … … 736 730 } 737 731 738 static inline void lock_all( __spinlock_t* locks [], __lock_size_t count ) {732 static inline void lock_all( spinlock * locks [], __lock_size_t count ) { 739 733 for( __lock_size_t i = 0; i < count; i++ ) { 740 DO_LOCK( *locks[i] DEBUG_CTX2 );741 } 742 } 743 744 static inline void lock_all( monitor_desc * source [], __spinlock_t* /*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 * /*out*/ locks [], __lock_size_t count ) { 745 739 for( __lock_size_t i = 0; i < count; i++ ) { 746 __spinlock_t* l = &source[i]->lock;747 DO_LOCK( *l DEBUG_CTX2 );740 spinlock * l = &source[i]->lock; 741 lock_yield( l DEBUG_CTX2 ); 748 742 if(locks) locks[i] = l; 749 743 } 750 744 } 751 745 752 static inline void unlock_all( __spinlock_t* locks [], __lock_size_t count ) {746 static inline void unlock_all( spinlock * locks [], __lock_size_t count ) { 753 747 for( __lock_size_t i = 0; i < count; i++ ) { 754 unlock( *locks[i] );748 unlock( locks[i] ); 755 749 } 756 750 } … … 758 752 static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ) { 759 753 for( __lock_size_t i = 0; i < count; i++ ) { 760 unlock( locks[i]->lock );754 unlock( &locks[i]->lock ); 761 755 } 762 756 } … … 765 759 monitor_desc * ctx [], 766 760 __lock_size_t count, 767 __attribute((unused)) __spinlock_t* locks [],761 __attribute((unused)) spinlock * locks [], 768 762 unsigned int /*out*/ recursions [], 769 763 __waitfor_mask_t /*out*/ masks [] … … 778 772 monitor_desc * ctx [], 779 773 __lock_size_t count, 780 __spinlock_t* locks [],774 spinlock * locks [], 781 775 unsigned int /*out*/ recursions [], 782 776 __waitfor_mask_t /*out*/ masks []
Note:
See TracChangeset
for help on using the changeset viewer.