File tree 1 file changed +3
-8
lines changed
1 file changed +3
-8
lines changed Original file line number Diff line number Diff line change @@ -539,20 +539,15 @@ impl AtomicBool {
539
539
// We can't use atomic_nand here because it can result in a bool with
540
540
// an invalid value. This happens because the atomic operation is done
541
541
// with an 8-bit integer internally, which would set the upper 7 bits.
542
- // So we just use fetch_xor or compare_exchange instead.
542
+ // So we just use fetch_xor or swap instead.
543
543
if val {
544
544
// !(x & true) == !x
545
545
// We must invert the bool.
546
546
self . fetch_xor ( true , order)
547
547
} else {
548
548
// !(x & false) == true
549
- // We must set the bool to true. Instead of delegating to swap or fetch_or, use
550
- // compare_exchange instead in order to avoid unnecessary writes to memory, which
551
- // might minimize cache-coherence traffic.
552
- match self . compare_exchange ( false , true , order, Ordering :: Relaxed ) {
553
- Ok ( _) => false ,
554
- Err ( _) => true ,
555
- }
549
+ // We must set the bool to true.
550
+ self . swap ( true , order)
556
551
}
557
552
}
558
553
You can’t perform that action at this time.
0 commit comments