Ignore:
Timestamp:
Jun 29, 2017, 11:59:09 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
b751c8e
Parents:
7bbba76
Message:

Commented some debug messages.
Monitors now yield when spinning.
Debug mode saves more information about previous locks and interrupts

File:
1 edited

Legend:

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

    r7bbba76 rb227f68  
    4545extern "C" {
    4646        void __enter_monitor_desc( monitor_desc * this ) {
    47                 lock( &this->lock DEBUG_CTX2 );
     47                lock_yield( &this->lock DEBUG_CTX2 );
    4848                thread_desc * thrd = this_thread;
    4949
     
    7676        //      TODO
    7777        void __leave_monitor_desc( monitor_desc * this ) {
    78                 lock( &this->lock DEBUG_CTX2 );
     78                lock_yield( &this->lock DEBUG_CTX2 );
    7979
    8080                // LIB_DEBUG_PRINT_SAFE("%p Leaving %p (o: %p, r: %i). ", this_thread, this, this->owner, this->recursion);
     
    104104        void __leave_thread_monitor( thread_desc * thrd ) {
    105105                monitor_desc * this = &thrd->mon;
    106                 lock( &this->lock DEBUG_CTX2 );
     106                lock_yield( &this->lock DEBUG_CTX2 );
    107107
    108108                disable_interrupts();
     
    188188// Internal scheduling
    189189void wait( condition * this, uintptr_t user_info = 0 ) {
    190         LIB_DEBUG_PRINT_SAFE("Waiting\n");
     190        // LIB_DEBUG_PRINT_SAFE("Waiting\n");
    191191
    192192        brand_condition( this );
     
    201201        spinlock *   locks     [ count ];               //We need to pass-in an array of locks to BlockInternal
    202202
    203         LIB_DEBUG_PRINT_SAFE("count %i\n", count);
     203        // LIB_DEBUG_PRINT_SAFE("count %i\n", count);
    204204
    205205        __condition_node_t waiter = { (thread_desc*)this_thread, count, user_info };
     
    208208        for(int i = 0; i < count; i++) {
    209209                (&criteria[i]){ this->monitors[i], &waiter };
    210                 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     210                // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
    211211        }
    212212
     
    230230        }
    231231
    232         LIB_DEBUG_PRINT_SAFE("Will unblock: ");
     232        // LIB_DEBUG_PRINT_SAFE("Will unblock: ");
    233233        for(int i = 0; i < thread_count; i++) {
    234                 LIB_DEBUG_PRINT_SAFE("%p ", threads[i]);
    235         }
    236         LIB_DEBUG_PRINT_SAFE("\n");
     234                // LIB_DEBUG_PRINT_SAFE("%p ", threads[i]);
     235        }
     236        // LIB_DEBUG_PRINT_SAFE("\n");
    237237
    238238        // Everything is ready to go to sleep
     
    251251bool signal( condition * this ) {
    252252        if( is_empty( this ) ) {
    253                 LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
     253                // LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
    254254                return false;
    255255        }
     
    277277        //Lock all the monitors
    278278        lock_all( this->monitors, NULL, count );
    279         LIB_DEBUG_PRINT_SAFE("Signalling");
     279        // LIB_DEBUG_PRINT_SAFE("Signalling");
    280280
    281281        //Pop the head of the waiting queue
     
    285285        for(int i = 0; i < count; i++) {
    286286                __condition_criterion_t * crit = &node->criteria[i];
    287                 LIB_DEBUG_PRINT_SAFE(" %p", crit->target);
     287                // LIB_DEBUG_PRINT_SAFE(" %p", crit->target);
    288288                assert( !crit->ready );
    289289                push( &crit->target->signal_stack, crit );
    290290        }
    291291
    292         LIB_DEBUG_PRINT_SAFE("\n");
     292        // LIB_DEBUG_PRINT_SAFE("\n");
    293293
    294294        //Release
     
    320320        for(int i = 0; i < count; i++) {
    321321                (&criteria[i]){ this->monitors[i], &waiter };
    322                 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     322                // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
    323323                push( &criteria[i].target->signal_stack, &criteria[i] );
    324324        }
     
    422422static inline void lock_all( spinlock ** locks, unsigned short count ) {
    423423        for( int i = 0; i < count; i++ ) {
    424                 lock( locks[i] DEBUG_CTX2 );
     424                lock_yield( locks[i] DEBUG_CTX2 );
    425425        }
    426426}
     
    429429        for( int i = 0; i < count; i++ ) {
    430430                spinlock * l = &source[i]->lock;
    431                 lock( l DEBUG_CTX2 );
     431                lock_yield( l DEBUG_CTX2 );
    432432                if(locks) locks[i] = l;
    433433        }
     
    472472        for(    int i = 0; i < count; i++ ) {
    473473
    474                 LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
     474                // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
    475475                if( &criteria[i] == target ) {
    476476                        criteria[i].ready = true;
    477                         LIB_DEBUG_PRINT_SAFE( "True\n" );
     477                        // LIB_DEBUG_PRINT_SAFE( "True\n" );
    478478                }
    479479
     
    481481        }
    482482
    483         LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );
     483        // LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );
    484484        return ready2run ? node->waiting_thread : NULL;
    485485}
     
    488488        thread_desc * thrd = this_thread;
    489489        if( !this->monitors ) {
    490                 LIB_DEBUG_PRINT_SAFE("Branding\n");
     490                // LIB_DEBUG_PRINT_SAFE("Branding\n");
    491491                assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors );
    492492                this->monitor_count = thrd->current_monitor_count;
Note: See TracChangeset for help on using the changeset viewer.