Changeset 280ec46 for libcfa


Ignore:
Timestamp:
Jun 13, 2020, 10:40:44 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c45d2fa
Parents:
ee06db5c
Message:

switch lock-free stack from CAAD to CAVD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/stackLockFree.hfa

    ree06db5c r280ec46  
    99// Created On       : Wed May 13 20:58:58 2020
    1010// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Mon May 18 13:30:08 2020
    12 // Update Count     : 55
     11// Last Modified On : Sat Jun 13 12:24:37 2020
     12// Update Count     : 62
    1313//
    1414
     
    1919forall( dtype T )
    2020union Link {
    21         struct {                                                                        // 32/64-bit x 2
    22                 T * top;                                                                // pointer to stack top
    23                 uintptr_t count;                                                // count each push
     21        struct {                                                                                        // 32/64-bit x 2
     22                T * top;                                                                                // pointer to stack top
     23                uintptr_t count;                                                                // count each push
    2424        };
    2525        #if __SIZEOF_INT128__ == 16
    26         __int128                                                                        // gcc, 128-bit integer
     26        __int128                                                                                        // gcc, 128-bit integer
    2727        #else
    28         uint64_t                                                                        // 64-bit integer
     28        uint64_t                                                                                        // 64-bit integer
    2929        #endif // __SIZEOF_INT128__ == 16
    3030        atom;
    3131}; // Link
    3232
    33 forall( otype T | { Link(T) * getNext( T * ); } ) {
     33forall( dtype T | sized(T) | { Link(T) * getNext( T * ); } ) {
    3434    struct StackLF {
    3535                Link(T) stack;
     
    4242
    4343                void push( StackLF(T) & this, T & n ) with(this) {
     44                        *getNext( &n ) = stack;                                         // atomic assignment unnecessary, or use CAA
    4445                        for () {                                                                        // busy wait
    45                                 *getNext( &n ) = stack;                                 // atomic assignment unnecessary, or use CAA
    4646                          if ( __atomic_compare_exchange_n( &stack.atom, &getNext( &n )->atom, (Link(T))@{ {&n, getNext( &n )->count + 1} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) break; // attempt to update top node
    4747                        } // for
     
    5050                T * pop( StackLF(T) & this ) with(this) {
    5151                        Link(T) t @= {};
     52                        t = stack;                                                                      // atomic assignment unnecessary, or use CAA
    5253                        for () {                                                                        // busy wait
    53                                 t = stack;                                                              // atomic assignment unnecessary, or use CAA
    5454                          if ( t.top == 0p ) return 0p;                         // empty stack ?
    5555                          if ( __atomic_compare_exchange_n( &stack.atom, &t.atom, (Link(T))@{ {getNext( t.top )->top, t.count} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) return t.top; // attempt to update top node
Note: See TracChangeset for help on using the changeset viewer.