Ignore:
Timestamp:
Apr 25, 2025, 7:39:09 AM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
65bd3c2
Parents:
b195498
Message:

change backquote call to regular call

File:
1 edited

Legend:

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

    rb195498 r6b33e89  
    99// Author           : Thierry Delisle
    1010// Created On       : Thd Feb 23 12:27:26 2017
    11 // Last Modified By : Kyoung Seo
    12 // Last Modified On : Thd Jan 16 12:59:00 2025
    13 // Update Count     : 73
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr 25 07:20:22 2025
     13// Update Count     : 80
    1414//
    1515
     
    7878        __spinlock_t * locks[count];                                                    /* We need to pass-in an array of locks to BlockInternal */
    7979
    80 #define monitor_save    save  ( monitors, count, locks, recursions, masks )
     80#define monitor_save save ( monitors, count, locks, recursions, masks )
    8181#define monitor_restore restore( monitors, count, locks, recursions, masks )
    8282
     
    9595        if ( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
    9696                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
    97         } else if ( !this->owner ) {
     97        } else if ( ! this->owner ) {
    9898                // No one has the monitor, just take it
    9999                __set_owner( this, thrd );
    100100
    101                 __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
     101                __cfaabi_dbg_print_safe( "Kernel : mon is free \n" );
    102102        } else if ( this->owner == thrd) {
    103103                // We already have the monitor, just note how many times we took it
    104104                this->recursion += 1;
    105105
    106                 __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
     106                __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" );
    107107        } else if ( is_accepted( this, group) ) {
    108108                // Some one was waiting for us, enter
     
    112112                reset_mask( this );
    113113
    114                 __cfaabi_dbg_print_safe( "Kernel :  mon accepts \n" );
     114                __cfaabi_dbg_print_safe( "Kernel : mon accepts \n" );
    115115        } else {
    116                 __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
     116                __cfaabi_dbg_print_safe( "Kernel : blocking \n" );
    117117
    118118                // Some one else has the monitor, wait in line for it
     
    124124                park();
    125125
    126                 __cfaabi_dbg_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                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     
    130130        }
    131131
    132         __cfaabi_dbg_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        /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     
    152152
    153153
    154         if ( !this->owner ) {
     154        if ( ! this->owner ) {
    155155                __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
    156156
     
    159159
    160160                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
    161                 /* paranoid */ verify( !is_thrd || thrd->state == Halted || thrd->state == Cancelled );
     161                /* paranoid */ verify( ! is_thrd || thrd->state == Halted || thrd->state == Cancelled );
    162162
    163163                unlock( this->lock );
    164164                return;
    165         } else if ( this->owner == thrd && !join) {
     165        } else if ( this->owner == thrd && ! join) {
    166166                // We already have the monitor... but where about to destroy it so the nesting will fail
    167167                // Abort!
     
    179179
    180180                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
    181                 /* paranoid */ verify( !is_thrd || thrd->state == Halted || thrd->state == Cancelled );
     181                /* paranoid */ verify( ! is_thrd || thrd->state == Halted || thrd->state == Cancelled );
    182182
    183183                unlock( this->lock );
     
    186186
    187187        // The monitor is busy, if this is a thread and the thread owns itself, it better be active
    188         /* paranoid */ verify( !is_thrd || this->owner != thrd || (thrd->state != Halted && thrd->state != Cancelled) );
     188        /* paranoid */ verify( ! is_thrd || this->owner != thrd || (thrd->state != Halted && thrd->state != Cancelled) );
    189189
    190190        __lock_size_t count = 1;
     
    192192        __monitor_group_t group = { &this, 1, func };
    193193        if ( is_accepted( this, group) ) {
    194                 __cfaabi_dbg_print_safe( "Kernel :  mon accepts dtor, block and signal it \n" );
     194                __cfaabi_dbg_print_safe( "Kernel : mon accepts dtor, block and signal it \n" );
    195195
    196196                // Wake the thread that is waiting for this
     
    220220                return;
    221221        } else {
    222                 __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
     222                __cfaabi_dbg_print_safe( "Kernel : blocking \n" );
    223223
    224224                wait_ctx( thrd, 0 )
     
    254254        // it means we don't need to do anything
    255255        if ( this->recursion != 0) {
    256                 __cfaabi_dbg_print_safe( "Kernel :  recursion still %d\n", this->recursion);
     256                __cfaabi_dbg_print_safe( "Kernel : recursion still %d\n", this->recursion);
    257257                unlock( this->lock );
    258258                return;
     
    264264        // Check the new owner is consistent with who we wake-up
    265265        // new_owner might be null even if someone owns the monitor when the owner is still waiting for another monitor
    266         /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
     266        /* paranoid */ verifyf( ! new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
    267267
    268268        // We can now let other threads in safely
     
    270270
    271271        //We need to wake-up the thread
    272         /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
     272        /* paranoid */ verifyf( ! new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
    273273        unpark( new_owner );
    274274}
     
    280280                        abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, active_thread(), this->owner);
    281281                }
    282                 if ( this->recursion != 1  && !join ) {
     282                if ( this->recursion != 1 && ! join ) {
    283283                        abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
    284284                }
     
    317317
    318318        // Unpark the next owner if needed
    319         /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
     319        /* paranoid */ verifyf( ! new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
    320320        /* paranoid */ verify( ! __preemption_enabled() );
    321321        /* paranoid */ verify( thrd->state == Halted );
     
    424424
    425425static void ?{}(__condition_criterion_t & this ) with( this ) {
    426         ready  = false;
     426        ready = false;
    427427        target = 0p;
    428         owner  = 0p;
    429         next  = 0p;
     428        owner = 0p;
     429        this.next = 0p;
    430430}
    431431
    432432static void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t & owner ) {
    433         this.ready  = false;
     433        this.ready = false;
    434434        this.target = target;
    435         this.owner  = &owner;
    436         this.next   = 0p;
     435        this.owner = &owner;
     436        this.next = 0p;
    437437}
    438438
     
    525525        for ( i; count ) {
    526526                __condition_criterion_t * crit = &node->criteria[i];
    527                 assert( !crit->ready );
     527                assert( ! crit->ready );
    528528                push( crit->target->signal_stack, crit );
    529529        }
     
    536536
    537537bool signal_block( condition & this ) libcfa_public {
    538         if ( !this.blocked.head ) { return false; }
     538        if ( ! this.blocked.head ) { return false; }
    539539
    540540        //Check that everything is as expected
     
    571571        // WE WOKE UP
    572572
    573         __cfaabi_dbg_print_buffer_local( "Kernel :   signal_block returned\n" );
     573        __cfaabi_dbg_print_buffer_local( "Kernel : signal_block returned\n" );
    574574
    575575        //We are back, restore the masks and recursions
     
    581581// Access the user_info of the thread waiting at the front of the queue
    582582uintptr_t front( condition & this ) libcfa_public {
    583         verifyf( !is_empty(this),
     583        verifyf( ! is_empty(this),
    584584                "Attempt to access user data on an empty condition.\n"
    585585                "Possible cause is not checking if the condition is empty before reading stored data."
     
    624624        {
    625625                // Check if the entry queue
    626                 thread$ * next; int index;
    627                 [next, index] = search_entry_queue( mask, monitors, count );
    628 
    629                 if ( next ) {
     626                thread$ * nxt; int index;
     627                [nxt, index] = search_entry_queue( mask, monitors, count );
     628
     629                if ( nxt ) {
    630630                        *mask.accepted = index;
    631631                        __acceptable_t& accepted = mask[index];
    632632                        if ( accepted.is_dtor ) {
    633633                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" );
    634                                 verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
     634                                verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." );
    635635
    636636                                monitor$ * mon2dtor = accepted[0];
     
    651651                                monitor_save;
    652652
    653                                 __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %"PRIdFAST16" monitors : ", count );
     653                                __cfaabi_dbg_print_buffer_local( "Kernel : baton of %"PRIdFAST16" monitors : ", count );
    654654                                #ifdef __CFA_DEBUG_PRINT__
    655655                                        for ( i; count ) {
     
    660660
    661661                                // Set the owners to be the next thread
    662                                 __set_owner( monitors, count, next );
     662                                __set_owner( monitors, count, nxt );
    663663
    664664                                // unlock all the monitors
     
    666666
    667667                                // unpark the thread we signalled
    668                                 unpark( next );
     668                                unpark( nxt );
    669669
    670670                                //Everything is ready to go to sleep
     
    741741        /* paranoid */ verify ( monitors[0]->lock.lock );
    742742        /* paranoid */ verifyf( monitors[0]->owner == active_thread(), "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), monitors[0]->owner, monitors[0]->recursion, monitors[0] );
    743         monitors[0]->owner        = owner;
    744         monitors[0]->recursion    = 1;
     743        monitors[0]->owner = owner;
     744        monitors[0]->recursion = 1;
    745745        for ( i; 1~count ) {
    746746                /* paranoid */ verify ( monitors[i]->lock.lock );
    747747                /* paranoid */ verifyf( monitors[i]->owner == active_thread(), "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), monitors[i]->owner, monitors[i]->recursion, monitors[i] );
    748                 monitors[i]->owner        = owner;
    749                 monitors[i]->recursion    = 0;
     748                monitors[i]->owner = owner;
     749                monitors[i]->recursion = 0;
    750750        }
    751751}
     
    765765static inline thread$ * next_thread( monitor$ * this ) {
    766766        //Check the signaller stack
    767         __cfaabi_dbg_print_safe( "Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     767        __cfaabi_dbg_print_safe( "Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top);
    768768        __condition_criterion_t * urgent = pop( this->signal_stack );
    769769        if ( urgent ) {
     
    771771                //regardless of if we are ready to baton pass,
    772772                //we need to set the monitor as in use
    773                 /* paranoid */ verifyf( !this->owner || active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
    774                 __set_owner( this,  urgent->owner->waiting_thread );
     773                /* paranoid */ verifyf( ! this->owner || active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     774                __set_owner( this, urgent->owner->waiting_thread );
    775775
    776776                return check_condition( urgent );
     
    780780        // Get the next thread in the entry_queue
    781781        thread$ * new_owner = pop_head( this->entry_queue );
    782         /* paranoid */ verifyf( !this->owner || active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
    783         /* paranoid */ verify( !new_owner || new_owner->user_link.next == 0p );
     782        /* paranoid */ verifyf( ! this->owner || active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     783        /* paranoid */ verify( ! new_owner || new_owner->user_link.next == 0p );
    784784        __set_owner( this, new_owner );
    785785
     
    792792
    793793        // Check if there are any acceptable functions
    794         if ( !it ) return false;
     794        if ( ! it ) return false;
    795795
    796796        // If this isn't the first monitor to test this, there is no reason to repeat the test.
     
    820820        for ( i; count ) {
    821821                (criteria[i]){ monitors[i], waiter };
    822                 __cfaabi_dbg_print_safe( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
     822                __cfaabi_dbg_print_safe( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] );
    823823                push( criteria[i].target->signal_stack, &criteria[i] );
    824824        }
     
    902902        }
    903903
    904         __cfaabi_dbg_print_safe( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? (thread*)node->waiting_thread : (thread*)0p );
     904        __cfaabi_dbg_print_safe( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? (thread*)node->waiting_thread : (thread*)0p );
    905905        return ready2run ? node->waiting_thread : 0p;
    906906}
     
    908908static inline void brand_condition( condition & this ) {
    909909        thread$ * thrd = active_thread();
    910         if ( !this.monitors ) {
     910        if ( ! this.monitors ) {
    911911                // __cfaabi_dbg_print_safe( "Branding\n" );
    912912                assertf( thrd->monitors.data != 0p, "No current monitor to brand condition %p", thrd->monitors.data );
     
    928928        for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
    929929                #if defined( __CFA_WITH_VERIFY__ )
    930                 thread$ * last = 0p;
     930                thread$ * prior = 0p;
    931931                #endif // __CFA_WITH_VERIFY__
    932932
     
    934934                        thread$ * curr = *thrd_it;
    935935
    936                         /* paranoid */ verifyf( !last || last->user_link.next == curr, "search not making progress, from %p (%p) to %p",
    937                                                                         last, last->user_link.next, curr );
    938                         /* paranoid */ verifyf( curr != last, "search not making progress, from %p to %p", last, curr );
     936                        /* paranoid */ verifyf( ! prior || prior->user_link.next == curr, "search not making progress, from %p (%p) to %p",
     937                                                                        prior, prior->user_link.next, curr );
     938                        /* paranoid */ verifyf( curr != prior, "search not making progress, from %p to %p", prior, curr );
    939939
    940940                        // For each thread in the entry-queue check for a match
     
    945945
    946946                        #if defined( __CFA_WITH_VERIFY__ )
    947                         last = curr;
     947                        prior = curr;
    948948                        #endif
    949949                } // for
     
    10011001        if ( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
    10021002                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
    1003         } else if ( !this->owner ) {
     1003        } else if ( ! this->owner ) {
    10041004                // No one has the monitor, just take it
    10051005                __set_owner( this, thrd );
    10061006
    1007                 __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
     1007                __cfaabi_dbg_print_safe( "Kernel : mon is free \n" );
    10081008        } else if ( this->owner == thrd) {
    10091009                // We already have the monitor, just note how many times we took it
    10101010                this->recursion += 1;
    10111011
    1012                 __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
     1012                __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" );
    10131013        } else {
    1014                 __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
     1014                __cfaabi_dbg_print_safe( "Kernel : blocking \n" );
    10151015
    10161016                // Some one else has the monitor, wait in line for it
     
    10221022                park();
    10231023
    1024                 __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     1024                __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);
    10251025
    10261026                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     
    10281028        }
    10291029
    1030         __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     1030        __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);
    10311031
    10321032        /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
Note: See TracChangeset for help on using the changeset viewer.