@@ -464,6 +464,23 @@ impl AtomicBool {
464
464
/// **Note:** This method is only available on platforms that support atomic
465
465
/// operations on `u8`.
466
466
///
467
+ /// # Migrating to `compare_exchange` and `compare_exchange_weak`
468
+ ///
469
+ /// `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
470
+ /// memory orderings:
471
+ ///
472
+ /// Original | Success | Failure
473
+ /// -------- | ------- | -------
474
+ /// Relaxed | Relaxed | Relaxed
475
+ /// Acquire | Acquire | Acquire
476
+ /// Release | Release | Relaxed
477
+ /// AcqRel | AcqRel | Acquire
478
+ /// SeqCst | SeqCst | SeqCst
479
+ ///
480
+ /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
481
+ /// which allows the compiler to generate better assembly code when the compare and swap
482
+ /// is used in a loop.
483
+ ///
467
484
/// # Examples
468
485
///
469
486
/// ```
@@ -479,6 +496,10 @@ impl AtomicBool {
479
496
/// ```
480
497
#[ inline]
481
498
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
499
+ #[ rustc_deprecated(
500
+ since = "1.50.0" ,
501
+ reason = "Use `compare_exchange` or `compare_exchange_weak` instead"
502
+ ) ]
482
503
#[ cfg( target_has_atomic = "8" ) ]
483
504
pub fn compare_and_swap ( & self , current : bool , new : bool , order : Ordering ) -> bool {
484
505
match self . compare_exchange ( current, new, order, strongest_failure_ordering ( order) ) {
@@ -493,9 +514,10 @@ impl AtomicBool {
493
514
/// the previous value. On success this value is guaranteed to be equal to `current`.
494
515
///
495
516
/// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
496
- /// ordering of this operation. The first describes the required ordering if the
497
- /// operation succeeds while the second describes the required ordering when the
498
- /// operation fails. Using [`Acquire`] as success ordering makes the store part
517
+ /// ordering of this operation. `success` describes the required ordering for the
518
+ /// read-modify-write operation that takes place if the comparison with `current` succeeds.
519
+ /// `failure` describes the required ordering for the load operation that takes place when
520
+ /// the comparison fails. Using [`Acquire`] as success ordering makes the store part
499
521
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
500
522
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
501
523
/// and must be equivalent to or weaker than the success ordering.
@@ -525,6 +547,7 @@ impl AtomicBool {
525
547
/// ```
526
548
#[ inline]
527
549
#[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
550
+ #[ doc( alias = "compare_and_swap" ) ]
528
551
#[ cfg( target_has_atomic = "8" ) ]
529
552
pub fn compare_exchange (
530
553
& self ,
@@ -550,9 +573,10 @@ impl AtomicBool {
550
573
/// previous value.
551
574
///
552
575
/// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
553
- /// ordering of this operation. The first describes the required ordering if the
554
- /// operation succeeds while the second describes the required ordering when the
555
- /// operation fails. Using [`Acquire`] as success ordering makes the store part
576
+ /// ordering of this operation. `success` describes the required ordering for the
577
+ /// read-modify-write operation that takes place if the comparison with `current` succeeds.
578
+ /// `failure` describes the required ordering for the load operation that takes place when
579
+ /// the comparison fails. Using [`Acquire`] as success ordering makes the store part
556
580
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
557
581
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
558
582
/// and must be equivalent to or weaker than the success ordering.
@@ -578,6 +602,7 @@ impl AtomicBool {
578
602
/// ```
579
603
#[ inline]
580
604
#[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
605
+ #[ doc( alias = "compare_and_swap" ) ]
581
606
#[ cfg( target_has_atomic = "8" ) ]
582
607
pub fn compare_exchange_weak (
583
608
& self ,
@@ -1066,6 +1091,23 @@ impl<T> AtomicPtr<T> {
1066
1091
/// **Note:** This method is only available on platforms that support atomic
1067
1092
/// operations on pointers.
1068
1093
///
1094
+ /// # Migrating to `compare_exchange` and `compare_exchange_weak`
1095
+ ///
1096
+ /// `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
1097
+ /// memory orderings:
1098
+ ///
1099
+ /// Original | Success | Failure
1100
+ /// -------- | ------- | -------
1101
+ /// Relaxed | Relaxed | Relaxed
1102
+ /// Acquire | Acquire | Acquire
1103
+ /// Release | Release | Relaxed
1104
+ /// AcqRel | AcqRel | Acquire
1105
+ /// SeqCst | SeqCst | SeqCst
1106
+ ///
1107
+ /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1108
+ /// which allows the compiler to generate better assembly code when the compare and swap
1109
+ /// is used in a loop.
1110
+ ///
1069
1111
/// # Examples
1070
1112
///
1071
1113
/// ```
@@ -1080,6 +1122,10 @@ impl<T> AtomicPtr<T> {
1080
1122
/// ```
1081
1123
#[ inline]
1082
1124
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1125
+ #[ rustc_deprecated(
1126
+ since = "1.50.0" ,
1127
+ reason = "Use `compare_exchange` or `compare_exchange_weak` instead"
1128
+ ) ]
1083
1129
#[ cfg( target_has_atomic = "ptr" ) ]
1084
1130
pub fn compare_and_swap ( & self , current : * mut T , new : * mut T , order : Ordering ) -> * mut T {
1085
1131
match self . compare_exchange ( current, new, order, strongest_failure_ordering ( order) ) {
@@ -1094,9 +1140,10 @@ impl<T> AtomicPtr<T> {
1094
1140
/// the previous value. On success this value is guaranteed to be equal to `current`.
1095
1141
///
1096
1142
/// `compare_exchange` takes two [`Ordering`] arguments to describe the memory
1097
- /// ordering of this operation. The first describes the required ordering if the
1098
- /// operation succeeds while the second describes the required ordering when the
1099
- /// operation fails. Using [`Acquire`] as success ordering makes the store part
1143
+ /// ordering of this operation. `success` describes the required ordering for the
1144
+ /// read-modify-write operation that takes place if the comparison with `current` succeeds.
1145
+ /// `failure` describes the required ordering for the load operation that takes place when
1146
+ /// the comparison fails. Using [`Acquire`] as success ordering makes the store part
1100
1147
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
1101
1148
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1102
1149
/// and must be equivalent to or weaker than the success ordering.
@@ -1157,9 +1204,10 @@ impl<T> AtomicPtr<T> {
1157
1204
/// previous value.
1158
1205
///
1159
1206
/// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
1160
- /// ordering of this operation. The first describes the required ordering if the
1161
- /// operation succeeds while the second describes the required ordering when the
1162
- /// operation fails. Using [`Acquire`] as success ordering makes the store part
1207
+ /// ordering of this operation. `success` describes the required ordering for the
1208
+ /// read-modify-write operation that takes place if the comparison with `current` succeeds.
1209
+ /// `failure` describes the required ordering for the load operation that takes place when
1210
+ /// the comparison fails. Using [`Acquire`] as success ordering makes the store part
1163
1211
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
1164
1212
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1165
1213
/// and must be equivalent to or weaker than the success ordering.
@@ -1604,6 +1652,23 @@ happens, and using [`Release`] makes the load part [`Relaxed`].
1604
1652
**Note**: This method is only available on platforms that support atomic
1605
1653
operations on [`" , $s_int_type, "`](" , $int_ref, ").
1606
1654
1655
+ # Migrating to `compare_exchange` and `compare_exchange_weak`
1656
+
1657
+ `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
1658
+ memory orderings:
1659
+
1660
+ Original | Success | Failure
1661
+ -------- | ------- | -------
1662
+ Relaxed | Relaxed | Relaxed
1663
+ Acquire | Acquire | Acquire
1664
+ Release | Release | Relaxed
1665
+ AcqRel | AcqRel | Acquire
1666
+ SeqCst | SeqCst | SeqCst
1667
+
1668
+ `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1669
+ which allows the compiler to generate better assembly code when the compare and swap
1670
+ is used in a loop.
1671
+
1607
1672
# Examples
1608
1673
1609
1674
```
@@ -1619,6 +1684,10 @@ assert_eq!(some_var.load(Ordering::Relaxed), 10);
1619
1684
```" ) ,
1620
1685
#[ inline]
1621
1686
#[ $stable]
1687
+ #[ rustc_deprecated(
1688
+ since = "1.50.0" ,
1689
+ reason = "Use `compare_exchange` or `compare_exchange_weak` instead" )
1690
+ ]
1622
1691
#[ $cfg_cas]
1623
1692
pub fn compare_and_swap( & self ,
1624
1693
current: $int_type,
@@ -1643,9 +1712,10 @@ containing the previous value. On success this value is guaranteed to be equal t
1643
1712
`current`.
1644
1713
1645
1714
`compare_exchange` takes two [`Ordering`] arguments to describe the memory
1646
- ordering of this operation. The first describes the required ordering if the
1647
- operation succeeds while the second describes the required ordering when the
1648
- operation fails. Using [`Acquire`] as success ordering makes the store part
1715
+ ordering of this operation. `success` describes the required ordering for the
1716
+ read-modify-write operation that takes place if the comparison with `current` succeeds.
1717
+ `failure` describes the required ordering for the load operation that takes place when
1718
+ the comparison fails. Using [`Acquire`] as success ordering makes the store part
1649
1719
of this operation [`Relaxed`], and using [`Release`] makes the successful load
1650
1720
[`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1651
1721
and must be equivalent to or weaker than the success ordering.
@@ -1695,9 +1765,10 @@ platforms. The return value is a result indicating whether the new value was
1695
1765
written and containing the previous value.
1696
1766
1697
1767
`compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory
1698
- ordering of this operation. The first describes the required ordering if the
1699
- operation succeeds while the second describes the required ordering when the
1700
- operation fails. Using [`Acquire`] as success ordering makes the store part
1768
+ ordering of this operation. `success` describes the required ordering for the
1769
+ read-modify-write operation that takes place if the comparison with `current` succeeds.
1770
+ `failure` describes the required ordering for the load operation that takes place when
1771
+ the comparison fails. Using [`Acquire`] as success ordering makes the store part
1701
1772
of this operation [`Relaxed`], and using [`Release`] makes the successful load
1702
1773
[`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1703
1774
and must be equivalent to or weaker than the success ordering.
0 commit comments