15
15
//! types.
16
16
//!
17
17
//! 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`] .
19
19
//! Atomic types present operations that, when used correctly, synchronize
20
20
//! updates between threads.
21
21
//!
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
23
27
//! the memory barrier for that operation. These orderings are the
24
28
//! same as [LLVM atomic orderings][1]. For more information see the [nomicon][2].
25
29
//!
30
+ //! [`Ordering`]: enum.Ordering.html
31
+ //!
26
32
//! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations
27
33
//! [2]: ../../../nomicon/atomics.html
28
34
//!
29
- //! Atomic variables are safe to share between threads (they implement `Sync`)
35
+ //! Atomic variables are safe to share between threads (they implement [ `Sync`] )
30
36
//! but they do not themselves provide the mechanism for sharing and follow the
31
37
//! [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
33
39
//! atomically-reference-counted shared pointer).
34
40
//!
41
+ //! [`Sync`]: ../../marker/trait.Sync.html
42
+ //! [arc]: ../struct.Arc.html
43
+ //!
35
44
//! 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
37
46
//! are often used for lazy global initialization.
38
47
//!
48
+ //! [`ATOMIC_BOOL_INIT`]: constant.ATOMIC_BOOL_INIT.html
39
49
//!
40
50
//! # Examples
41
51
//!
@@ -149,21 +159,26 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
149
159
#[ derive( Copy , Clone , Debug ) ]
150
160
pub enum Ordering {
151
161
/// 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
153
164
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
154
165
Relaxed ,
155
166
/// 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
157
168
/// on the same value.
169
+ /// [1]: http://llvm.org/docs/Atomics.html#acquire
158
170
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
159
171
Release ,
160
172
/// 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
162
174
/// in other threads.
175
+ /// [1]: http://llvm.org/docs/Atomics.html#release
163
176
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
164
177
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
167
182
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
168
183
AcqRel ,
169
184
/// Like `AcqRel` with the additional guarantee that all threads see all
@@ -176,7 +191,8 @@ pub enum Ordering {
176
191
__Nonexhaustive,
177
192
}
178
193
179
- /// An `AtomicBool` initialized to `false`.
194
+ /// An [`AtomicBool`] initialized to `false`.
195
+ /// [`AtomicBool`]: struct.AtomicBool.html
180
196
#[ cfg( target_has_atomic = "8" ) ]
181
197
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
182
198
pub const ATOMIC_BOOL_INIT : AtomicBool = AtomicBool :: new ( false ) ;
@@ -241,7 +257,7 @@ impl AtomicBool {
241
257
242
258
/// Loads a value from the bool.
243
259
///
244
- /// `load` takes an [`Ordering`] argument which describes the memory ordering
260
+ /// `load() ` takes an [`Ordering`] argument which describes the memory ordering
245
261
/// of this operation.
246
262
///
247
263
/// # Panics
@@ -250,7 +266,7 @@ impl AtomicBool {
250
266
///
251
267
/// [`Ordering`]: enum.Ordering.html
252
268
/// [`Release`]: enum.Ordering.html#variant.Release
253
- /// [`AcqRel`]: enum.Ordering.html#variant.Release
269
+ /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
254
270
///
255
271
/// # Examples
256
272
///
@@ -269,7 +285,7 @@ impl AtomicBool {
269
285
270
286
/// Stores a value into the bool.
271
287
///
272
- /// `store` takes an [`Ordering`] argument which describes the memory ordering
288
+ /// `store() ` takes an [`Ordering`] argument which describes the memory ordering
273
289
/// of this operation.
274
290
///
275
291
/// [`Ordering`]: enum.Ordering.html
@@ -287,7 +303,10 @@ impl AtomicBool {
287
303
///
288
304
/// # Panics
289
305
///
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
291
310
#[ inline]
292
311
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
293
312
pub fn store ( & self , val : bool , order : Ordering ) {
@@ -298,7 +317,7 @@ impl AtomicBool {
298
317
299
318
/// Stores a value into the bool, returning the old value.
300
319
///
301
- /// `swap` takes an [`Ordering`] argument which describes the memory ordering
320
+ /// `swap() ` takes an [`Ordering`] argument which describes the memory ordering
302
321
/// of this operation.
303
322
///
304
323
/// [`Ordering`]: enum.Ordering.html
@@ -324,7 +343,7 @@ impl AtomicBool {
324
343
/// The return value is always the previous value. If it is equal to `current`, then the value
325
344
/// was updated.
326
345
///
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
328
347
/// ordering of this operation.
329
348
///
330
349
/// [`Ordering`]: enum.Ordering.html
@@ -356,7 +375,7 @@ impl AtomicBool {
356
375
/// The return value is a result indicating whether the new value was written and containing
357
376
/// the previous value. On success this value is guaranteed to be equal to `current`.
358
377
///
359
- /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
378
+ /// `compare_exchange() ` takes two [`Ordering`] arguments to describe the memory
360
379
/// ordering of this operation. The first describes the required ordering if the
361
380
/// operation succeeds while the second describes the required ordering when the
362
381
/// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and must
@@ -404,17 +423,18 @@ impl AtomicBool {
404
423
405
424
/// Stores a value into the `bool` if the current value is the same as the `current` value.
406
425
///
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
408
427
/// comparison succeeds, which can result in more efficient code on some platforms. The
409
428
/// return value is a result indicating whether the new value was written and containing the
410
429
/// previous value.
411
430
///
412
- /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
431
+ /// `compare_exchange_weak() ` takes two [`Ordering`] arguments to describe the memory
413
432
/// ordering of this operation. The first describes the required ordering if the operation
414
433
/// succeeds while the second describes the required ordering when the operation fails. The
415
434
/// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or
416
435
/// weaker than the success ordering.
417
436
///
437
+ /// [`compare_exchange()`]: #method.compare_exchange
418
438
/// [`Ordering`]: enum.Ordering.html
419
439
/// [`Release`]: enum.Ordering.html#variant.Release
420
440
/// [`AcqRel`]: enum.Ordering.html#variant.Release
@@ -645,7 +665,7 @@ impl<T> AtomicPtr<T> {
645
665
646
666
/// Loads a value from the pointer.
647
667
///
648
- /// `load` takes an [`Ordering`] argument which describes the memory ordering
668
+ /// `load() ` takes an [`Ordering`] argument which describes the memory ordering
649
669
/// of this operation.
650
670
///
651
671
/// # Panics
@@ -674,7 +694,7 @@ impl<T> AtomicPtr<T> {
674
694
675
695
/// Stores a value into the pointer.
676
696
///
677
- /// `store` takes an [`Ordering`] argument which describes the memory ordering
697
+ /// `store() ` takes an [`Ordering`] argument which describes the memory ordering
678
698
/// of this operation.
679
699
///
680
700
/// [`Ordering`]: enum.Ordering.html
@@ -694,7 +714,11 @@ impl<T> AtomicPtr<T> {
694
714
///
695
715
/// # Panics
696
716
///
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
+ ///
698
722
#[ inline]
699
723
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
700
724
pub fn store ( & self , ptr : * mut T , order : Ordering ) {
@@ -705,7 +729,7 @@ impl<T> AtomicPtr<T> {
705
729
706
730
/// Stores a value into the pointer, returning the old value.
707
731
///
708
- /// `swap` takes an [`Ordering`] argument which describes the memory ordering
732
+ /// `swap() ` takes an [`Ordering`] argument which describes the memory ordering
709
733
/// of this operation.
710
734
///
711
735
/// [`Ordering`]: enum.Ordering.html
@@ -733,7 +757,7 @@ impl<T> AtomicPtr<T> {
733
757
/// The return value is always the previous value. If it is equal to `current`, then the value
734
758
/// was updated.
735
759
///
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
737
761
/// ordering of this operation.
738
762
///
739
763
/// [`Ordering`]: enum.Ordering.html
@@ -765,7 +789,7 @@ impl<T> AtomicPtr<T> {
765
789
/// The return value is a result indicating whether the new value was written and containing
766
790
/// the previous value. On success this value is guaranteed to be equal to `current`.
767
791
///
768
- /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
792
+ /// `compare_exchange() ` takes two [`Ordering`] arguments to describe the memory
769
793
/// ordering of this operation. The first describes the required ordering if
770
794
/// the operation succeeds while the second describes the required ordering when
771
795
/// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`]
@@ -812,18 +836,18 @@ impl<T> AtomicPtr<T> {
812
836
813
837
/// Stores a value into the pointer if the current value is the same as the `current` value.
814
838
///
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
816
840
/// comparison succeeds, which can result in more efficient code on some platforms. The
817
841
/// return value is a result indicating whether the new value was written and containing the
818
842
/// previous value.
819
843
///
820
- /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
844
+ /// `compare_exchange_weak() ` takes two [`Ordering`] arguments to describe the memory
821
845
/// ordering of this operation. The first describes the required ordering if the operation
822
846
/// succeeds while the second describes the required ordering when the operation fails. The
823
847
/// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or
824
848
/// weaker than the success ordering.
825
849
///
826
- /// [`compare_exchange`]: #method.compare_exchange
850
+ /// [`compare_exchange() `]: #method.compare_exchange
827
851
/// [`Ordering`]: enum.Ordering.html
828
852
/// [`Release`]: enum.Ordering.html#variant.Release
829
853
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
@@ -962,7 +986,7 @@ macro_rules! atomic_int {
962
986
963
987
/// Loads a value from the atomic integer.
964
988
///
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
966
990
/// operation.
967
991
///
968
992
/// # Panics
@@ -990,7 +1014,7 @@ macro_rules! atomic_int {
990
1014
991
1015
/// Stores a value into the atomic integer.
992
1016
///
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
994
1018
/// operation.
995
1019
///
996
1020
/// [`Ordering`]: enum.Ordering.html
@@ -1008,7 +1032,11 @@ macro_rules! atomic_int {
1008
1032
///
1009
1033
/// # Panics
1010
1034
///
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
+ ///
1012
1040
#[ inline]
1013
1041
#[ $stable]
1014
1042
pub fn store( & self , val: $int_type, order: Ordering ) {
@@ -1017,7 +1045,7 @@ macro_rules! atomic_int {
1017
1045
1018
1046
/// Stores a value into the atomic integer, returning the old value.
1019
1047
///
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
1021
1049
/// operation.
1022
1050
///
1023
1051
/// [`Ordering`]: enum.Ordering.html
@@ -1043,7 +1071,7 @@ macro_rules! atomic_int {
1043
1071
/// The return value is always the previous value. If it is equal to `current`, then the
1044
1072
/// value was updated.
1045
1073
///
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
1047
1075
/// ordering of this operation.
1048
1076
///
1049
1077
/// [`Ordering`]: enum.Ordering.html
@@ -1083,7 +1111,7 @@ macro_rules! atomic_int {
1083
1111
/// containing the previous value. On success this value is guaranteed to be equal to
1084
1112
/// `current`.
1085
1113
///
1086
- /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
1114
+ /// `compare_exchange() ` takes two [`Ordering`] arguments to describe the memory
1087
1115
/// ordering of this operation. The first describes the required ordering if
1088
1116
/// the operation succeeds while the second describes the required ordering when
1089
1117
/// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and
@@ -1125,18 +1153,18 @@ macro_rules! atomic_int {
1125
1153
/// Stores a value into the atomic integer if the current value is the same as the
1126
1154
/// `current` value.
1127
1155
///
1128
- /// Unlike [`compare_exchange`], this function is allowed to spuriously fail even
1156
+ /// Unlike [`compare_exchange() `], this function is allowed to spuriously fail even
1129
1157
/// when the comparison succeeds, which can result in more efficient code on some
1130
1158
/// platforms. The return value is a result indicating whether the new value was
1131
1159
/// written and containing the previous value.
1132
1160
///
1133
- /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
1161
+ /// `compare_exchange_weak() ` takes two [`Ordering`] arguments to describe the memory
1134
1162
/// ordering of this operation. The first describes the required ordering if the
1135
1163
/// operation succeeds while the second describes the required ordering when the
1136
1164
/// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and
1137
1165
/// must be equivalent or weaker than the success ordering.
1138
1166
///
1139
- /// [`compare_exchange`]: #method.compare_exchange
1167
+ /// [`compare_exchange() `]: #method.compare_exchange
1140
1168
/// [`Ordering`]: enum.Ordering.html
1141
1169
/// [`Release`]: enum.Ordering.html#variant.Release
1142
1170
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
0 commit comments