Ignore:
Timestamp:
Dec 5, 2017, 2:35:03 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f9feab8
Parents:
9c35431 (diff), 65197c2 (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 cleanup-dtors

File:
1 edited

Legend:

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

    r9c35431 rc13e8dc8  
    1919#include <inttypes.h>
    2020
    21 #include "libhdr.h"
    2221#include "kernel_private.h"
    2322
     
    9190        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    9291                // Lock the monitor spinlock
    93                 DO_LOCK( this->lock DEBUG_CTX2 );
     92                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    9493                thread_desc * thrd = this_thread;
    9594
    96                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     95                __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9796
    9897                if( !this->owner ) {
     
    10099                        set_owner( this, thrd );
    101100
    102                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon is free \n");
     101                        __cfaabi_dbg_print_safe("Kernel :  mon is free \n");
    103102                }
    104103                else if( this->owner == thrd) {
     
    106105                        this->recursion += 1;
    107106
    108                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon already owned \n");
     107                        __cfaabi_dbg_print_safe("Kernel :  mon already owned \n");
    109108                }
    110109                else if( is_accepted( this, group) ) {
     
    115114                        reset_mask( this );
    116115
    117                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts \n");
     116                        __cfaabi_dbg_print_safe("Kernel :  mon accepts \n");
    118117                }
    119118                else {
    120                         LIB_DEBUG_PRINT_SAFE("Kernel :  blocking \n");
     119                        __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    121120
    122121                        // Some one else has the monitor, wait in line for it
     
    124123                        BlockInternal( &this->lock );
    125124
    126                         LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered  mon %p\n", thrd, this);
     125                        __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
    127126
    128127                        // BlockInternal will unlock spinlock, no need to unlock ourselves
     
    130129                }
    131130
    132                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered  mon %p\n", thrd, this);
     131                __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
    133132
    134133                // Release the lock and leave
     
    139138        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    140139                // Lock the monitor spinlock
    141                 DO_LOCK( this->lock DEBUG_CTX2 );
     140                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    142141                thread_desc * thrd = this_thread;
    143142
    144                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
     143                __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
    145144
    146145
    147146                if( !this->owner ) {
    148                         LIB_DEBUG_PRINT_SAFE("Kernel : Destroying free mon %p\n", this);
     147                        __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);
    149148
    150149                        // No one has the monitor, just take it
     
    164163                __monitor_group_t group = { &this, 1, func };
    165164                if( is_accepted( this, group) ) {
    166                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts dtor, block and signal it \n");
     165                        __cfaabi_dbg_print_safe("Kernel :  mon accepts dtor, block and signal it \n");
    167166
    168167                        // Wake the thread that is waiting for this
     
    183182                }
    184183                else {
    185                         LIB_DEBUG_PRINT_SAFE("Kernel :  blocking \n");
     184                        __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    186185
    187186                        wait_ctx( this_thread, 0 )
     
    196195                }
    197196
    198                 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying %p\n", this);
     197                __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);
    199198
    200199        }
     
    203202        void __leave_monitor_desc( monitor_desc * this ) {
    204203                // Lock the monitor spinlock, DO_LOCK to reduce contention
    205                 DO_LOCK( this->lock DEBUG_CTX2 );
    206 
    207                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     204                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     205
     206                __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
    208207
    209208                verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this );
     
    215214                // it means we don't need to do anything
    216215                if( this->recursion != 0) {
    217                         LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
     216                        __cfaabi_dbg_print_safe("Kernel :  recursion still %d\n", this->recursion);
    218217                        unlock( this->lock );
    219218                        return;
     
    232231        // Leave single monitor for the last time
    233232        void __leave_dtor_monitor_desc( monitor_desc * this ) {
    234                 LIB_DEBUG_DO(
     233                __cfaabi_dbg_debug_do(
    235234                        if( this_thread != this->owner ) {
    236235                                abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
     
    249248
    250249                // Lock the monitor now
    251                 DO_LOCK( this->lock DEBUG_CTX2 );
     250                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    252251
    253252                disable_interrupts();
     
    308307        (this_thread->monitors){m, count, func};
    309308
    310         // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
     309        // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);
    311310
    312311        // Enter the monitors in order
     
    314313        enter( group );
    315314
    316         // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");
     315        // __cfaabi_dbg_print_safe("MGUARD : entered\n");
    317316}
    318317
     
    320319// Dtor for monitor guard
    321320void ^?{}( monitor_guard_t & this ) {
    322         // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);
     321        // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);
    323322
    324323        // Leave the monitors in order
    325324        leave( this.m, this.count );
    326325
    327         // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");
     326        // __cfaabi_dbg_print_safe("MGUARD : left\n");
    328327
    329328        // Restore thread context
     
    430429
    431430        //Some more checking in debug
    432         LIB_DEBUG_DO(
     431        __cfaabi_dbg_debug_do(
    433432                thread_desc * this_thrd = this_thread;
    434433                if ( this.monitor_count != this_thrd->monitors.size ) {
     
    487486        set_owner( monitors, count, signallee );
    488487
    489         LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );
     488        __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );
    490489
    491490        //Everything is ready to go to sleep
     
    496495
    497496
    498         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :   signal_block returned\n" );
     497        __cfaabi_dbg_print_buffer_local( "Kernel :   signal_block returned\n" );
    499498
    500499        //We are back, restore the masks and recursions
     
    535534        __lock_size_t actual_count = aggregate( mon_storage, mask );
    536535
    537         LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
     536        __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
    538537
    539538        if(actual_count == 0) return;
    540539
    541         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");
     540        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");
    542541
    543542        // Create storage for monitor context
     
    556555                        __acceptable_t& accepted = mask[index];
    557556                        if( accepted.is_dtor ) {
    558                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
     557                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");
    559558                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
    560559
     
    568567                        }
    569568                        else {
    570                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");
     569                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n");
    571570
    572571                                // Create the node specific to this wait operation
     
    576575                                monitor_save;
    577576
    578                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :  baton of %d monitors : ", count );
     577                                __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %d monitors : ", count );
    579578                                #ifdef __CFA_DEBUG_PRINT__
    580579                                        for( int i = 0; i < count; i++) {
    581                                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
     580                                                __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
    582581                                        }
    583582                                #endif
    584                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");
     583                                __cfaabi_dbg_print_buffer_local( "\n");
    585584
    586585                                // Set the owners to be the next thread
     
    593592                                monitor_restore;
    594593
    595                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");
     594                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");
    596595                        }
    597596
    598                         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     597                        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    599598                        return;
    600599                }
     
    603602
    604603        if( duration == 0 ) {
    605                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");
     604                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");
    606605
    607606                unlock_all( locks, count );
    608607
    609                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     608                __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    610609                return;
    611610        }
     
    614613        verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    615614
    616         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");
     615        __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");
    617616
    618617        // Create the node specific to this wait operation
     
    636635        monitor_restore;
    637636
    638         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");
    639 
    640         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     637        __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");
     638
     639        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    641640}
    642641
     
    645644
    646645static inline void set_owner( monitor_desc * this, thread_desc * owner ) {
    647         // LIB_DEBUG_PRINT_SAFE("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
     646        // __cfaabi_dbg_print_safe("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    648647
    649648        //Pass the monitor appropriately
     
    677676static inline thread_desc * next_thread( monitor_desc * this ) {
    678677        //Check the signaller stack
    679         LIB_DEBUG_PRINT_SAFE("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     678        __cfaabi_dbg_print_safe("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    680679        __condition_criterion_t * urgent = pop( this->signal_stack );
    681680        if( urgent ) {
     
    729728        for( __lock_size_t i = 0; i < count; i++) {
    730729                (criteria[i]){ monitors[i], waiter };
    731                 LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
     730                __cfaabi_dbg_print_safe( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
    732731                push( criteria[i].target->signal_stack, &criteria[i] );
    733732        }
     
    738737static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    739738        for( __lock_size_t i = 0; i < count; i++ ) {
    740                 DO_LOCK( *locks[i] DEBUG_CTX2 );
     739                DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );
    741740        }
    742741}
     
    745744        for( __lock_size_t i = 0; i < count; i++ ) {
    746745                __spinlock_t * l = &source[i]->lock;
    747                 DO_LOCK( *l DEBUG_CTX2 );
     746                DO_LOCK( *l __cfaabi_dbg_ctx2 );
    748747                if(locks) locks[i] = l;
    749748        }
     
    803802        for(    int i = 0; i < count; i++ ) {
    804803
    805                 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
     804                // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target );
    806805                if( &criteria[i] == target ) {
    807806                        criteria[i].ready = true;
    808                         // LIB_DEBUG_PRINT_SAFE( "True\n" );
     807                        // __cfaabi_dbg_print_safe( "True\n" );
    809808                }
    810809
     
    812811        }
    813812
    814         LIB_DEBUG_PRINT_SAFE( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
     813        __cfaabi_dbg_print_safe( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
    815814        return ready2run ? node->waiting_thread : NULL;
    816815}
     
    819818        thread_desc * thrd = this_thread;
    820819        if( !this.monitors ) {
    821                 // LIB_DEBUG_PRINT_SAFE("Branding\n");
     820                // __cfaabi_dbg_print_safe("Branding\n");
    822821                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    823822                this.monitor_count = thrd->monitors.size;
Note: See TracChangeset for help on using the changeset viewer.