Changeset a5294af for libcfa


Ignore:
Timestamp:
May 25, 2023, 5:00:06 PM (11 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ast-experimental, master
Children:
a5aa5bf
Parents:
4246869 (diff), bccd70a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r4246869 ra5294af  
    6262    bool closed;                      // indicates channel close/open
    6363    #ifdef CHAN_STATS
    64     size_t blocks, operations;      // counts total ops and ops resulting in a blocked thd
     64    size_t p_blocks, p_ops, c_blocks, c_ops;      // counts total ops and ops resulting in a blocked thd
    6565    #endif
    6666};
     
    7575    closed = false;
    7676    #ifdef CHAN_STATS
    77     blocks = 0;
    78     operations = 0;
     77    p_blocks = 0;
     78    p_ops = 0;
     79    c_blocks = 0;
     80    c_ops = 0;
    7981    #endif
    8082}
     
    8385static inline void ^?{}( channel(T) &c ) with(c) {
    8486    #ifdef CHAN_STATS
    85     printf("Channel %p Blocks: %lu, Operations: %lu, %.2f%% of ops blocked\n", &c, blocks, operations, ((double)blocks)/operations * 100);
    86     #endif
    87     verifyf( cons`isEmpty && prods`isEmpty, "Attempted to delete channel with waiting threads (Deadlock).\n" );
     87    printf("Channel %p Blocks: %lu,\t\tOperations: %lu,\t%.2f%% of ops blocked\n", &c, p_blocks + c_blocks, p_ops + c_ops, ((double)p_blocks + c_blocks)/(p_ops + c_ops) * 100);
     88    printf("Channel %p Consumer Blocks: %lu,\tConsumer Ops: %lu,\t%.2f%% of Consumer ops blocked\n", &c, p_blocks, p_ops, ((double)p_blocks)/p_ops * 100);
     89    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);
     90    #endif
     91    verifyf( __handle_waituntil_OR( cons ) || __handle_waituntil_OR( prods ) || cons`isEmpty && prods`isEmpty,
     92        "Attempted to delete channel with waiting threads (Deadlock).\n" );
    8893    if ( size != 0 ) delete( buffer );
    8994}
     
    149154    lock( mutex_lock );
    150155    #ifdef CHAN_STATS
    151     operations++;
     156    p_ops++;
    152157    #endif
    153158
     
    187192
    188193    #ifdef CHAN_STATS
    189     if ( !closed ) operations++;
     194    if ( !closed ) p_ops++;
    190195    #endif
    191196
     
    208213    if ( count == size ) {
    209214        #ifdef CHAN_STATS
    210         blocks++;
     215        p_blocks++;
    211216        #endif
    212217
     
    237242    lock( mutex_lock );
    238243    #ifdef CHAN_STATS
    239     operations++;
     244    c_ops++;
    240245    #endif
    241246
     
    285290
    286291    #ifdef CHAN_STATS
    287     if ( !closed ) operations++;
     292    if ( !closed ) c_ops++;
    288293    #endif
    289294
     
    305310    if ( count == 0 ) {
    306311        #ifdef CHAN_STATS
    307         blocks++;
     312        c_blocks++;
    308313        #endif
    309314        // check for if woken due to close
     
    323328///////////////////////////////////////////////////////////////////////////////////////////
    324329static inline bool unregister_chan( channel(T) & chan, select_node & node ) with(chan) {
    325     // if ( !node`isListed && !node.park_counter ) return false; // handle special OR case C_TODO: try adding this back
     330    if ( !node`isListed && !node.park_counter ) return false; // handle special OR case
    326331    lock( mutex_lock );
    327332    if ( node`isListed ) { // op wasn't performed
    328         #ifdef CHAN_STATS
    329         operations--;
    330         #endif
    331333        remove( node );
    332334        unlock( mutex_lock );
     
    362364
    363365    #ifdef CHAN_STATS
    364     if ( !closed ) operations++;
     366    if ( !closed ) c_ops++;
    365367    #endif
    366368
     
    407409    if ( count == 0 ) {
    408410        #ifdef CHAN_STATS
    409         blocks++;
     411        c_blocks++;
    410412        #endif
    411413       
     
    451453
    452454    #ifdef CHAN_STATS
    453     if ( !closed ) operations++;
     455    if ( !closed ) p_ops++;
    454456    #endif
    455457
     
    498500    if ( count == size ) {
    499501        #ifdef CHAN_STATS
    500         blocks++;
     502        p_blocks++;
    501503        #endif
    502504
  • libcfa/src/concurrency/locks.hfa

    r4246869 ra5294af  
    176176static inline void ?{}(mcs_spin_node & this) { this.next = 0p; this.locked = true; }
    177177
    178 static inline mcs_spin_node * volatile & ?`next ( mcs_spin_node * node ) {
    179         return node->next;
    180 }
    181 
    182178struct mcs_spin_lock {
    183179        mcs_spin_queue queue;
     
    185181
    186182static inline void lock(mcs_spin_lock & l, mcs_spin_node & n) {
     183    n.locked = true;
    187184        mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST);
    188         n.locked = true;
    189         if(prev == 0p) return;
     185        if( prev == 0p ) return;
    190186        prev->next = &n;
    191         while(__atomic_load_n(&n.locked, __ATOMIC_RELAXED)) Pause();
     187        while( __atomic_load_n(&n.locked, __ATOMIC_RELAXED) ) Pause();
    192188}
    193189
     
    195191        mcs_spin_node * n_ptr = &n;
    196192        if (__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return;
    197         while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) {}
     193        while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) Pause();
    198194        n.next->locked = false;
    199195}
Note: See TracChangeset for help on using the changeset viewer.