Ignore:
Timestamp:
Oct 27, 2017, 5:54:56 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:
af0c8da
Parents:
9f0b975
Message:

Modified waitfor to sort monitors

File:
1 edited

Legend:

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

    r9f0b975 r6a5be52  
    9595                else if( this->owner == thrd) {
    9696                        // We already have the monitor, just note how many times we took it
    97                         verify( this->recursion > 0 );
    9897                        this->recursion += 1;
    9998
     
    207206                // it means we don't need to do anything
    208207                if( this->recursion != 0) {
     208                        LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
    209209                        unlock( &this->lock );
    210210                        return;
     
    536536        short actual_count = aggregate( mon_storage, mask );
    537537
    538         LIB_DEBUG_PRINT_SAFE("Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (short)max);
     538        LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (short)max);
    539539
    540540        if(actual_count == 0) return;
    541541
    542         LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal proceeding\n");
     542        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");
    543543
    544544        // Create storage for monitor context
     
    556556                        *mask.accepted = index;
    557557                        if( mask.clauses[index].is_dtor ) {
    558                                 LIB_DEBUG_PRINT_SAFE("Kernel : dtor already there\n");
     558                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
    559559                                verifyf( mask.clauses[index].size == 1        , "ERROR: Accepted dtor has more than 1 mutex parameter." );
    560560
     
    568568                        }
    569569                        else {
    570                                 LIB_DEBUG_PRINT_SAFE("Kernel : thread present, baton-passing\n");
     570                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");
    571571
    572572                                // Create the node specific to this wait operation
     
    576576                                monitor_save;
    577577
     578                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :  baton of %d monitors : ", count );
     579                                #ifdef __CFA_DEBUG_PRINT__
     580                                        for( int i = 0; i < count; i++) {
     581                                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
     582                                        }
     583                                #endif
     584                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");
     585
    578586                                // Set the owners to be the next thread
    579587                                set_owner( monitors, count, next );
     
    585593                                monitor_restore;
    586594
    587                                 LIB_DEBUG_PRINT_SAFE("Kernel : thread present, returned\n");
     595                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");
    588596                        }
    589597
    590                         LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     598                        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    591599
    592600                        return;
     
    596604
    597605        if( duration == 0 ) {
    598                 LIB_DEBUG_PRINT_SAFE("Kernel : non-blocking, exiting\n");
     606                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");
    599607
    600608                unlock_all( locks, count );
    601609
    602                 LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     610                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    603611                return;
    604612        }
     
    607615        verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    608616
    609         LIB_DEBUG_PRINT_SAFE("Kernel : blocking waitfor\n");
     617        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");
    610618
    611619        // Create the node specific to this wait operation
     
    629637        monitor_restore;
    630638
    631         LIB_DEBUG_PRINT_SAFE("Kernel : exiting\n");
    632 
    633         LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     639        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");
     640
     641        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    634642}
    635643
     
    648656
    649657static inline void set_owner( monitor_desc ** monitors, short count, thread_desc * owner ) {
    650         for( int i = 0; i < count; i++ ) {
    651                 set_owner( monitors[i], owner );
     658        monitors[0]->owner     = owner;
     659        monitors[0]->recursion = 1;
     660        for( int i = 1; i < count; i++ ) {
     661                monitors[i]->owner     = owner;
     662                monitors[i]->recursion = 0;
    652663        }
    653664}
     
    667678static inline thread_desc * next_thread( monitor_desc * this ) {
    668679        //Check the signaller stack
     680        LIB_DEBUG_PRINT_SAFE("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    669681        __condition_criterion_t * urgent = pop( &this->signal_stack );
    670682        if( urgent ) {
     
    718730        for(int i = 0; i < count; i++) {
    719731                (criteria[i]){ monitors[i], waiter };
     732                LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
    720733                push( &criteria[i].target->signal_stack, &criteria[i] );
    721734        }
     
    788801        }
    789802
    790         // LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );
     803        LIB_DEBUG_PRINT_SAFE( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
    791804        return ready2run ? node->waiting_thread : NULL;
    792805}
     
    856869        short size = 0;
    857870        for( int i = 0; i < mask.size; i++ ) {
     871                qsort( mask.clauses[i].list, mask.clauses[i].size );
    858872                for( int j = 0; j < mask.clauses[i].size; j++) {
    859873                        insert_unique( storage, size, mask.clauses[i].list[j] );
    860874                }
    861875        }
     876        // TODO insertion sort instead of this
    862877        qsort( storage, size );
    863878        return size;
Note: See TracChangeset for help on using the changeset viewer.