Changeset 88b49bb


Ignore:
Timestamp:
May 24, 2023, 11:46:05 AM (18 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
6c15d66
Parents:
5ece8ce
Message:

added a small waituntil optimization and added some improvements to statistic collection

File:
1 edited

Legend:

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

    r5ece8ce r88b49bb  
    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
Note: See TracChangeset for help on using the changeset viewer.