Ignore:
Timestamp:
Jun 19, 2020, 5:30:16 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b232745
Parents:
68f36f4
Message:

Modified StackLF to use `next instead of getNext

File:
1 edited

Legend:

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

    r68f36f4 r0f89d4f  
    3131}; // Link
    3232
    33 forall( otype T | { Link(T) * getNext( T * ); } ) {
     33forall( otype T | { Link(T) * ?`next( T * ); } ) {
    3434        struct StackLF {
    3535                Link(T) stack;
     
    4343                void push( StackLF(T) & this, T & n ) with(this) {
    4444                        for () {                                                                        // busy wait
    45                                 *getNext( &n ) = stack;                                 // atomic assignment unnecessary, or use CAA
    46                           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
     45                                *( &n )`next = stack;                                   // atomic assignment unnecessary, or use CAA
     46                          if ( __atomic_compare_exchange_n( &stack.atom, &( &n )`next->atom, (Link(T))@{ {&n, ( &n )`next->count + 1} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) break; // attempt to update top node
    4747                        } // for
    4848                } // push
     
    5353                                t = stack;                                                              // atomic assignment unnecessary, or use CAA
    5454                          if ( t.top == 0p ) return 0p;                         // empty stack ?
    55                           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
     55                          if ( __atomic_compare_exchange_n( &stack.atom, &t.atom, (Link(T))@{ {( t.top )`next->top, t.count} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) return t.top; // attempt to update top node
    5656                        } // for
    5757                } // pop
     
    6262                                T * next = link->top;
    6363                                if( next == node ) {
    64                                         link->top = getNext( node )->top;
     64                                        link->top = ( node )`next->top;
    6565                                        return true;
    6666                                }
    6767                                if( next == 0p ) return false;
    68                                 link = getNext(next);
     68                                link = (next)`next;
    6969                        }
    7070                }
Note: See TracChangeset for help on using the changeset viewer.