Ignore:
Timestamp:
Mar 29, 2026, 9:52:51 PM (5 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
e6e250d
Parents:
00675ed4
Message:

2nd attempt at harmonizing isOp functions, e.g., isEmpty, to C/C++ form empty

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/channel.hfa

    r00675ed4 r81ab5eb  
    117117                printf("Channel %p Producer Blocks: %lu,\tProducer Ops: %lu,\t%.2f%% of Producer ops blocked\n", &c, c_blocks, c_ops, ((double)c_blocks)/c_ops * 100);
    118118            #endif
    119                 verifyf( __handle_waituntil_OR( cons ) || __handle_waituntil_OR( prods ) || isEmpty( cons ) && isEmpty( prods ),
     119                verifyf( __handle_waituntil_OR( cons ) || __handle_waituntil_OR( prods ) || empty( cons ) && empty( prods ),
    120120                                 "Attempted to delete channel with waiting threads (Deadlock).\n" );
    121121                if ( size != 0 ) delete( buffer );
     
    123123        size_t get_count( channel(T) & chan ) with(chan) { return __atomic_load_n( &count, __ATOMIC_RELAXED ); }
    124124        size_t get_size( channel(T) & chan ) with(chan) { return __atomic_load_n( &size, __ATOMIC_RELAXED ); }
    125         bool has_waiters( channel(T) & chan ) with(chan) { return ! isEmpty( cons ) || ! isEmpty( prods ); }
    126         bool has_waiting_consumers( channel(T) & chan ) with(chan) { return ! isEmpty( cons ); }
    127         bool has_waiting_producers( channel(T) & chan ) with(chan) { return ! isEmpty( prods ); }
     125        bool has_waiters( channel(T) & chan ) with(chan) { return ! empty( cons ) || ! empty( prods ); }
     126        bool has_waiting_consumers( channel(T) & chan ) with(chan) { return ! empty( cons ); }
     127        bool has_waiting_producers( channel(T) & chan ) with(chan) { return ! empty( prods ); }
    128128
    129129        // closes the channel and notifies all blocked threads
     
    164164        void flush( channel(T) & chan, T elem ) with(chan) {
    165165                lock( mutex_lock );
    166                 while ( count == 0 && ! isEmpty( cons ) ) {
     166                while ( count == 0 && ! empty( cons ) ) {
    167167                        __cons_handoff( chan, elem );
    168168                }
     
    186186
    187187          ConsEmpty:
    188                 if ( ! isEmpty( cons ) ) {
     188                if ( ! empty( cons ) ) {
    189189                        if ( ! __handle_waituntil_OR( cons ) ) break ConsEmpty;
    190190                        __cons_handoff( chan, elem );
     
    233233                // buffer count must be zero if cons are blocked (also handles zero-size case)
    234234          ConsEmpty:
    235                 if ( ! isEmpty( cons ) ) {
     235                if ( ! empty( cons ) ) {
    236236                        if ( ! __handle_waituntil_OR( cons ) ) break ConsEmpty;
    237237                        __cons_handoff( chan, elem );
     
    261261                count -= 1;
    262262                front = (front + 1) % size;
    263                 if (count == size - 1 && ! isEmpty( prods ) ) {
     263                if (count == size - 1 && ! empty( prods ) ) {
    264264                        if ( ! __handle_waituntil_OR( prods ) ) return;
    265265                        __buf_insert( chan, *(T *)first( prods ).extra );  // do waiting producer work
     
    276276
    277277          ZeroSize:
    278                 if ( size == 0 && ! isEmpty( prods ) ) {
     278                if ( size == 0 && ! empty( prods ) ) {
    279279                        if ( ! __handle_waituntil_OR( prods ) ) break ZeroSize;
    280280                        __prods_handoff( chan, retval );
     
    332332                // have to check for the zero size channel case
    333333          ZeroSize:
    334                 if ( size == 0 && ! isEmpty( prods ) ) {
     334                if ( size == 0 && ! empty( prods ) ) {
    335335                        if ( ! __handle_waituntil_OR( prods ) ) break ZeroSize;
    336336                        __prods_handoff( chan, retval );
     
    384384        // special case of __handle_waituntil_OR, that does some work to avoid starvation/deadlock case
    385385        bool __handle_pending( dlist( select_node ) & queue, select_node & mine ) {
    386             while ( ! isEmpty( queue ) ) {
     386            while ( ! empty( queue ) ) {
    387387                // if node not a special OR case or if we win the special OR case race break
    388388                if ( ! first( queue ).clause_status || first( queue ).park_counter || __pending_set_other( first( queue ), mine, ((unsigned long int)(&(first( queue )))) ) )
     
    421421            if ( ! node.park_counter ) {
    422422                // are we special case OR and front of cons is also special case OR
    423                 if ( ! unlikely(closed) && ! isEmpty( prods ) && first( prods ).clause_status && ! first( prods ).park_counter ) {
     423                if ( ! unlikely(closed) && ! empty( prods ) && first( prods ).clause_status && ! first( prods ).park_counter ) {
    424424                    if ( ! __make_select_node_pending( node ) ) {
    425425                        unlock( mutex_lock );
     
    437437                }
    438438                // check if we can complete operation. If so race to establish winner in special OR case
    439                 if ( count != 0 || ! isEmpty( prods ) || unlikely(closed) ) {
     439                if ( count != 0 || ! empty( prods ) || unlikely(closed) ) {
    440440                    if ( ! __make_select_node_available( node ) ) { // we didn't win the race so give up on registering
    441441                        unlock( mutex_lock );
     
    453453            // have to check for the zero size channel case
    454454            ZeroSize:
    455                 if ( size == 0 && ! isEmpty( prods ) ) {
     455                if ( size == 0 && ! empty( prods ) ) {
    456456                        if ( ! __handle_waituntil_OR( prods ) ) break ZeroSize;
    457457                        __prods_handoff( *chan, *ret );
     
    522522            if ( ! node.park_counter ) {
    523523                // are we special case OR and front of cons is also special case OR
    524                 if ( ! unlikely(closed) && ! isEmpty( cons ) && first( cons ).clause_status && ! first( cons ).park_counter ) {
     524                if ( ! unlikely(closed) && ! empty( cons ) && first( cons ).clause_status && ! first( cons ).park_counter ) {
    525525                    if ( ! __make_select_node_pending( node ) ) {
    526526                        unlock( mutex_lock );
     
    537537                        }
    538538                        // check if we can complete operation. If so race to establish winner in special OR case
    539                         if ( count != size || ! isEmpty( cons ) || unlikely(closed) ) {
     539                        if ( count != size || ! empty( cons ) || unlikely(closed) ) {
    540540                                if ( ! __make_select_node_available( node ) ) { // we didn't win the race so give up on registering
    541541                                        unlock( mutex_lock );
     
    554554                // handle blocked consumer case via handoff (buffer is implicitly empty)
    555555    ConsEmpty:
    556                 if ( ! isEmpty( cons ) ) {
     556                if ( ! empty( cons ) ) {
    557557                        if ( ! __handle_waituntil_OR( cons ) ) break ConsEmpty;
    558558                        __cons_handoff( *chan, elem );
Note: See TracChangeset for help on using the changeset viewer.