Changes in / [2b78949:6ece306]


Ignore:
Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r2b78949 r6ece306  
    6262    bool closed;                      // indicates channel close/open
    6363    #ifdef CHAN_STATS
    64     size_t p_blocks, p_ops, c_blocks, c_ops;      // counts total ops and ops resulting in a blocked thd
     64    size_t blocks, operations;      // counts total ops and ops resulting in a blocked thd
    6565    #endif
    6666};
     
    7575    closed = false;
    7676    #ifdef CHAN_STATS
    77     p_blocks = 0;
    78     p_ops = 0;
    79     c_blocks = 0;
    80     c_ops = 0;
     77    blocks = 0;
     78    operations = 0;
    8179    #endif
    8280}
     
    8583static inline void ^?{}( channel(T) &c ) with(c) {
    8684    #ifdef CHAN_STATS
    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" );
     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" );
    9388    if ( size != 0 ) delete( buffer );
    9489}
     
    154149    lock( mutex_lock );
    155150    #ifdef CHAN_STATS
    156     p_ops++;
     151    operations++;
    157152    #endif
    158153
     
    192187
    193188    #ifdef CHAN_STATS
    194     if ( !closed ) p_ops++;
     189    if ( !closed ) operations++;
    195190    #endif
    196191
     
    213208    if ( count == size ) {
    214209        #ifdef CHAN_STATS
    215         p_blocks++;
     210        blocks++;
    216211        #endif
    217212
     
    242237    lock( mutex_lock );
    243238    #ifdef CHAN_STATS
    244     c_ops++;
     239    operations++;
    245240    #endif
    246241
     
    290285
    291286    #ifdef CHAN_STATS
    292     if ( !closed ) c_ops++;
     287    if ( !closed ) operations++;
    293288    #endif
    294289
     
    310305    if ( count == 0 ) {
    311306        #ifdef CHAN_STATS
    312         c_blocks++;
     307        blocks++;
    313308        #endif
    314309        // check for if woken due to close
     
    328323///////////////////////////////////////////////////////////////////////////////////////////
    329324static inline bool unregister_chan( channel(T) & chan, select_node & node ) with(chan) {
    330     if ( !node`isListed && !node.park_counter ) return false; // handle special OR case
     325    // if ( !node`isListed && !node.park_counter ) return false; // handle special OR case C_TODO: try adding this back
    331326    lock( mutex_lock );
    332327    if ( node`isListed ) { // op wasn't performed
     328        #ifdef CHAN_STATS
     329        operations--;
     330        #endif
    333331        remove( node );
    334332        unlock( mutex_lock );
     
    364362
    365363    #ifdef CHAN_STATS
    366     if ( !closed ) c_ops++;
     364    if ( !closed ) operations++;
    367365    #endif
    368366
     
    409407    if ( count == 0 ) {
    410408        #ifdef CHAN_STATS
    411         c_blocks++;
     409        blocks++;
    412410        #endif
    413411       
     
    453451
    454452    #ifdef CHAN_STATS
    455     if ( !closed ) p_ops++;
     453    if ( !closed ) operations++;
    456454    #endif
    457455
     
    500498    if ( count == size ) {
    501499        #ifdef CHAN_STATS
    502         p_blocks++;
     500        blocks++;
    503501        #endif
    504502
  • libcfa/src/concurrency/locks.hfa

    r2b78949 r6ece306  
    176176static inline void ?{}(mcs_spin_node & this) { this.next = 0p; this.locked = true; }
    177177
     178static inline mcs_spin_node * volatile & ?`next ( mcs_spin_node * node ) {
     179        return node->next;
     180}
     181
    178182struct mcs_spin_lock {
    179183        mcs_spin_queue queue;
     
    181185
    182186static inline void lock(mcs_spin_lock & l, mcs_spin_node & n) {
    183     n.locked = true;
    184187        mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST);
    185         if( prev == 0p ) return;
     188        n.locked = true;
     189        if(prev == 0p) return;
    186190        prev->next = &n;
    187         while( __atomic_load_n(&n.locked, __ATOMIC_RELAXED) ) Pause();
     191        while(__atomic_load_n(&n.locked, __ATOMIC_RELAXED)) Pause();
    188192}
    189193
     
    191195        mcs_spin_node * n_ptr = &n;
    192196        if (__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return;
    193         while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) Pause();
     197        while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) {}
    194198        n.next->locked = false;
    195199}
Note: See TracChangeset for help on using the changeset viewer.