- File:
-
- 1 edited
-
libcfa/src/containers/lockfree.hfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/lockfree.hfa
re8b8e65 r88ac843e 142 142 143 143 static inline void ?{}(poison_list(T) & this) { this.head = 0p; } 144 static inline bool is_poisoned( const poison_list(T) & this ) { return 1p == this.head; }145 144 146 145 static inline forall(| { T * volatile & ?`next ( T * ); }) … … 148 147 // Adds an element to the list 149 148 // Multi-Thread Safe, Lock-Free 150 boolpush(poison_list(T) & this, T * elem) __attribute__((artificial));151 boolpush(poison_list(T) & this, T * elem) {149 T * push(poison_list(T) & this, T * elem) __attribute__((artificial)); 150 T * push(poison_list(T) & this, T * elem) { 152 151 /* paranoid */ verify(0p == (elem`next)); 153 152 __atomic_store_n( &elem`next, (T*)1p, __ATOMIC_RELAXED ); … … 157 156 for() { 158 157 // check if it's poisoned 159 if(expected == 1p) return false;158 if(expected == 1p) return 0p; 160 159 161 160 // try to CAS the elem in … … 163 162 // We managed to exchange in, we are done 164 163 165 // We should never succeed the CAS if it's poisonned and the elem should be 1p. 166 /* paranoid */ verify( expected != 1p ); 167 /* paranoid */ verify( elem`next == 1p ); 164 // We should never succeed the CAS if it's poisonned. 165 /* paranoid */ verify( expected != 1p ); 168 166 169 167 // If we aren't the first, we need to tell the person before us 170 168 // No need to 171 169 elem`next = expected; 172 return true;170 return expected; 173 171 } 174 172 } … … 192 190 T * poison(poison_list(T) & this) { 193 191 T * ret = __atomic_exchange_n( &this.head, (T*)1p, __ATOMIC_SEQ_CST ); 194 /* paranoid */ verify f( ret != (T*)1p, "Poison list %p poisoned more than once!", &this);192 /* paranoid */ verify( ret != (T*)1p ); 195 193 return ret; 196 194 }
Note:
See TracChangeset
for help on using the changeset viewer.