Changeset 0f89d4f for libcfa/src/containers
- Timestamp:
- Jun 19, 2020, 5:30:16 PM (4 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/stackLockFree.hfa
r68f36f4 r0f89d4f 31 31 }; // Link 32 32 33 forall( otype T | { Link(T) * getNext( T * ); } ) {33 forall( otype T | { Link(T) * ?`next( T * ); } ) { 34 34 struct StackLF { 35 35 Link(T) stack; … … 43 43 void push( StackLF(T) & this, T & n ) with(this) { 44 44 for () { // busy wait 45 * getNext( &n )= stack; // atomic assignment unnecessary, or use CAA46 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 node45 *( &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 47 47 } // for 48 48 } // push … … 53 53 t = stack; // atomic assignment unnecessary, or use CAA 54 54 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 node55 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 56 56 } // for 57 57 } // pop … … 62 62 T * next = link->top; 63 63 if( next == node ) { 64 link->top = getNext( node )->top;64 link->top = ( node )`next->top; 65 65 return true; 66 66 } 67 67 if( next == 0p ) return false; 68 link = getNext(next);68 link = (next)`next; 69 69 } 70 70 }
Note: See TracChangeset
for help on using the changeset viewer.