Changeset 9d47c1f for libcfa


Ignore:
Timestamp:
Sep 6, 2023, 3:44:03 PM (8 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
cb0bcf1
Parents:
92d8cda
Message:

changes over all usages of uC++ collections to use dlist instead

Location:
libcfa/src/concurrency
Files:
3 edited

Legend:

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

    r92d8cda r9d47c1f  
    594594                lock( queue.lock __cfaabi_dbg_ctx2 );
    595595                {
    596                         was_empty = empty(queue.queue);
     596                        was_empty = queue.queue`isEmpty;
    597597
    598598                        // Add our request to the list
    599                         add( queue.queue, item );
     599                        insert_last( queue.queue, item );
    600600
    601601                        // Mark as pending
     
    632632        // notify the arbiter that new allocations are available
    633633        static void __ioarbiter_notify( io_arbiter$ & this, io_context$ * ctx ) {
    634                 /* paranoid */ verify( !empty(this.pending.queue) );
     634                /* paranoid */ verify( !this.pending.queue`isEmpty );
    635635                /* paranoid */ verify( __preemption_enabled() );
    636636
     
    642642                        // as long as there are pending allocations try to satisfy them
    643643                        // for simplicity do it in FIFO order
    644                         while( !empty(this.pending.queue) ) {
     644                        while( !this.pending.queue`isEmpty ) {
    645645                                // get first pending allocs
    646646                                __u32 have = ctx->sq.free_ring.tail - ctx->sq.free_ring.head;
    647                                 __pending_alloc & pa = (__pending_alloc&)head( this.pending.queue );
     647                                __pending_alloc & pa = (__pending_alloc&)(this.pending.queue`first);
    648648
    649649                                // check if we have enough to satisfy the request
     
    651651
    652652                                // if there are enough allocations it means we can drop the request
    653                                 drop( this.pending.queue );
     653                                try_pop_front( this.pending.queue );
    654654
    655655                                /* paranoid */__attribute__((unused)) bool ret =
     
    727727                        // pop each operation one at a time.
    728728                        // There is no wait morphing because of the io sq ring
    729                         while( !empty(ctx.ext_sq.queue) ) {
     729                        while( !ctx.ext_sq.queue`isEmpty ) {
    730730                                // drop the element from the queue
    731                                 __external_io & ei = (__external_io&)drop( ctx.ext_sq.queue );
     731                                __external_io & ei = (__external_io&)try_pop_front( ctx.ext_sq.queue );
    732732
    733733                                // submit it
  • libcfa/src/concurrency/io/types.hfa

    r92d8cda r9d47c1f  
    2424
    2525#include "bits/locks.hfa"
    26 #include "bits/queue.hfa"
    2726#include "iofwd.hfa"
    2827#include "kernel/fwd.hfa"
    2928
    3029#if defined(CFA_HAVE_LINUX_IO_URING_H)
    31         #include "bits/sequence.hfa"
    3230        #include "monitor.hfa"
    3331
     
    120118        struct __outstanding_io {
    121119                // intrusive link fields
    122                 inline Colable;
     120                inline dlink(__outstanding_io);
    123121
    124122                // primitive on which to block until the io is processed
    125123                oneshot waitctx;
    126124        };
    127         static inline __outstanding_io *& Next( __outstanding_io * n ) { return (__outstanding_io *)Next( (Colable *)n ); }
     125    P9_EMBEDDED( __outstanding_io, dlink(__outstanding_io) )
    128126
    129127        // queue of operations that are outstanding
     
    134132
    135133                // the actual queue
    136                 Queue(__outstanding_io) queue;
     134                dlist(__outstanding_io) queue;
    137135
    138136                // volatile used to avoid the need for taking the lock if it's empty
  • libcfa/src/concurrency/pthread.cfa

    r92d8cda r9d47c1f  
    2020#include <errno.h>
    2121#include "locks.hfa"
    22 #include "bits/stack.hfa"
    23 #include "bits/sequence.hfa"
    24 
    2522
    2623#define check_nonnull(x) asm("": "+rm"(x)); if( x == 0p ) return EINVAL;
     
    3431
    3532struct pthread_values{
    36         inline Seqable;
     33        inline dlink(pthread_values);
    3734        void * value;
    3835        bool in_use;
    3936};
    40 
    41 static inline {
    42         pthread_values *& Back( pthread_values * n ) {
    43                 return (pthread_values *)Back( (Seqable *)n );
    44         }
    45 
    46         pthread_values *& Next( pthread_values * n ) {
    47                 return (pthread_values *)Next( (Colable *)n );
    48         }
    49 }
     37P9_EMBEDDED( pthread_values, dlink(pthread_values) )
    5038
    5139struct pthread_keys {
    5240        bool in_use;
    5341        void (* destructor)( void * );
    54         Sequence(pthread_values) threads;
     42    dlist( pthread_values ) threads;
    5543};
    5644
     
    7866
    7967struct Pthread_kernel_threads{
    80         inline Colable;
     68        inline dlink(Pthread_kernel_threads);
    8169        processor p;
    8270};
    83 
    84 Pthread_kernel_threads *& Next( Pthread_kernel_threads * n ) {
    85         return (Pthread_kernel_threads *)Next( (Colable *)n );
    86 }
    87 
    88 static Stack(Pthread_kernel_threads) cfa_pthreads_kernel_threads;
     71P9_EMBEDDED( Pthread_kernel_threads, dlink(Pthread_kernel_threads) )
     72
     73static dlist(Pthread_kernel_threads) cfa_pthreads_kernel_threads;
    8974static bool cfa_pthreads_kernel_threads_zero = false;   // set to zero ?
    9075static int cfa_pthreads_no_kernel_threads = 1;  // number of kernel threads
     
    231216                                        key = &cfa_pthread_keys[i];
    232217                                        value->in_use = false;
    233                                         remove(key->threads, *value);
     218                                        remove(*value);
     219
    234220                                        // if  a  key  value  has  a  non-NULL  destructor pointer,  and  the  thread  has  a  non-NULL  value associated with that key,
    235221                                        // the value of the key is set to NULL, and then the function pointed to is called with the previously associated value as its sole argument.
     
    551537
    552538                // Remove key from all threads with a value.
    553                 pthread_values& p;
    554                 Sequence(pthread_values)& head = cfa_pthread_keys[key].threads;
    555                 for ( SeqIter(pthread_values) iter = { head }; iter | p; ) {
    556                         remove(head, p);
    557                         p.in_use = false;
    558                 }
     539               
     540                // Sequence(pthread_values)& head = cfa_pthread_keys[key].threads;
     541                // for ( SeqIter(pthread_values) iter = { head }; iter | p; ) {
     542                //      remove(head, p);
     543                //      p.in_use = false;
     544                // }
     545        pthread_values * p = &try_pop_front( cfa_pthread_keys[key].threads );
     546        for ( ; p; ) {           
     547            p->in_use = false;
     548            p = &try_pop_front( cfa_pthread_keys[key].threads );
     549        }
    559550                unlock(key_lock);
    560551                return 0;
     
    585576                if ( ! entry.in_use ) {
    586577                        entry.in_use = true;
    587                         add(cfa_pthread_keys[key].threads, entry);
     578                        insert_last(cfa_pthread_keys[key].threads, entry);
    588579                } // if
    589580                entry.value = (void *)value;
     
    612603        //######################### Parallelism #########################
    613604        void pthread_delete_kernel_threads_() __THROW { // see uMain::~uMain
    614                 Pthread_kernel_threads& p;
    615                 for ( StackIter(Pthread_kernel_threads) iter = {cfa_pthreads_kernel_threads}; iter | p; ) {
    616                         delete(&p);
     605                Pthread_kernel_threads * p = &try_pop_front(cfa_pthreads_kernel_threads);
     606                for ( ; p; ) {
     607            delete(p);
     608                        p = &try_pop_front(cfa_pthreads_kernel_threads);
    617609                } // for
    618610        } // pthread_delete_kernel_threads_
     
    631623                lock( concurrency_lock );
    632624                for ( ; new_level > cfa_pthreads_no_kernel_threads; cfa_pthreads_no_kernel_threads += 1 ) { // add processors ?
    633                         push(cfa_pthreads_kernel_threads, *new() );
     625                        insert_last(cfa_pthreads_kernel_threads, *new() );
    634626                } // for
    635627                for ( ; new_level < cfa_pthreads_no_kernel_threads; cfa_pthreads_no_kernel_threads -= 1 ) { // remove processors ?
    636                         delete(&pop(cfa_pthreads_kernel_threads));
     628                        delete(&try_pop_front(cfa_pthreads_kernel_threads));
    637629                } // for
    638630                unlock( concurrency_lock );
Note: See TracChangeset for help on using the changeset viewer.