File tree Expand file tree Collapse file tree 1 file changed +3
-8
lines changed Expand file tree Collapse file tree 1 file changed +3
-8
lines changed Original file line number Diff line number Diff line change @@ -539,20 +539,15 @@ impl AtomicBool {
539539 // We can't use atomic_nand here because it can result in a bool with
540540 // an invalid value. This happens because the atomic operation is done
541541 // 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.
543543 if val {
544544 // !(x & true) == !x
545545 // We must invert the bool.
546546 self . fetch_xor ( true , order)
547547 } else {
548548 // !(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)
556551 }
557552 }
558553
You can’t perform that action at this time.
0 commit comments