-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stabilize atomic_from_ptr
#115719
Merged
Merged
Stabilize atomic_from_ptr
#115719
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,7 +319,7 @@ impl AtomicBool { | |
/// # Examples | ||
/// | ||
/// ``` | ||
/// #![feature(atomic_from_ptr, pointer_is_aligned)] | ||
/// #![feature(pointer_is_aligned)] | ||
/// use std::sync::atomic::{self, AtomicBool}; | ||
/// use std::mem::align_of; | ||
/// | ||
|
@@ -346,13 +346,21 @@ impl AtomicBool { | |
/// | ||
/// # Safety | ||
/// | ||
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can be bigger than `align_of::<bool>()`). | ||
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can | ||
/// be bigger than `align_of::<bool>()`). | ||
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`. | ||
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`. | ||
/// * Non-atomic accesses to the value behind `ptr` must have a happens-before relationship | ||
/// with atomic accesses via the returned value (or vice-versa). | ||
/// * In other words, time periods where the value is accessed atomically may not overlap | ||
/// with periods where the value is accessed non-atomically. | ||
/// * This requirement is trivially satisfied if `ptr` is never used non-atomically for the | ||
/// duration of lifetime `'a`. Most use cases should be able to follow this guideline. | ||
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are done | ||
/// from the same thread. | ||
/// | ||
/// [valid]: crate::ptr#safety | ||
#[unstable(feature = "atomic_from_ptr", issue = "108652")] | ||
#[rustc_const_unstable(feature = "atomic_from_ptr", issue = "108652")] | ||
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")] | ||
#[rustc_const_unstable(feature = "const_atomic_from_ptr", issue = "108652")] | ||
pub const unsafe fn from_ptr<'a>(ptr: *mut bool) -> &'a AtomicBool { | ||
// SAFETY: guaranteed by the caller | ||
unsafe { &*ptr.cast() } | ||
|
@@ -1113,7 +1121,7 @@ impl<T> AtomicPtr<T> { | |
/// # Examples | ||
/// | ||
/// ``` | ||
/// #![feature(atomic_from_ptr, pointer_is_aligned)] | ||
/// #![feature(pointer_is_aligned)] | ||
/// use std::sync::atomic::{self, AtomicPtr}; | ||
/// use std::mem::align_of; | ||
/// | ||
|
@@ -1140,13 +1148,23 @@ impl<T> AtomicPtr<T> { | |
/// | ||
/// # Safety | ||
/// | ||
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this can be bigger than `align_of::<*mut T>()`). | ||
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this | ||
/// can be bigger than `align_of::<*mut T>()`). | ||
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`. | ||
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`. | ||
/// * Non-atomic accesses to the value behind `ptr` must have a happens-before relationship | ||
/// with atomic accesses via the returned value (or vice-versa). | ||
/// * In other words, time periods where the value is accessed atomically may not overlap | ||
/// with periods where the value is accessed non-atomically. | ||
/// * This requirement is trivially satisfied if `ptr` is never used non-atomically for the | ||
/// duration of lifetime `'a`. Most use cases should be able to follow this guideline. | ||
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are done | ||
/// from the same thread. | ||
/// * This method should not be used to create overlapping or mixed-size atomic accesses, as | ||
/// these are not supported by the memory model. | ||
/// | ||
/// [valid]: crate::ptr#safety | ||
#[unstable(feature = "atomic_from_ptr", issue = "108652")] | ||
#[rustc_const_unstable(feature = "atomic_from_ptr", issue = "108652")] | ||
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")] | ||
#[rustc_const_unstable(feature = "const_atomic_from_ptr", issue = "108652")] | ||
pub const unsafe fn from_ptr<'a>(ptr: *mut *mut T) -> &'a AtomicPtr<T> { | ||
// SAFETY: guaranteed by the caller | ||
unsafe { &*ptr.cast() } | ||
|
@@ -2083,7 +2101,7 @@ macro_rules! atomic_int { | |
/// # Examples | ||
/// | ||
/// ``` | ||
/// #![feature(atomic_from_ptr, pointer_is_aligned)] | ||
/// #![feature(pointer_is_aligned)] | ||
#[doc = concat!($extra_feature, "use std::sync::atomic::{self, ", stringify!($atomic_type), "};")] | ||
/// use std::mem::align_of; | ||
/// | ||
|
@@ -2111,14 +2129,25 @@ macro_rules! atomic_int { | |
/// | ||
/// # Safety | ||
/// | ||
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can be bigger than `align_of::<bool>()`). | ||
#[doc = concat!(" * `ptr` must be aligned to `align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this can be bigger than `align_of::<", stringify!($int_type), ">()`).")] | ||
#[doc = concat!(" * `ptr` must be aligned to \ | ||
`align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this \ | ||
can be bigger than `align_of::<", stringify!($int_type), ">()`).")] | ||
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`. | ||
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`. | ||
/// * Non-atomic accesses to the value behind `ptr` must have a happens-before | ||
/// relationship with atomic accesses via the returned value (or vice-versa). | ||
/// * In other words, time periods where the value is accessed atomically may not | ||
/// overlap with periods where the value is accessed non-atomically. | ||
/// * This requirement is trivially satisfied if `ptr` is never used non-atomically | ||
/// for the duration of lifetime `'a`. Most use cases should be able to follow | ||
/// this guideline. | ||
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are | ||
/// done from the same thread. | ||
/// * This method should not be used to create overlapping or mixed-size atomic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should say "must not". Looks like some methods got this note and some didn't; it should be present on all of these methods. |
||
/// accesses, as these are not supported by the memory model. | ||
/// | ||
/// [valid]: crate::ptr#safety | ||
#[unstable(feature = "atomic_from_ptr", issue = "108652")] | ||
#[rustc_const_unstable(feature = "atomic_from_ptr", issue = "108652")] | ||
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")] | ||
#[rustc_const_unstable(feature = "const_atomic_from_ptr", issue = "108652")] | ||
pub const unsafe fn from_ptr<'a>(ptr: *mut $int_type) -> &'a $atomic_type { | ||
// SAFETY: guaranteed by the caller | ||
unsafe { &*ptr.cast() } | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically I was looking for the overlapping atomics part here and I am not seeing it.