Changeset daacf82 for src/libcfa


Ignore:
Timestamp:
Sep 26, 2017, 4:06:22 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:
a7d151f
Parents:
19c43b7
Message:

Added test for validate single monitor barging avoidance for waitfor statments

File:
1 edited

Legend:

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

    r19c43b7 rdaacf82  
    2323//-----------------------------------------------------------------------------
    2424// Forward declarations
    25 static inline void set_owner( monitor_desc * this, thread_desc * owner );
    26 static inline void set_owner( monitor_desc ** storage, short count, thread_desc * owner );
    27 static inline void set_mask ( monitor_desc ** storage, short count, const __waitfor_mask_t & mask );
     25static inline void set_owner ( monitor_desc * this, thread_desc * owner );
     26static inline void set_owner ( monitor_desc ** storage, short count, thread_desc * owner );
     27static inline void set_mask  ( monitor_desc ** storage, short count, const __waitfor_mask_t & mask );
     28static inline void reset_mask( monitor_desc * this );
    2829
    2930static inline thread_desc * next_thread( monitor_desc * this );
     
    102103                        // Some one was waiting for us, enter
    103104                        set_owner( this, thrd );
     105
     106                        // Reset mask
     107                        reset_mask( this );
    104108
    105109                        LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts \n");
     
    420424//              block
    421425void __waitfor_internal( const __waitfor_mask_t & mask, int duration ) {
    422         LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal \n");
    423 
    424426        // This statment doesn't have a contiguous list of monitors...
    425427        // Create one!
     
    428430        short actual_count = aggregate( mon_storage, mask );
    429431
    430         if(actual_count == 0) {
    431                 LIB_DEBUG_PRINT_SAFE("Kernel :  nothing to wait for \n");
    432                 return;
    433         }
     432        if(actual_count == 0) return;
    434433
    435434        LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal proceeding\n");
     
    499498        set_mask( monitors, count, mask );
    500499
     500        for(int i = 0; i < count; i++) {
     501                verify( monitors[i]->owner == this_thread );
     502        }
     503
    501504        //Everything is ready to go to sleep
    502505        BlockInternal( locks, count );
     
    537540                storage[i]->mask = mask;
    538541        }
     542}
     543
     544static inline void reset_mask( monitor_desc * this ) {
     545        this->mask.accepted = NULL;
     546        this->mask.clauses = NULL;
     547        this->mask.size = 0;
    539548}
    540549
     
    599608
    600609static inline void lock_all( spinlock ** locks, unsigned short count ) {
    601         LIB_DEBUG_ACQUIRE();
    602         LIB_DEBUG_PRINT_NOLOCK("Kernel :   Locking");
    603610        for( int i = 0; i < count; i++ ) {
    604                 LIB_DEBUG_PRINT_NOLOCK(" %p", locks[i]);
    605611                lock_yield( locks[i] DEBUG_CTX2 );
    606612        }
    607         LIB_DEBUG_PRINT_NOLOCK("\n");
    608         LIB_DEBUG_RELEASE();
    609613}
    610614
    611615static inline void lock_all( monitor_desc ** source, spinlock ** /*out*/ locks, unsigned short count ) {
    612         LIB_DEBUG_ACQUIRE();
    613         LIB_DEBUG_PRINT_NOLOCK("Kernel :   Locking");
    614616        for( int i = 0; i < count; i++ ) {
    615617                spinlock * l = &source[i]->lock;
    616                 LIB_DEBUG_PRINT_NOLOCK(" %p", l);
    617618                lock_yield( l DEBUG_CTX2 );
    618619                if(locks) locks[i] = l;
    619620        }
    620         LIB_DEBUG_PRINT_NOLOCK("\n");
    621         LIB_DEBUG_RELEASE();
    622621}
    623622
     
    634633}
    635634
    636 static inline void save   ( monitor_desc ** ctx, short count, __attribute((unused)) spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks ) {
     635static inline void save( monitor_desc ** ctx, short count, __attribute((unused)) spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks ) {
    637636        for( int i = 0; i < count; i++ ) {
    638637                recursions[i] = ctx[i]->recursion;
Note: See TracChangeset for help on using the changeset viewer.