Changeset e8b8e65
- Timestamp:
- Oct 31, 2022, 4:39:28 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 1dafdfc
- Parents:
- 7f3b5ce
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r7f3b5ce re8b8e65 111 111 concurrency/invoke.h \ 112 112 concurrency/future.hfa \ 113 concurrency/once.hfa \ 113 114 concurrency/kernel/fwd.hfa \ 114 115 concurrency/mutex_stmt.hfa -
libcfa/src/containers/lockfree.hfa
r7f3b5ce re8b8e65 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; } 144 145 145 146 static inline forall(| { T * volatile & ?`next ( T * ); }) … … 147 148 // Adds an element to the list 148 149 // Multi-Thread Safe, Lock-Free 149 T *push(poison_list(T) & this, T * elem) __attribute__((artificial));150 T *push(poison_list(T) & this, T * elem) {150 bool push(poison_list(T) & this, T * elem) __attribute__((artificial)); 151 bool push(poison_list(T) & this, T * elem) { 151 152 /* paranoid */ verify(0p == (elem`next)); 152 153 __atomic_store_n( &elem`next, (T*)1p, __ATOMIC_RELAXED ); … … 156 157 for() { 157 158 // check if it's poisoned 158 if(expected == 1p) return 0p;159 if(expected == 1p) return false; 159 160 160 161 // try to CAS the elem in … … 162 163 // We managed to exchange in, we are done 163 164 164 // We should never succeed the CAS if it's poisonned. 165 /* paranoid */ verify( expected != 1p ); 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 ); 166 168 167 169 // If we aren't the first, we need to tell the person before us 168 170 // No need to 169 171 elem`next = expected; 170 return expected;172 return true; 171 173 } 172 174 } … … 190 192 T * poison(poison_list(T) & this) { 191 193 T * ret = __atomic_exchange_n( &this.head, (T*)1p, __ATOMIC_SEQ_CST ); 192 /* paranoid */ verify ( ret != (T*)1p);194 /* paranoid */ verifyf( ret != (T*)1p, "Poison list %p poisoned more than once!", &this ); 193 195 return ret; 194 196 }
Note: See TracChangeset
for help on using the changeset viewer.