Skip to content

Commit 5840184

Browse files
committed
Update docs for AtomicU8/I8.
Clarify that they always have the same alignment as u8/i8, (unlike other atomic types). Clarify in from_ptr that alignment is never an issue because of this.
1 parent 263861f commit 5840184

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

core/src/sync/atomic.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,10 +2091,10 @@ impl<T> From<*mut T> for AtomicPtr<T> {
20912091
}
20922092

20932093
#[allow(unused_macros)] // This macro ends up being unused on some architectures.
2094-
macro_rules! if_not_8_bit {
2095-
(u8, $($tt:tt)*) => { "" };
2096-
(i8, $($tt:tt)*) => { "" };
2097-
($_:ident, $($tt:tt)*) => { $($tt)* };
2094+
macro_rules! if_8_bit {
2095+
(u8, $( yes = [$($yes:tt)*], )? $( no = [$($no:tt)*], )? ) => { concat!("", $($($yes)*)?) };
2096+
(i8, $( yes = [$($yes:tt)*], )? $( no = [$($no:tt)*], )? ) => { concat!("", $($($yes)*)?) };
2097+
($_:ident, $( yes = [$($yes:tt)*], )? $( no = [$($no:tt)*], )? ) => { concat!("", $($($no)*)?) };
20982098
}
20992099

21002100
#[cfg(target_has_atomic_load_store)]
@@ -2116,18 +2116,24 @@ macro_rules! atomic_int {
21162116
$int_type:ident $atomic_type:ident) => {
21172117
/// An integer type which can be safely shared between threads.
21182118
///
2119-
/// This type has the same size and bit validity as the underlying
2120-
/// integer type, [`
2119+
/// This type has the same
2120+
#[doc = if_8_bit!(
2121+
$int_type,
2122+
yes = ["size, alignment, and bit validity"],
2123+
no = ["size and bit validity"],
2124+
)]
2125+
/// as the underlying integer type, [`
21212126
#[doc = $s_int_type]
21222127
/// `].
2123-
#[doc = if_not_8_bit! {
2128+
#[doc = if_8_bit! {
21242129
$int_type,
2125-
concat!(
2130+
no = [
21262131
"However, the alignment of this type is always equal to its ",
21272132
"size, even on targets where [`", $s_int_type, "`] has a ",
21282133
"lesser alignment."
2129-
)
2134+
],
21302135
}]
2136+
///
21312137
/// For more about the differences between atomic types and
21322138
/// non-atomic types as well as information about the portability of
21332139
/// this type, please see the [module-level documentation].
@@ -2220,9 +2226,19 @@ macro_rules! atomic_int {
22202226
///
22212227
/// # Safety
22222228
///
2223-
#[doc = concat!(" * `ptr` must be aligned to \
2224-
`align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this \
2225-
can be bigger than `align_of::<", stringify!($int_type), ">()`).")]
2229+
/// * `ptr` must be aligned to
2230+
#[doc = concat!(" `align_of::<", stringify!($atomic_type), ">()`")]
2231+
#[doc = if_8_bit!{
2232+
$int_type,
2233+
yes = [
2234+
" (note that this is always true, since `align_of::<",
2235+
stringify!($atomic_type), ">() == 1`)."
2236+
],
2237+
no = [
2238+
" (note that on some platforms this can be bigger than `align_of::<",
2239+
stringify!($int_type), ">()`)."
2240+
],
2241+
}]
22262242
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
22272243
/// * You must adhere to the [Memory model for atomic accesses]. In particular, it is not
22282244
/// allowed to mix atomic and non-atomic accesses, or atomic accesses of different sizes,
@@ -2261,12 +2277,12 @@ macro_rules! atomic_int {
22612277

22622278
#[doc = concat!("Get atomic access to a `&mut ", stringify!($int_type), "`.")]
22632279
///
2264-
#[doc = if_not_8_bit! {
2280+
#[doc = if_8_bit! {
22652281
$int_type,
2266-
concat!(
2282+
no = [
22672283
"**Note:** This function is only available on targets where `",
22682284
stringify!($int_type), "` has an alignment of ", $align, " bytes."
2269-
)
2285+
],
22702286
}]
22712287
///
22722288
/// # Examples

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy