Changeset c0d00b6 for src/libcfa/concurrency/monitor.c
- Timestamp:
- Nov 25, 2017, 3:22:18 PM (8 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c6e2c18
- Parents:
- 9d06142 (diff), 3de176d (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
-
src/libcfa/concurrency/monitor.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
r9d06142 rc0d00b6 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 [] ); … … 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_YIELD 57 #define DO_LOCK lock_yield 58 #else 59 #define DO_LOCK lock 60 #endif 55 61 56 62 //----------------------------------------------------------------------------- … … 71 77 unsigned int recursions[ count ]; /* Save the current recursion levels to restore them later */ \ 72 78 __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 */ \79 __spinlock_t * locks [ count ]; /* We need to pass-in an array of locks to BlockInternal */ \ 74 80 75 81 #define monitor_save save ( monitors, count, locks, recursions, masks ) … … 84 90 // Enter single monitor 85 91 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 86 // Lock the monitor spinlock , lock_yield to reduce contention87 lock_yield( &this->lock DEBUG_CTX2 );92 // Lock the monitor spinlock 93 DO_LOCK( this->lock DEBUG_CTX2 ); 88 94 thread_desc * thrd = this_thread; 89 95 … … 127 133 128 134 // Release the lock and leave 129 unlock( &this->lock );135 unlock( this->lock ); 130 136 return; 131 137 } 132 138 133 139 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 134 // Lock the monitor spinlock , lock_yield to reduce contention135 lock_yield( &this->lock DEBUG_CTX2 );140 // Lock the monitor spinlock 141 DO_LOCK( this->lock DEBUG_CTX2 ); 136 142 thread_desc * thrd = this_thread; 137 143 … … 145 151 set_owner( this, thrd ); 146 152 147 unlock( &this->lock );153 unlock( this->lock ); 148 154 return; 149 155 } … … 196 202 // Leave single monitor 197 203 void __leave_monitor_desc( monitor_desc * this ) { 198 // Lock the monitor spinlock, lock_yieldto reduce contention199 lock_yield( &this->lock DEBUG_CTX2 );204 // Lock the monitor spinlock, DO_LOCK to reduce contention 205 DO_LOCK( this->lock DEBUG_CTX2 ); 200 206 201 207 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); … … 210 216 if( this->recursion != 0) { 211 217 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion); 212 unlock( &this->lock );218 unlock( this->lock ); 213 219 return; 214 220 } … … 218 224 219 225 // We can now let other threads in safely 220 unlock( &this->lock );226 unlock( this->lock ); 221 227 222 228 //We need to wake-up the thread … … 243 249 244 250 // Lock the monitor now 245 lock_yield( &this->lock DEBUG_CTX2 );251 DO_LOCK( this->lock DEBUG_CTX2 ); 246 252 247 253 disable_interrupts(); … … 730 736 } 731 737 732 static inline void lock_all( spinlock* locks [], __lock_size_t count ) {738 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 733 739 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 ) {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 ) { 739 745 for( __lock_size_t i = 0; i < count; i++ ) { 740 spinlock* l = &source[i]->lock;741 lock_yield(l DEBUG_CTX2 );746 __spinlock_t * l = &source[i]->lock; 747 DO_LOCK( *l DEBUG_CTX2 ); 742 748 if(locks) locks[i] = l; 743 749 } 744 750 } 745 751 746 static inline void unlock_all( spinlock* locks [], __lock_size_t count ) {752 static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count ) { 747 753 for( __lock_size_t i = 0; i < count; i++ ) { 748 unlock( locks[i] );754 unlock( *locks[i] ); 749 755 } 750 756 } … … 752 758 static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ) { 753 759 for( __lock_size_t i = 0; i < count; i++ ) { 754 unlock( &locks[i]->lock );760 unlock( locks[i]->lock ); 755 761 } 756 762 } … … 759 765 monitor_desc * ctx [], 760 766 __lock_size_t count, 761 __attribute((unused)) spinlock* locks [],767 __attribute((unused)) __spinlock_t * locks [], 762 768 unsigned int /*out*/ recursions [], 763 769 __waitfor_mask_t /*out*/ masks [] … … 772 778 monitor_desc * ctx [], 773 779 __lock_size_t count, 774 spinlock* locks [],780 __spinlock_t * locks [], 775 781 unsigned int /*out*/ recursions [], 776 782 __waitfor_mask_t /*out*/ masks [] … … 817 823 this.monitor_count = thrd->monitors.size; 818 824 819 this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );825 this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) ); 820 826 for( int i = 0; i < this.monitor_count; i++ ) { 821 827 this.monitors[i] = thrd->monitors.list[i];
Note:
See TracChangeset
for help on using the changeset viewer.