pub fn fetch_xor(&self, val: bool, order: Ordering) -> bool {
unsafe { atomic_xor(self.v.get(), val as u8, order) != 0 }
}
+
+ /// Returns a mutable pointer to the underlying [`bool`].
+ ///
+ /// Doing non-atomic reads and writes on the resulting integer can be a data race.
+ /// This method is mostly useful for FFI, where the function signature may use
+ /// `*mut bool` instead of `&AtomicBool`.
+ ///
+ /// [`bool`]: ../../../std/primitive.bool.html
+ ///
+ /// # Examples
+ ///
+ /// ```ignore (extern-declaration)
+ /// # fn main() {
+ /// use std::sync::atomic::AtomicBool;
+ /// extern {
+ /// fn my_atomic_op(arg: *mut bool);
+ /// }
+ ///
+ /// let mut atomic = AtomicBool::new(true);
+ /// unsafe {
+ /// my_atomic_op(atomic.as_mut_ptr());
+ /// }
+ /// # }
+ /// ```
+ #[inline]
+ #[unstable(feature = "atomic_mut_ptr",
+ reason = "recently added",
+ issue = "0")]
+ pub fn as_mut_ptr(&self) -> *mut bool {
+ self.v.get() as *mut bool
+ }
}
#[cfg(any(bootstrap, target_has_atomic_load_store = "ptr"))]
}
}
+ doc_comment! {
+ concat!("Returns a mutable pointer to the underlying integer.
+
+Doing non-atomic reads and writes on the resulting integer can be a data race.
+This method is mostly useful for FFI, where the function signature may use
+`*mut ", stringify!($int_type), "` instead of `&", stringify!($atomic_type), "`.
+
+# Examples
+
+```ignore (extern-declaration)
+# fn main() {
+", $extra_feature, "use std::sync::atomic::", stringify!($atomic_type), ";
+
+extern {
+ fn my_atomic_op(arg: *mut ", stringify!($int_type), ");
+}
+
+let mut atomic = ", stringify!($atomic_type), "::new(1);
+unsafe {
+ my_atomic_op(atomic.as_mut_ptr());
+}
+# }
+```"),
+ #[inline]
+ #[unstable(feature = "atomic_mut_ptr",
+ reason = "recently added",
+ issue = "0")]
+ pub fn as_mut_ptr(&self) -> *mut $int_type {
+ self.v.get()
+ }
+ }
}
}
}