Ignore:
Timestamp:
Nov 2, 2017, 5:23:25 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
c1a9c86
Parents:
025278e
Message:

started using int_fast16_t for counts of monitors

Location:
src/libcfa/concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/invoke.h

    r025278e r513daec  
    2929
    3030        typedef void (*fptr_t)();
     31        typedef int_fast16_t __lock_size_t;
    3132
    3233        struct spinlock {
  • src/libcfa/concurrency/monitor.c

    r025278e r513daec  
    2626// Forward declarations
    2727static inline void set_owner ( monitor_desc * this, thread_desc * owner );
    28 static inline void set_owner ( monitor_desc * storage [], short count, thread_desc * owner );
    29 static inline void set_mask  ( monitor_desc * storage [], short count, const __waitfor_mask_t & mask );
     28static inline void set_owner ( monitor_desc * storage [], __lock_size_t count, thread_desc * owner );
     29static inline void set_mask  ( monitor_desc * storage [], __lock_size_t count, const __waitfor_mask_t & mask );
    3030static inline void reset_mask( monitor_desc * this );
    3131
     
    3333static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors );
    3434
    35 static inline void lock_all  ( spinlock * locks [], unsigned short count );
    36 static inline void lock_all  ( monitor_desc * source [], spinlock * /*out*/ locks [], unsigned short count );
    37 static inline void unlock_all( spinlock * locks [], unsigned short count );
    38 static inline void unlock_all( monitor_desc * locks [], unsigned short count );
    39 
    40 static inline void save   ( monitor_desc * ctx [], short count, spinlock * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
    41 static inline void restore( monitor_desc * ctx [], short count, spinlock * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );
    42 
    43 static inline void init     ( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
    44 static inline void init_push( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
     35static inline void lock_all  ( spinlock * locks [], __lock_size_t count );
     36static inline void lock_all  ( monitor_desc * source [], spinlock * /*out*/ locks [], __lock_size_t count );
     37static inline void unlock_all( spinlock * locks [], __lock_size_t count );
     38static inline void unlock_all( monitor_desc * locks [], __lock_size_t count );
     39
     40static inline void save   ( monitor_desc * ctx [], __lock_size_t count, spinlock * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
     41static inline void restore( monitor_desc * ctx [], __lock_size_t count, spinlock * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );
     42
     43static inline void init     ( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
     44static inline void init_push( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
    4545
    4646static inline thread_desc *        check_condition   ( __condition_criterion_t * );
     
    330330}
    331331
    332 
    333332// Ctor for monitor guard
    334333// Sorts monitors before entering
     
    349348        __enter_monitor_dtor( this.m, func );
    350349}
    351 
    352350
    353351// Dtor for monitor guard
     
    661659}
    662660
    663 static inline void set_owner( monitor_desc * monitors [], short count, thread_desc * owner ) {
     661static inline void set_owner( monitor_desc * monitors [], __lock_size_t count, thread_desc * owner ) {
    664662        monitors[0]->owner     = owner;
    665663        monitors[0]->recursion = 1;
    666         for( int i = 1; i < count; i++ ) {
     664        for( __lock_size_t i = 1; i < count; i++ ) {
    667665                monitors[i]->owner     = owner;
    668666                monitors[i]->recursion = 0;
     
    670668}
    671669
    672 static inline void set_mask( monitor_desc * storage [], short count, const __waitfor_mask_t & mask ) {
    673         for(int i = 0; i < count; i++) {
     670static inline void set_mask( monitor_desc * storage [], __lock_size_t count, const __waitfor_mask_t & mask ) {
     671        for( __lock_size_t i = 0; i < count; i++) {
    674672                storage[i]->mask = mask;
    675673        }
     
    725723}
    726724
    727 static inline void init( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
    728         for(int i = 0; i < count; i++) {
     725static inline void init( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
     726        for( __lock_size_t i = 0; i < count; i++) {
    729727                (criteria[i]){ monitors[i], waiter };
    730728        }
     
    733731}
    734732
    735 static inline void init_push( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
    736         for(int i = 0; i < count; i++) {
     733static inline void init_push( __lock_size_t count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
     734        for( __lock_size_t i = 0; i < count; i++) {
    737735                (criteria[i]){ monitors[i], waiter };
    738736                LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
     
    743741}
    744742
    745 static inline void lock_all( spinlock * locks [], unsigned short count ) {
    746         for( int i = 0; i < count; i++ ) {
     743static inline void lock_all( spinlock * locks [], __lock_size_t count ) {
     744        for( __lock_size_t i = 0; i < count; i++ ) {
    747745                lock_yield( locks[i] DEBUG_CTX2 );
    748746        }
    749747}
    750748
    751 static inline void lock_all( monitor_desc * source [], spinlock * /*out*/ locks [], unsigned short count ) {
    752         for( int i = 0; i < count; i++ ) {
     749static inline void lock_all( monitor_desc * source [], spinlock * /*out*/ locks [], __lock_size_t count ) {
     750        for( __lock_size_t i = 0; i < count; i++ ) {
    753751                spinlock * l = &source[i]->lock;
    754752                lock_yield( l DEBUG_CTX2 );
     
    757755}
    758756
    759 static inline void unlock_all( spinlock * locks [], unsigned short count ) {
    760         for( int i = 0; i < count; i++ ) {
     757static inline void unlock_all( spinlock * locks [], __lock_size_t count ) {
     758        for( __lock_size_t i = 0; i < count; i++ ) {
    761759                unlock( locks[i] );
    762760        }
    763761}
    764762
    765 static inline void unlock_all( monitor_desc * locks [], unsigned short count ) {
    766         for( int i = 0; i < count; i++ ) {
     763static inline void unlock_all( monitor_desc * locks [], __lock_size_t count ) {
     764        for( __lock_size_t i = 0; i < count; i++ ) {
    767765                unlock( &locks[i]->lock );
    768766        }
     
    771769static inline void save(
    772770        monitor_desc * ctx [],
    773         short count,
     771        __lock_size_t count,
    774772        __attribute((unused)) spinlock * locks [],
    775773        unsigned int /*out*/ recursions [],
    776774        __waitfor_mask_t /*out*/ masks []
    777775) {
    778         for( int i = 0; i < count; i++ ) {
     776        for( __lock_size_t i = 0; i < count; i++ ) {
    779777                recursions[i] = ctx[i]->recursion;
    780778                masks[i]      = ctx[i]->mask;
     
    784782static inline void restore(
    785783        monitor_desc * ctx [],
    786         short count,
     784        __lock_size_t count,
    787785        spinlock * locks [],
    788786        unsigned int /*out*/ recursions [],
     
    790788) {
    791789        lock_all( locks, count );
    792         for( int i = 0; i < count; i++ ) {
     790        for( __lock_size_t i = 0; i < count; i++ ) {
    793791                ctx[i]->recursion = recursions[i];
    794792                ctx[i]->mask      = masks[i];
Note: See TracChangeset for help on using the changeset viewer.