Ignore:
File:
1 edited

Legend:

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

    r0cf5b79 r36982fc  
    9191        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    9292                // Lock the monitor spinlock
    93                 DO_LOCK( this->lock DEBUG_CTX2 );
     93                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    9494                thread_desc * thrd = this_thread;
    9595
    96                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     96                __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9797
    9898                if( !this->owner ) {
     
    100100                        set_owner( this, thrd );
    101101
    102                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon is free \n");
     102                        __cfaabi_dbg_print_safe("Kernel :  mon is free \n");
    103103                }
    104104                else if( this->owner == thrd) {
     
    106106                        this->recursion += 1;
    107107
    108                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon already owned \n");
     108                        __cfaabi_dbg_print_safe("Kernel :  mon already owned \n");
    109109                }
    110110                else if( is_accepted( this, group) ) {
     
    115115                        reset_mask( this );
    116116
    117                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts \n");
     117                        __cfaabi_dbg_print_safe("Kernel :  mon accepts \n");
    118118                }
    119119                else {
    120                         LIB_DEBUG_PRINT_SAFE("Kernel :  blocking \n");
     120                        __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    121121
    122122                        // Some one else has the monitor, wait in line for it
     
    124124                        BlockInternal( &this->lock );
    125125
    126                         LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered  mon %p\n", thrd, this);
     126                        __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
    127127
    128128                        // BlockInternal will unlock spinlock, no need to unlock ourselves
     
    130130                }
    131131
    132                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered  mon %p\n", thrd, this);
     132                __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
    133133
    134134                // Release the lock and leave
     
    139139        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    140140                // Lock the monitor spinlock
    141                 DO_LOCK( this->lock DEBUG_CTX2 );
     141                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    142142                thread_desc * thrd = this_thread;
    143143
    144                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
     144                __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
    145145
    146146
    147147                if( !this->owner ) {
    148                         LIB_DEBUG_PRINT_SAFE("Kernel : Destroying free mon %p\n", this);
     148                        __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);
    149149
    150150                        // No one has the monitor, just take it
     
    164164                __monitor_group_t group = { &this, 1, func };
    165165                if( is_accepted( this, group) ) {
    166                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts dtor, block and signal it \n");
     166                        __cfaabi_dbg_print_safe("Kernel :  mon accepts dtor, block and signal it \n");
    167167
    168168                        // Wake the thread that is waiting for this
     
    183183                }
    184184                else {
    185                         LIB_DEBUG_PRINT_SAFE("Kernel :  blocking \n");
     185                        __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    186186
    187187                        wait_ctx( this_thread, 0 )
     
    196196                }
    197197
    198                 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying %p\n", this);
     198                __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);
    199199
    200200        }
     
    203203        void __leave_monitor_desc( monitor_desc * this ) {
    204204                // 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);
     205                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     206
     207                __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
    208208
    209209                verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this );
     
    215215                // it means we don't need to do anything
    216216                if( this->recursion != 0) {
    217                         LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
     217                        __cfaabi_dbg_print_safe("Kernel :  recursion still %d\n", this->recursion);
    218218                        unlock( this->lock );
    219219                        return;
     
    232232        // Leave single monitor for the last time
    233233        void __leave_dtor_monitor_desc( monitor_desc * this ) {
    234                 LIB_DEBUG_DO(
     234                __cfaabi_dbg_debug_do(
    235235                        if( this_thread != this->owner ) {
    236236                                abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
     
    249249
    250250                // Lock the monitor now
    251                 DO_LOCK( this->lock DEBUG_CTX2 );
     251                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    252252
    253253                disable_interrupts();
     
    308308        (this_thread->monitors){m, count, func};
    309309
    310         // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
     310        // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);
    311311
    312312        // Enter the monitors in order
     
    314314        enter( group );
    315315
    316         // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");
     316        // __cfaabi_dbg_print_safe("MGUARD : entered\n");
    317317}
    318318
     
    320320// Dtor for monitor guard
    321321void ^?{}( monitor_guard_t & this ) {
    322         // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);
     322        // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);
    323323
    324324        // Leave the monitors in order
    325325        leave( this.m, this.count );
    326326
    327         // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");
     327        // __cfaabi_dbg_print_safe("MGUARD : left\n");
    328328
    329329        // Restore thread context
     
    430430
    431431        //Some more checking in debug
    432         LIB_DEBUG_DO(
     432        __cfaabi_dbg_debug_do(
    433433                thread_desc * this_thrd = this_thread;
    434434                if ( this.monitor_count != this_thrd->monitors.size ) {
     
    487487        set_owner( monitors, count, signallee );
    488488
    489         LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );
     489        __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );
    490490
    491491        //Everything is ready to go to sleep
     
    496496
    497497
    498         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :   signal_block returned\n" );
     498        __cfaabi_dbg_print_buffer_local( "Kernel :   signal_block returned\n" );
    499499
    500500        //We are back, restore the masks and recursions
     
    535535        __lock_size_t actual_count = aggregate( mon_storage, mask );
    536536
    537         LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
     537        __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
    538538
    539539        if(actual_count == 0) return;
    540540
    541         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");
     541        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");
    542542
    543543        // Create storage for monitor context
     
    556556                        __acceptable_t& accepted = mask[index];
    557557                        if( accepted.is_dtor ) {
    558                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
     558                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");
    559559                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
    560560
     
    568568                        }
    569569                        else {
    570                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");
     570                                __cfaabi_dbg_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 );
     578                                __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %d monitors : ", count );
    579579                                #ifdef __CFA_DEBUG_PRINT__
    580580                                        for( int i = 0; i < count; i++) {
    581                                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
     581                                                __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
    582582                                        }
    583583                                #endif
    584                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");
     584                                __cfaabi_dbg_print_buffer_local( "\n");
    585585
    586586                                // Set the owners to be the next thread
     
    593593                                monitor_restore;
    594594
    595                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");
     595                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");
    596596                        }
    597597
    598                         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     598                        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    599599                        return;
    600600                }
     
    603603
    604604        if( duration == 0 ) {
    605                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");
     605                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");
    606606
    607607                unlock_all( locks, count );
    608608
    609                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     609                __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    610610                return;
    611611        }
     
    614614        verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    615615
    616         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");
     616        __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");
    617617
    618618        // Create the node specific to this wait operation
     
    636636        monitor_restore;
    637637
    638         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");
    639 
    640         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     638        __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");
     639
     640        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    641641}
    642642
     
    645645
    646646static 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 );
     647        // __cfaabi_dbg_print_safe("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    648648
    649649        //Pass the monitor appropriately
     
    677677static inline thread_desc * next_thread( monitor_desc * this ) {
    678678        //Check the signaller stack
    679         LIB_DEBUG_PRINT_SAFE("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     679        __cfaabi_dbg_print_safe("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    680680        __condition_criterion_t * urgent = pop( this->signal_stack );
    681681        if( urgent ) {
     
    729729        for( __lock_size_t i = 0; i < count; i++) {
    730730                (criteria[i]){ monitors[i], waiter };
    731                 LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
     731                __cfaabi_dbg_print_safe( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
    732732                push( criteria[i].target->signal_stack, &criteria[i] );
    733733        }
     
    738738static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    739739        for( __lock_size_t i = 0; i < count; i++ ) {
    740                 DO_LOCK( *locks[i] DEBUG_CTX2 );
     740                DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );
    741741        }
    742742}
     
    745745        for( __lock_size_t i = 0; i < count; i++ ) {
    746746                __spinlock_t * l = &source[i]->lock;
    747                 DO_LOCK( *l DEBUG_CTX2 );
     747                DO_LOCK( *l __cfaabi_dbg_ctx2 );
    748748                if(locks) locks[i] = l;
    749749        }
     
    803803        for(    int i = 0; i < count; i++ ) {
    804804
    805                 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
     805                // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target );
    806806                if( &criteria[i] == target ) {
    807807                        criteria[i].ready = true;
    808                         // LIB_DEBUG_PRINT_SAFE( "True\n" );
     808                        // __cfaabi_dbg_print_safe( "True\n" );
    809809                }
    810810
     
    812812        }
    813813
    814         LIB_DEBUG_PRINT_SAFE( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
     814        __cfaabi_dbg_print_safe( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
    815815        return ready2run ? node->waiting_thread : NULL;
    816816}
     
    819819        thread_desc * thrd = this_thread;
    820820        if( !this.monitors ) {
    821                 // LIB_DEBUG_PRINT_SAFE("Branding\n");
     821                // __cfaabi_dbg_print_safe("Branding\n");
    822822                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    823823                this.monitor_count = thrd->monitors.size;
    824824
    825                 this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );
     825                this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) );
    826826                for( int i = 0; i < this.monitor_count; i++ ) {
    827827                        this.monitors[i] = thrd->monitors[i];
Note: See TracChangeset for help on using the changeset viewer.