Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor.c

    r34c6c767 r2f6a7e93  
    3434static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors );
    3535
    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 );
     36static inline void lock_all  ( spinlock * locks [], __lock_size_t count );
     37static inline void lock_all  ( monitor_desc * source [], spinlock * /*out*/ locks [], __lock_size_t count );
     38static inline void unlock_all( spinlock * locks [], __lock_size_t count );
    3939static inline void unlock_all( monitor_desc * locks [], __lock_size_t count );
    4040
    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 [] );
     41static inline void save   ( monitor_desc * ctx [], __lock_size_t count, spinlock * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
     42static inline void restore( monitor_desc * ctx [], __lock_size_t count, spinlock * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );
    4343
    4444static inline void init     ( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
     
    5353static inline __lock_size_t count_max    ( const __waitfor_mask_t & mask );
    5454static 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
    6155
    6256//-----------------------------------------------------------------------------
     
    7771        unsigned int recursions[ count ];                         /* Save the current recursion levels to restore them later                             */ \
    7872        __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                               */ \
    8074
    8175#define monitor_save    save   ( monitors, count, locks, recursions, masks )
     
    9084        // Enter single monitor
    9185        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 );
    9488                thread_desc * thrd = this_thread;
    9589
     
    133127
    134128                // Release the lock and leave
    135                 unlock( this->lock );
     129                unlock( &this->lock );
    136130                return;
    137131        }
    138132
    139133        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 );
    142136                thread_desc * thrd = this_thread;
    143137
     
    151145                        set_owner( this, thrd );
    152146
    153                         unlock( this->lock );
     147                        unlock( &this->lock );
    154148                        return;
    155149                }
     
    202196        // Leave single monitor
    203197        void __leave_monitor_desc( monitor_desc * this ) {
    204                 // Lock the monitor spinlock, DO_LOCK to reduce contention
    205                 DO_LOCK( this->lock DEBUG_CTX2 );
     198                // Lock the monitor spinlock, lock_yield to reduce contention
     199                lock_yield( &this->lock DEBUG_CTX2 );
    206200
    207201                LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     
    216210                if( this->recursion != 0) {
    217211                        LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
    218                         unlock( this->lock );
     212                        unlock( &this->lock );
    219213                        return;
    220214                }
     
    224218
    225219                // We can now let other threads in safely
    226                 unlock( this->lock );
     220                unlock( &this->lock );
    227221
    228222                //We need to wake-up the thread
     
    249243
    250244                // Lock the monitor now
    251                 DO_LOCK( this->lock DEBUG_CTX2 );
     245                lock_yield( &this->lock DEBUG_CTX2 );
    252246
    253247                disable_interrupts();
     
    736730}
    737731
    738 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
     732static inline void lock_all( spinlock * locks [], __lock_size_t count ) {
    739733        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
     738static inline void lock_all( monitor_desc * source [], spinlock * /*out*/ locks [], __lock_size_t count ) {
    745739        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 );
    748742                if(locks) locks[i] = l;
    749743        }
    750744}
    751745
    752 static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count ) {
     746static inline void unlock_all( spinlock * locks [], __lock_size_t count ) {
    753747        for( __lock_size_t i = 0; i < count; i++ ) {
    754                 unlock( *locks[i] );
     748                unlock( locks[i] );
    755749        }
    756750}
     
    758752static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ) {
    759753        for( __lock_size_t i = 0; i < count; i++ ) {
    760                 unlock( locks[i]->lock );
     754                unlock( &locks[i]->lock );
    761755        }
    762756}
     
    765759        monitor_desc * ctx [],
    766760        __lock_size_t count,
    767         __attribute((unused)) __spinlock_t * locks [],
     761        __attribute((unused)) spinlock * locks [],
    768762        unsigned int /*out*/ recursions [],
    769763        __waitfor_mask_t /*out*/ masks []
     
    778772        monitor_desc * ctx [],
    779773        __lock_size_t count,
    780         __spinlock_t * locks [],
     774        spinlock * locks [],
    781775        unsigned int /*out*/ recursions [],
    782776        __waitfor_mask_t /*out*/ masks []
Note: See TracChangeset for help on using the changeset viewer.