Skip to content

Commit 2415282

Browse files
Adding intradoc links for better clarity on memory model
1 parent a87f6ea commit 2415282

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

library/core/src/sync/atomic.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,9 @@ impl AtomicBool {
11131113

11141114
/// Returns a mutable pointer to the underlying [`bool`].
11151115
///
1116-
/// Doing non-atomic reads and writes on the resulting boolean can be a data race.
1116+
/// Note that doing non-atomic reads or writes on the resulting integer can be
1117+
/// Undefined Behavior due to a data race; see the [memory model section] for further information.
1118+
///
11171119
/// This method is mostly useful for FFI, where the function signature may use
11181120
/// `*mut bool` instead of `&AtomicBool`. All modifications of an atomic change the value
11191121
/// through a shared reference, and can do so safely as long as they use atomic operations.
@@ -1136,6 +1138,7 @@ impl AtomicBool {
11361138
/// }
11371139
/// # }
11381140
/// ```
1141+
/// [memory model section]: self#memory-model-for-atomic-accesses
11391142
#[inline]
11401143
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
11411144
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]
@@ -2303,7 +2306,9 @@ impl<T> AtomicPtr<T> {
23032306

23042307
/// Returns a mutable pointer to the underlying pointer.
23052308
///
2306-
/// Doing non-atomic reads and writes on the resulting pointer can be a data race.
2309+
/// Note that doing non-atomic reads or writes on the resulting integer can be
2310+
/// Undefined Behavior due to a data race; see the [memory model section] for further information.
2311+
///
23072312
/// This method is mostly useful for FFI, where the function signature may use
23082313
/// `*mut *mut T` instead of `&AtomicPtr<T>`. All modifications of an atomic change the value
23092314
/// through a shared reference, and can do so safely as long as they use atomic operations.
@@ -2325,6 +2330,7 @@ impl<T> AtomicPtr<T> {
23252330
/// my_atomic_op(atomic.as_ptr());
23262331
/// }
23272332
/// ```
2333+
/// [memory model section]: self#memory-model-for-atomic-accesses
23282334
#[inline]
23292335
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
23302336
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]
@@ -3390,7 +3396,9 @@ macro_rules! atomic_int {
33903396

33913397
/// Returns a mutable pointer to the underlying integer.
33923398
///
3393-
/// Doing non-atomic reads and writes on the resulting integer can be a data race.
3399+
/// Note that doing non-atomic reads or writes on the resulting integer can be
3400+
/// Undefined Behavior due to a data race; see the [memory model section] for further information.
3401+
///
33943402
/// This method is mostly useful for FFI, where the function signature may use
33953403
#[doc = concat!("`*mut ", stringify!($int_type), "` instead of `&", stringify!($atomic_type), "`.")]
33963404
/// All modifications of an atomic change the value through a shared reference, and can do so safely
@@ -3414,6 +3422,7 @@ macro_rules! atomic_int {
34143422
/// }
34153423
/// # }
34163424
/// ```
3425+
/// [memory model section]: self#memory-model-for-atomic-accesses
34173426
#[inline]
34183427
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
34193428
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]

0 commit comments

Comments
 (0)