Skip to content
/ rust Public
forked from rust-lang/rust

Commit 0d715bc

Browse files
authored
Rollup merge of rust-lang#150094 - atomic-ptr-null, r=workingjubilee
`c_variadic`: provide our own `va_arg` implementation for more targets Implementation for rust-lang#150733. I marked this function as `#[must_use]` even though the other `AtomicPtr` constructors aren't. It's unclear to me why they aren't already marked as such, I opened a zulip thread asking about it: [#t-libs > Is there a reason AtomicPtr constructors aren't #&rust-lang#91;must_use&rust-lang#93;?](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Is.20there.20a.20reason.20AtomicPtr.20constructors.20aren't.20.23.5Bmust_use.5D.3F/with/566624261).
2 parents 89e6d46 + fff9c62 commit 0d715bc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

library/core/src/sync/atomic.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,24 @@ impl<T> AtomicPtr<T> {
15501550
unsafe { &*ptr.cast() }
15511551
}
15521552

1553+
/// Creates a new `AtomicPtr` initialized with a null pointer.
1554+
///
1555+
/// # Examples
1556+
///
1557+
/// ```
1558+
/// #![feature(atomic_ptr_null)]
1559+
/// use std::sync::atomic::{AtomicPtr, Ordering};
1560+
///
1561+
/// let atomic_ptr = AtomicPtr::<()>::null();
1562+
/// assert!(atomic_ptr.load(Ordering::Relaxed).is_null());
1563+
/// ```
1564+
#[inline]
1565+
#[must_use]
1566+
#[unstable(feature = "atomic_ptr_null", issue = "150733")]
1567+
pub const fn null() -> AtomicPtr<T> {
1568+
AtomicPtr::new(crate::ptr::null_mut())
1569+
}
1570+
15531571
/// Returns a mutable reference to the underlying pointer.
15541572
///
15551573
/// This is safe because the mutable reference guarantees that no other threads are

0 commit comments

Comments
 (0)