Skip to content

Commit 756f224

Browse files
committed
Adding links for Atomics docs #29377
1 parent 7846dbe commit 756f224

File tree

1 file changed

+66
-38
lines changed

1 file changed

+66
-38
lines changed

src/libcore/sync/atomic.rs

+66-38
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,37 @@
1515
//! types.
1616
//!
1717
//! This module defines atomic versions of a select number of primitive
18-
//! types, including `AtomicBool`, `AtomicIsize`, and `AtomicUsize`.
18+
//! types, including [`AtomicBool`], [`AtomicIsize`], and [`AtomicUsize`].
1919
//! Atomic types present operations that, when used correctly, synchronize
2020
//! updates between threads.
2121
//!
22-
//! Each method takes an `Ordering` which represents the strength of
22+
//! [`AtomicBool`]: struct.AtomicBool.html
23+
//! [`AtomicIsize`]: struct.AtomicIsize.html
24+
//! [`AtomicUsize`]: struct.AtomicUsize.html
25+
//!
26+
//! Each method takes an [`Ordering`] which represents the strength of
2327
//! the memory barrier for that operation. These orderings are the
2428
//! same as [LLVM atomic orderings][1]. For more information see the [nomicon][2].
2529
//!
30+
//! [`Ordering`]: enum.Ordering.html
31+
//!
2632
//! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations
2733
//! [2]: ../../../nomicon/atomics.html
2834
//!
29-
//! Atomic variables are safe to share between threads (they implement `Sync`)
35+
//! Atomic variables are safe to share between threads (they implement [`Sync`])
3036
//! but they do not themselves provide the mechanism for sharing and follow the
3137
//! [threading model](../../../std/thread/index.html#the-threading-model) of rust.
32-
//! The most common way to share an atomic variable is to put it into an `Arc` (an
38+
//! The most common way to share an atomic variable is to put it into an [`Arc`][arc] (an
3339
//! atomically-reference-counted shared pointer).
3440
//!
41+
//! [`Sync`]: ../../marker/trait.Sync.html
42+
//! [arc]: ../struct.Arc.html
43+
//!
3544
//! Most atomic types may be stored in static variables, initialized using
36-
//! the provided static initializers like `ATOMIC_BOOL_INIT`. Atomic statics
45+
//! the provided static initializers like [`ATOMIC_BOOL_INIT`]. Atomic statics
3746
//! are often used for lazy global initialization.
3847
//!
48+
//! [`ATOMIC_BOOL_INIT`]: constant.ATOMIC_BOOL_INIT.html
3949
//!
4050
//! # Examples
4151
//!
@@ -149,21 +159,26 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
149159
#[derive(Copy, Clone, Debug)]
150160
pub enum Ordering {
151161
/// No ordering constraints, only atomic operations. Corresponds to LLVM's
152-
/// `Monotonic` ordering.
162+
/// [`Monotonic`][1] ordering.
163+
/// [1]: http://llvm.org/docs/Atomics.html#monotonic
153164
#[stable(feature = "rust1", since = "1.0.0")]
154165
Relaxed,
155166
/// When coupled with a store, all previous writes become visible
156-
/// to the other threads that perform a load with `Acquire` ordering
167+
/// to the other threads that perform a load with [`Acquire`][1] ordering
157168
/// on the same value.
169+
/// [1]: http://llvm.org/docs/Atomics.html#acquire
158170
#[stable(feature = "rust1", since = "1.0.0")]
159171
Release,
160172
/// When coupled with a load, all subsequent loads will see data
161-
/// written before a store with `Release` ordering on the same value
173+
/// written before a store with [`Release`][1] ordering on the same value
162174
/// in other threads.
175+
/// [1]: http://llvm.org/docs/Atomics.html#release
163176
#[stable(feature = "rust1", since = "1.0.0")]
164177
Acquire,
165-
/// When coupled with a load, uses `Acquire` ordering, and with a store
166-
/// `Release` ordering.
178+
/// When coupled with a load, uses [`Acquire`][1] ordering, and with a store
179+
/// [`Release`][2] ordering.
180+
/// [1]: http://llvm.org/docs/Atomics.html#acquire
181+
/// [2]: http://llvm.org/docs/Atomics.html#release
167182
#[stable(feature = "rust1", since = "1.0.0")]
168183
AcqRel,
169184
/// Like `AcqRel` with the additional guarantee that all threads see all
@@ -176,7 +191,8 @@ pub enum Ordering {
176191
__Nonexhaustive,
177192
}
178193

179-
/// An `AtomicBool` initialized to `false`.
194+
/// An [`AtomicBool`] initialized to `false`.
195+
/// [`AtomicBool`]: struct.AtomicBool.html
180196
#[cfg(target_has_atomic = "8")]
181197
#[stable(feature = "rust1", since = "1.0.0")]
182198
pub const ATOMIC_BOOL_INIT: AtomicBool = AtomicBool::new(false);
@@ -241,7 +257,7 @@ impl AtomicBool {
241257

242258
/// Loads a value from the bool.
243259
///
244-
/// `load` takes an [`Ordering`] argument which describes the memory ordering
260+
/// `load()` takes an [`Ordering`] argument which describes the memory ordering
245261
/// of this operation.
246262
///
247263
/// # Panics
@@ -250,7 +266,7 @@ impl AtomicBool {
250266
///
251267
/// [`Ordering`]: enum.Ordering.html
252268
/// [`Release`]: enum.Ordering.html#variant.Release
253-
/// [`AcqRel`]: enum.Ordering.html#variant.Release
269+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
254270
///
255271
/// # Examples
256272
///
@@ -269,7 +285,7 @@ impl AtomicBool {
269285

270286
/// Stores a value into the bool.
271287
///
272-
/// `store` takes an [`Ordering`] argument which describes the memory ordering
288+
/// `store()` takes an [`Ordering`] argument which describes the memory ordering
273289
/// of this operation.
274290
///
275291
/// [`Ordering`]: enum.Ordering.html
@@ -287,7 +303,10 @@ impl AtomicBool {
287303
///
288304
/// # Panics
289305
///
290-
/// Panics if `order` is `Acquire` or `AcqRel`.
306+
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
307+
///
308+
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
309+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
291310
#[inline]
292311
#[stable(feature = "rust1", since = "1.0.0")]
293312
pub fn store(&self, val: bool, order: Ordering) {
@@ -298,7 +317,7 @@ impl AtomicBool {
298317

299318
/// Stores a value into the bool, returning the old value.
300319
///
301-
/// `swap` takes an [`Ordering`] argument which describes the memory ordering
320+
/// `swap()` takes an [`Ordering`] argument which describes the memory ordering
302321
/// of this operation.
303322
///
304323
/// [`Ordering`]: enum.Ordering.html
@@ -324,7 +343,7 @@ impl AtomicBool {
324343
/// The return value is always the previous value. If it is equal to `current`, then the value
325344
/// was updated.
326345
///
327-
/// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory
346+
/// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory
328347
/// ordering of this operation.
329348
///
330349
/// [`Ordering`]: enum.Ordering.html
@@ -356,7 +375,7 @@ impl AtomicBool {
356375
/// The return value is a result indicating whether the new value was written and containing
357376
/// the previous value. On success this value is guaranteed to be equal to `current`.
358377
///
359-
/// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
378+
/// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory
360379
/// ordering of this operation. The first describes the required ordering if the
361380
/// operation succeeds while the second describes the required ordering when the
362381
/// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and must
@@ -404,17 +423,18 @@ impl AtomicBool {
404423

405424
/// Stores a value into the `bool` if the current value is the same as the `current` value.
406425
///
407-
/// Unlike `compare_exchange`, this function is allowed to spuriously fail even when the
426+
/// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even when the
408427
/// comparison succeeds, which can result in more efficient code on some platforms. The
409428
/// return value is a result indicating whether the new value was written and containing the
410429
/// previous value.
411430
///
412-
/// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
431+
/// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory
413432
/// ordering of this operation. The first describes the required ordering if the operation
414433
/// succeeds while the second describes the required ordering when the operation fails. The
415434
/// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or
416435
/// weaker than the success ordering.
417436
///
437+
/// [`compare_exchange()`]: #method.compare_exchange
418438
/// [`Ordering`]: enum.Ordering.html
419439
/// [`Release`]: enum.Ordering.html#variant.Release
420440
/// [`AcqRel`]: enum.Ordering.html#variant.Release
@@ -645,7 +665,7 @@ impl<T> AtomicPtr<T> {
645665

646666
/// Loads a value from the pointer.
647667
///
648-
/// `load` takes an [`Ordering`] argument which describes the memory ordering
668+
/// `load()` takes an [`Ordering`] argument which describes the memory ordering
649669
/// of this operation.
650670
///
651671
/// # Panics
@@ -674,7 +694,7 @@ impl<T> AtomicPtr<T> {
674694

675695
/// Stores a value into the pointer.
676696
///
677-
/// `store` takes an [`Ordering`] argument which describes the memory ordering
697+
/// `store()` takes an [`Ordering`] argument which describes the memory ordering
678698
/// of this operation.
679699
///
680700
/// [`Ordering`]: enum.Ordering.html
@@ -694,7 +714,11 @@ impl<T> AtomicPtr<T> {
694714
///
695715
/// # Panics
696716
///
697-
/// Panics if `order` is `Acquire` or `AcqRel`.
717+
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
718+
///
719+
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
720+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
721+
///
698722
#[inline]
699723
#[stable(feature = "rust1", since = "1.0.0")]
700724
pub fn store(&self, ptr: *mut T, order: Ordering) {
@@ -705,7 +729,7 @@ impl<T> AtomicPtr<T> {
705729

706730
/// Stores a value into the pointer, returning the old value.
707731
///
708-
/// `swap` takes an [`Ordering`] argument which describes the memory ordering
732+
/// `swap()` takes an [`Ordering`] argument which describes the memory ordering
709733
/// of this operation.
710734
///
711735
/// [`Ordering`]: enum.Ordering.html
@@ -733,7 +757,7 @@ impl<T> AtomicPtr<T> {
733757
/// The return value is always the previous value. If it is equal to `current`, then the value
734758
/// was updated.
735759
///
736-
/// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory
760+
/// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory
737761
/// ordering of this operation.
738762
///
739763
/// [`Ordering`]: enum.Ordering.html
@@ -765,7 +789,7 @@ impl<T> AtomicPtr<T> {
765789
/// The return value is a result indicating whether the new value was written and containing
766790
/// the previous value. On success this value is guaranteed to be equal to `current`.
767791
///
768-
/// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
792+
/// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory
769793
/// ordering of this operation. The first describes the required ordering if
770794
/// the operation succeeds while the second describes the required ordering when
771795
/// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`]
@@ -812,18 +836,18 @@ impl<T> AtomicPtr<T> {
812836

813837
/// Stores a value into the pointer if the current value is the same as the `current` value.
814838
///
815-
/// Unlike [`compare_exchange`], this function is allowed to spuriously fail even when the
839+
/// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even when the
816840
/// comparison succeeds, which can result in more efficient code on some platforms. The
817841
/// return value is a result indicating whether the new value was written and containing the
818842
/// previous value.
819843
///
820-
/// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
844+
/// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory
821845
/// ordering of this operation. The first describes the required ordering if the operation
822846
/// succeeds while the second describes the required ordering when the operation fails. The
823847
/// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or
824848
/// weaker than the success ordering.
825849
///
826-
/// [`compare_exchange`]: #method.compare_exchange
850+
/// [`compare_exchange()`]: #method.compare_exchange
827851
/// [`Ordering`]: enum.Ordering.html
828852
/// [`Release`]: enum.Ordering.html#variant.Release
829853
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
@@ -962,7 +986,7 @@ macro_rules! atomic_int {
962986

963987
/// Loads a value from the atomic integer.
964988
///
965-
/// `load` takes an [`Ordering`] argument which describes the memory ordering of this
989+
/// `load()` takes an [`Ordering`] argument which describes the memory ordering of this
966990
/// operation.
967991
///
968992
/// # Panics
@@ -990,7 +1014,7 @@ macro_rules! atomic_int {
9901014

9911015
/// Stores a value into the atomic integer.
9921016
///
993-
/// `store` takes an [`Ordering`] argument which describes the memory ordering of this
1017+
/// `store()` takes an [`Ordering`] argument which describes the memory ordering of this
9941018
/// operation.
9951019
///
9961020
/// [`Ordering`]: enum.Ordering.html
@@ -1008,7 +1032,11 @@ macro_rules! atomic_int {
10081032
///
10091033
/// # Panics
10101034
///
1011-
/// Panics if `order` is `Acquire` or `AcqRel`.
1035+
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
1036+
///
1037+
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
1038+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
1039+
///
10121040
#[inline]
10131041
#[$stable]
10141042
pub fn store(&self, val: $int_type, order: Ordering) {
@@ -1017,7 +1045,7 @@ macro_rules! atomic_int {
10171045

10181046
/// Stores a value into the atomic integer, returning the old value.
10191047
///
1020-
/// `swap` takes an [`Ordering`] argument which describes the memory ordering of this
1048+
/// `swap()` takes an [`Ordering`] argument which describes the memory ordering of this
10211049
/// operation.
10221050
///
10231051
/// [`Ordering`]: enum.Ordering.html
@@ -1043,7 +1071,7 @@ macro_rules! atomic_int {
10431071
/// The return value is always the previous value. If it is equal to `current`, then the
10441072
/// value was updated.
10451073
///
1046-
/// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory
1074+
/// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory
10471075
/// ordering of this operation.
10481076
///
10491077
/// [`Ordering`]: enum.Ordering.html
@@ -1083,7 +1111,7 @@ macro_rules! atomic_int {
10831111
/// containing the previous value. On success this value is guaranteed to be equal to
10841112
/// `current`.
10851113
///
1086-
/// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
1114+
/// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory
10871115
/// ordering of this operation. The first describes the required ordering if
10881116
/// the operation succeeds while the second describes the required ordering when
10891117
/// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and
@@ -1125,18 +1153,18 @@ macro_rules! atomic_int {
11251153
/// Stores a value into the atomic integer if the current value is the same as the
11261154
/// `current` value.
11271155
///
1128-
/// Unlike [`compare_exchange`], this function is allowed to spuriously fail even
1156+
/// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even
11291157
/// when the comparison succeeds, which can result in more efficient code on some
11301158
/// platforms. The return value is a result indicating whether the new value was
11311159
/// written and containing the previous value.
11321160
///
1133-
/// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
1161+
/// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory
11341162
/// ordering of this operation. The first describes the required ordering if the
11351163
/// operation succeeds while the second describes the required ordering when the
11361164
/// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and
11371165
/// must be equivalent or weaker than the success ordering.
11381166
///
1139-
/// [`compare_exchange`]: #method.compare_exchange
1167+
/// [`compare_exchange()`]: #method.compare_exchange
11401168
/// [`Ordering`]: enum.Ordering.html
11411169
/// [`Release`]: enum.Ordering.html#variant.Release
11421170
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel

0 commit comments

Comments
 (0)