Changeset 5024df4 for libcfa


Ignore:
Timestamp:
May 25, 2022, 3:41:58 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
c715e5f
Parents:
b035046
Message:

Changed ready-queue to atomically read/write timestamps, no effect on x64. + whitespace

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/cluster.cfa

    rb035046 r5024df4  
    484484        /* paranoid */ verify( &mock_head(this)->link.ts   == &this.anchor.ts   );
    485485        /* paranoid */ verify( mock_head(this)->link.next == 0p );
    486         /* paranoid */ verify( mock_head(this)->link.ts   == MAX  );
     486        /* paranoid */ verify( mock_head(this)->link.ts   == MAX );
    487487        /* paranoid */ verify( mock_head(this) == this.prev );
    488488        /* paranoid */ verify( __alignof__(__intrusive_lane_t) == 128 );
  • libcfa/src/concurrency/ready_subqueue.hfa

    rb035046 r5024df4  
    3232        /* paranoid */ verify( this.lock );
    3333        /* paranoid */ verify( node->link.next == 0p );
    34         /* paranoid */ verify( node->link.ts  == MAX  );
     34        /* paranoid */ verify( __atomic_load_n(&node->link.ts, __ATOMIC_RELAXED) == MAX  );
    3535        /* paranoid */ verify( this.prev->link.next == 0p );
    36         /* paranoid */ verify( this.prev->link.ts   == MAX  );
     36        /* paranoid */ verify( __atomic_load_n(&this.prev->link.ts, __ATOMIC_RELAXED)   == MAX  );
    3737        if( this.anchor.next == 0p ) {
    3838                /* paranoid */ verify( this.anchor.next == 0p );
    39                 /* paranoid */ verify( this.anchor.ts  == MAX );
    40                 /* paranoid */ verify( this.anchor.ts  != 0  );
     39                /* paranoid */ verify( __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED) == MAX );
     40                /* paranoid */ verify( __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED) != 0  );
    4141                /* paranoid */ verify( this.prev == mock_head( this ) );
    4242        } else {
    4343                /* paranoid */ verify( this.anchor.next != 0p );
    44                 /* paranoid */ verify( this.anchor.ts  != MAX );
    45                 /* paranoid */ verify( this.anchor.ts  != 0  );
     44                /* paranoid */ verify( __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED) != MAX );
     45                /* paranoid */ verify( __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED) != 0  );
    4646                /* paranoid */ verify( this.prev != mock_head( this ) );
    4747        }
     
    6262        /* paranoid */ verify( this.lock );
    6363        /* paranoid */ verify( this.anchor.next != 0p );
    64         /* paranoid */ verify( this.anchor.ts  != MAX );
    65         /* paranoid */ verify( this.anchor.ts   != 0  );
     64        /* paranoid */ verify( __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED) != MAX );
     65        /* paranoid */ verify( __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED) != 0   );
    6666
    6767        // Get the relevant nodes locally
    6868        thread$ * node = this.anchor.next;
    6969        this.anchor.next = node->link.next;
    70         this.anchor.ts   = node->link.ts;
     70        __atomic_store_n(&this.anchor.ts, __atomic_load_n(&node->link.ts, __ATOMIC_RELAXED), __ATOMIC_RELAXED);
    7171        bool is_empty = this.anchor.next == 0p;
    7272        node->link.next = 0p;
    73         node->link.ts   = ULLONG_MAX;
     73        __atomic_store_n(&node->link.ts, ULLONG_MAX, __ATOMIC_RELAXED);
    7474        #if !defined(__CFA_NO_STATISTICS__)
    7575                this.cnt--;
     
    7979        if(is_empty) this.prev = mock_head( this );
    8080
     81        unsigned long long ats = __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED);
    8182        /* paranoid */ verify( node->link.next == 0p );
    82         /* paranoid */ verify( node->link.ts   == MAX );
    83         /* paranoid */ verify( node->link.ts   != 0  );
    84         /* paranoid */ verify( this.anchor.ts  != 0 );
    85         /* paranoid */ verify( (this.anchor.ts == MAX) == is_empty );
    86         return [node, this.anchor.ts];
     83        /* paranoid */ verify( __atomic_load_n(&node->link.ts , __ATOMIC_RELAXED) == MAX );
     84        /* paranoid */ verify( __atomic_load_n(&node->link.ts , __ATOMIC_RELAXED) != 0   );
     85        /* paranoid */ verify( ats != 0 );
     86        /* paranoid */ verify( (ats == MAX) == is_empty );
     87        return [node, ats];
    8788}
    8889
     
    9697        // Cannot verify 'emptiness' here since it may not be locked
    9798        /* paranoid */ verify(this.anchor.ts != 0);
    98         return this.anchor.ts;
     99        /* paranoid */ static_assert(__atomic_always_lock_free(sizeof(this.anchor.ts), &this.anchor.ts));
     100        return __atomic_load_n(&this.anchor.ts, __ATOMIC_RELAXED);
    99101}
Note: See TracChangeset for help on using the changeset viewer.