@@ -464,6 +464,23 @@ impl AtomicBool {
464464 /// **Note:** This method is only available on platforms that support atomic
465465 /// operations on `u8`.
466466 ///
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+ ///
467484 /// # Examples
468485 ///
469486 /// ```
@@ -479,6 +496,10 @@ impl AtomicBool {
479496 /// ```
480497 #[ inline]
481498 #[ 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+ ) ]
482503 #[ cfg( target_has_atomic = "8" ) ]
483504 pub fn compare_and_swap ( & self , current : bool , new : bool , order : Ordering ) -> bool {
484505 match self . compare_exchange ( current, new, order, strongest_failure_ordering ( order) ) {
@@ -493,9 +514,10 @@ impl AtomicBool {
493514 /// the previous value. On success this value is guaranteed to be equal to `current`.
494515 ///
495516 /// `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
499521 /// of this operation [`Relaxed`], and using [`Release`] makes the successful load
500522 /// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
501523 /// and must be equivalent to or weaker than the success ordering.
@@ -525,6 +547,7 @@ impl AtomicBool {
525547 /// ```
526548 #[ inline]
527549 #[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
550+ #[ doc( alias = "compare_and_swap" ) ]
528551 #[ cfg( target_has_atomic = "8" ) ]
529552 pub fn compare_exchange (
530553 & self ,
@@ -550,9 +573,10 @@ impl AtomicBool {
550573 /// previous value.
551574 ///
552575 /// `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
556580 /// of this operation [`Relaxed`], and using [`Release`] makes the successful load
557581 /// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
558582 /// and must be equivalent to or weaker than the success ordering.
@@ -578,6 +602,7 @@ impl AtomicBool {
578602 /// ```
579603 #[ inline]
580604 #[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
605+ #[ doc( alias = "compare_and_swap" ) ]
581606 #[ cfg( target_has_atomic = "8" ) ]
582607 pub fn compare_exchange_weak (
583608 & self ,
@@ -1066,6 +1091,23 @@ impl<T> AtomicPtr<T> {
10661091 /// **Note:** This method is only available on platforms that support atomic
10671092 /// operations on pointers.
10681093 ///
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+ ///
10691111 /// # Examples
10701112 ///
10711113 /// ```
@@ -1080,6 +1122,10 @@ impl<T> AtomicPtr<T> {
10801122 /// ```
10811123 #[ inline]
10821124 #[ 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+ ) ]
10831129 #[ cfg( target_has_atomic = "ptr" ) ]
10841130 pub fn compare_and_swap ( & self , current : * mut T , new : * mut T , order : Ordering ) -> * mut T {
10851131 match self . compare_exchange ( current, new, order, strongest_failure_ordering ( order) ) {
@@ -1094,9 +1140,10 @@ impl<T> AtomicPtr<T> {
10941140 /// the previous value. On success this value is guaranteed to be equal to `current`.
10951141 ///
10961142 /// `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
11001147 /// of this operation [`Relaxed`], and using [`Release`] makes the successful load
11011148 /// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
11021149 /// and must be equivalent to or weaker than the success ordering.
@@ -1157,9 +1204,10 @@ impl<T> AtomicPtr<T> {
11571204 /// previous value.
11581205 ///
11591206 /// `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
11631211 /// of this operation [`Relaxed`], and using [`Release`] makes the successful load
11641212 /// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
11651213 /// and must be equivalent to or weaker than the success ordering.
@@ -1604,6 +1652,23 @@ happens, and using [`Release`] makes the load part [`Relaxed`].
16041652**Note**: This method is only available on platforms that support atomic
16051653operations on [`" , $s_int_type, "`](" , $int_ref, ").
16061654
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+
16071672# Examples
16081673
16091674```
@@ -1619,6 +1684,10 @@ assert_eq!(some_var.load(Ordering::Relaxed), 10);
16191684```" ) ,
16201685 #[ inline]
16211686 #[ $stable]
1687+ #[ rustc_deprecated(
1688+ since = "1.50.0" ,
1689+ reason = "Use `compare_exchange` or `compare_exchange_weak` instead" )
1690+ ]
16221691 #[ $cfg_cas]
16231692 pub fn compare_and_swap( & self ,
16241693 current: $int_type,
@@ -1643,9 +1712,10 @@ containing the previous value. On success this value is guaranteed to be equal t
16431712`current`.
16441713
16451714`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
16491719of this operation [`Relaxed`], and using [`Release`] makes the successful load
16501720[`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
16511721and 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
16951765written and containing the previous value.
16961766
16971767`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
17011772of this operation [`Relaxed`], and using [`Release`] makes the successful load
17021773[`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
17031774and must be equivalent to or weaker than the success ordering.
0 commit comments