Ignore:
Timestamp:
Nov 15, 2017, 2:01:08 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
20632a2
Parents:
c95b115 (diff), 6d2386e (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.
Message:

Merge branch 'master' into unique-variable-renaming

File:
1 edited

Legend:

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

    rc95b115 r490db327  
    3434static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors );
    3535
    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 );
     36static inline void lock_all  ( __spinlock_t * locks [], __lock_size_t count );
     37static inline void lock_all  ( monitor_desc * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count );
     38static inline void unlock_all( __spinlock_t * 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 * 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 [] );
     41static inline void save   ( monitor_desc * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
     42static inline void restore( monitor_desc * ctx [], __lock_size_t count, __spinlock_t * 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
    5561
    5662//-----------------------------------------------------------------------------
     
    7177        unsigned int recursions[ count ];                         /* Save the current recursion levels to restore them later                             */ \
    7278        __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                               */ \
    7480
    7581#define monitor_save    save   ( monitors, count, locks, recursions, masks )
     
    8490        // Enter single monitor
    8591        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    86                 // Lock the monitor spinlock, lock_yield to reduce contention
    87                 lock_yield( &this->lock DEBUG_CTX2 );
     92                // Lock the monitor spinlock
     93                DO_LOCK( this->lock DEBUG_CTX2 );
    8894                thread_desc * thrd = this_thread;
    8995
     
    127133
    128134                // Release the lock and leave
    129                 unlock( &this->lock );
     135                unlock( this->lock );
    130136                return;
    131137        }
    132138
    133139        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    134                 // Lock the monitor spinlock, lock_yield to reduce contention
    135                 lock_yield( &this->lock DEBUG_CTX2 );
     140                // Lock the monitor spinlock
     141                DO_LOCK( this->lock DEBUG_CTX2 );
    136142                thread_desc * thrd = this_thread;
    137143
     
    145151                        set_owner( this, thrd );
    146152
    147                         unlock( &this->lock );
     153                        unlock( this->lock );
    148154                        return;
    149155                }
     
    196202        // Leave single monitor
    197203        void __leave_monitor_desc( monitor_desc * this ) {
    198                 // Lock the monitor spinlock, lock_yield to reduce contention
    199                 lock_yield( &this->lock DEBUG_CTX2 );
     204                // Lock the monitor spinlock, DO_LOCK to reduce contention
     205                DO_LOCK( this->lock DEBUG_CTX2 );
    200206
    201207                LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     
    210216                if( this->recursion != 0) {
    211217                        LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
    212                         unlock( &this->lock );
     218                        unlock( this->lock );
    213219                        return;
    214220                }
     
    218224
    219225                // We can now let other threads in safely
    220                 unlock( &this->lock );
     226                unlock( this->lock );
    221227
    222228                //We need to wake-up the thread
     
    243249
    244250                // Lock the monitor now
    245                 lock_yield( &this->lock DEBUG_CTX2 );
     251                DO_LOCK( this->lock DEBUG_CTX2 );
    246252
    247253                disable_interrupts();
     
    730736}
    731737
    732 static inline void lock_all( spinlock * locks [], __lock_size_t count ) {
     738static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    733739        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
     744static inline void lock_all( monitor_desc * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count ) {
    739745        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 );
    742748                if(locks) locks[i] = l;
    743749        }
    744750}
    745751
    746 static inline void unlock_all( spinlock * locks [], __lock_size_t count ) {
     752static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count ) {
    747753        for( __lock_size_t i = 0; i < count; i++ ) {
    748                 unlock( locks[i] );
     754                unlock( *locks[i] );
    749755        }
    750756}
     
    752758static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ) {
    753759        for( __lock_size_t i = 0; i < count; i++ ) {
    754                 unlock( &locks[i]->lock );
     760                unlock( locks[i]->lock );
    755761        }
    756762}
     
    759765        monitor_desc * ctx [],
    760766        __lock_size_t count,
    761         __attribute((unused)) spinlock * locks [],
     767        __attribute((unused)) __spinlock_t * locks [],
    762768        unsigned int /*out*/ recursions [],
    763769        __waitfor_mask_t /*out*/ masks []
     
    772778        monitor_desc * ctx [],
    773779        __lock_size_t count,
    774         spinlock * locks [],
     780        __spinlock_t * locks [],
    775781        unsigned int /*out*/ recursions [],
    776782        __waitfor_mask_t /*out*/ masks []
Note: See TracChangeset for help on using the changeset viewer.