Changeset 19c43b7 for src/libcfa


Ignore:
Timestamp:
Sep 26, 2017, 2:30:51 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:
daacf82
Parents:
a2d4d1c
Message:

Added test to check correct statment is executed after waitfor

File:
1 edited

Legend:

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

    ra2d4d1c r19c43b7  
    7272#define monitor_restore restore( monitors, count, locks, recursions, masks )
    7373
    74 #define blockAndWake( thrd, cnt )                               /* Create the necessary information to use the signaller stack                         */ \
    75         monitor_save;                                             /* Save monitor states                                                                 */ \
    76         BlockInternal( locks, count, thrd, cnt );                 /* Everything is ready to go to sleep                                                  */ \
    77         monitor_restore;                                          /* We are back, restore the owners and recursions                                      */ \
    78 
    7974
    8075//-----------------------------------------------------------------------------
     
    229224        this_thread->monitors.func = func;
    230225
    231         LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
     226        // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
    232227
    233228        // Enter the monitors in order
     
    235230        enter( group );
    236231
    237         LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");
     232        // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");
    238233}
    239234
     
    241236// Dtor for monitor guard
    242237void ^?{}( monitor_guard_t & this ) {
    243         LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);
     238        // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);
    244239
    245240        // Leave the monitors in order
    246241        leave( this.m, this.count );
    247242
    248         LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");
     243        // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");
    249244
    250245        // Restore thread context
     
    425420//              block
    426421void __waitfor_internal( const __waitfor_mask_t & mask, int duration ) {
     422        LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal \n");
     423
    427424        // This statment doesn't have a contiguous list of monitors...
    428425        // Create one!
     
    431428        short actual_count = aggregate( mon_storage, mask );
    432429
    433         if(actual_count == 0) return;
     430        if(actual_count == 0) {
     431                LIB_DEBUG_PRINT_SAFE("Kernel :  nothing to wait for \n");
     432                return;
     433        }
     434
     435        LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal proceeding\n");
    434436
    435437        // Create storage for monitor context
     
    445447
    446448                if( next ) {
     449                        *mask.accepted = index;
    447450                        if( mask.clauses[index].is_dtor ) {
    448451                                #warning case not implemented
    449452                        }
    450453                        else {
    451                                 blockAndWake( &next, 1 );
     454                                LIB_DEBUG_PRINT_SAFE("Kernel : thread present, baton-passing\n");
     455
     456                                // Create the node specific to this wait operation
     457                                wait_ctx_primed( this_thread, 0 );
     458
     459                                // Save monitor states
     460                                monitor_save;
     461
     462                                // Set the owners to be the next thread
     463                                set_owner( monitors, count, next );
     464
     465                                // Everything is ready to go to sleep
     466                                BlockInternal( locks, count, &next, 1 );
     467
     468                                // We are back, restore the owners and recursions
     469                                monitor_restore;
     470
     471                                LIB_DEBUG_PRINT_SAFE("Kernel : thread present, returned\n");
    452472                        }
    453473
    454                         return index;
     474                        LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     475
     476                        return;
    455477                }
    456478        }
     
    458480
    459481        if( duration == 0 ) {
     482                LIB_DEBUG_PRINT_SAFE("Kernel : non-blocking, exiting\n");
     483
    460484                unlock_all( locks, count );
     485
     486                LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
    461487                return;
    462488        }
     
    465491        verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    466492
     493        LIB_DEBUG_PRINT_SAFE("Kernel : blocking waitfor\n");
     494
     495        // Create the node specific to this wait operation
     496        wait_ctx_primed( this_thread, 0 );
    467497
    468498        monitor_save;
    469499        set_mask( monitors, count, mask );
    470500
    471         BlockInternal( locks, count );       // Everything is ready to go to sleep
    472         //WE WOKE UP
    473         monitor_restore;                     //We are back, restore the masks and recursions
     501        //Everything is ready to go to sleep
     502        BlockInternal( locks, count );
     503
     504
     505        // WE WOKE UP
     506
     507
     508        //We are back, restore the masks and recursions
     509        monitor_restore;
     510
     511        LIB_DEBUG_PRINT_SAFE("Kernel : exiting\n");
     512
     513        LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
    474514}
    475515
     
    478518
    479519static inline void set_owner( monitor_desc * this, thread_desc * owner ) {
    480         LIB_DEBUG_PRINT_SAFE("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
     520        // LIB_DEBUG_PRINT_SAFE("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    481521
    482522        //Pass the monitor appropriately
     
    559599
    560600static inline void lock_all( spinlock ** locks, unsigned short count ) {
     601        LIB_DEBUG_ACQUIRE();
     602        LIB_DEBUG_PRINT_NOLOCK("Kernel :   Locking");
    561603        for( int i = 0; i < count; i++ ) {
     604                LIB_DEBUG_PRINT_NOLOCK(" %p", locks[i]);
    562605                lock_yield( locks[i] DEBUG_CTX2 );
    563606        }
     607        LIB_DEBUG_PRINT_NOLOCK("\n");
     608        LIB_DEBUG_RELEASE();
    564609}
    565610
    566611static inline void lock_all( monitor_desc ** source, spinlock ** /*out*/ locks, unsigned short count ) {
     612        LIB_DEBUG_ACQUIRE();
     613        LIB_DEBUG_PRINT_NOLOCK("Kernel :   Locking");
    567614        for( int i = 0; i < count; i++ ) {
    568615                spinlock * l = &source[i]->lock;
     616                LIB_DEBUG_PRINT_NOLOCK(" %p", l);
    569617                lock_yield( l DEBUG_CTX2 );
    570618                if(locks) locks[i] = l;
    571619        }
     620        LIB_DEBUG_PRINT_NOLOCK("\n");
     621        LIB_DEBUG_RELEASE();
    572622}
    573623
Note: See TracChangeset for help on using the changeset viewer.