@@ -854,6 +854,42 @@ impl AtomicBool {
854
854
unsafe { atomic_xor ( self . v . get ( ) , val as u8 , order) != 0 }
855
855
}
856
856
857
+ /// Logical "not" with a boolean value.
858
+ ///
859
+ /// Performs a logical "not" operation on the current value, and sets
860
+ /// the new value to the result.
861
+ ///
862
+ /// Returns the previous value.
863
+ ///
864
+ /// `fetch_not` takes an [`Ordering`] argument which describes the memory ordering
865
+ /// of this operation. All ordering modes are possible. Note that using
866
+ /// [`Acquire`] makes the store part of this operation [`Relaxed`], and
867
+ /// using [`Release`] makes the load part [`Relaxed`].
868
+ ///
869
+ /// **Note:** This method is only available on platforms that support atomic
870
+ /// operations on `u8`.
871
+ ///
872
+ /// # Examples
873
+ ///
874
+ /// ```
875
+ /// #![feature(atomic_bool_fetch_not)]
876
+ /// use std::sync::atomic::{AtomicBool, Ordering};
877
+ ///
878
+ /// let foo = AtomicBool::new(true);
879
+ /// assert_eq!(foo.fetch_not(Ordering::SeqCst), true);
880
+ /// assert_eq!(foo.load(Ordering::SeqCst), false);
881
+ ///
882
+ /// let foo = AtomicBool::new(false);
883
+ /// assert_eq!(foo.fetch_not(Ordering::SeqCst), false);
884
+ /// assert_eq!(foo.load(Ordering::SeqCst), true);
885
+ /// ```
886
+ #[ inline]
887
+ #[ unstable( feature = "atomic_bool_fetch_not" , issue = "98485" ) ]
888
+ #[ cfg( target_has_atomic = "8" ) ]
889
+ pub fn fetch_not ( & self , order : Ordering ) -> bool {
890
+ self . fetch_xor ( true , order)
891
+ }
892
+
857
893
/// Returns a mutable pointer to the underlying [`bool`].
858
894
///
859
895
/// Doing non-atomic reads and writes on the resulting integer can be a data race.
0 commit comments