@@ -854,6 +854,41 @@ 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
+ /// use std::sync::atomic::{AtomicBool, Ordering};
876
+ ///
877
+ /// let foo = AtomicBool::new(true);
878
+ /// assert_eq!(foo.fetch_not(Ordering::SeqCst), true);
879
+ /// assert_eq!(foo.load(Ordering::SeqCst), false);
880
+ ///
881
+ /// let foo = AtomicBool::new(false);
882
+ /// assert_eq!(foo.fetch_not(Ordering::SeqCst), false);
883
+ /// assert_eq!(foo.load(Ordering::SeqCst), true);
884
+ /// ```
885
+ #[ inline]
886
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
887
+ #[ cfg( target_has_atomic = "8" ) ]
888
+ pub fn fetch_not ( & self , order : Ordering ) -> bool {
889
+ self . fetch_xor ( true , order)
890
+ }
891
+
857
892
/// Returns a mutable pointer to the underlying [`bool`].
858
893
///
859
894
/// Doing non-atomic reads and writes on the resulting integer can be a data race.
0 commit comments