Skip to content

Commit a7434da

Browse files
committed
Remove restrictions on compare-exchange memory ordering.
1 parent 493c960 commit a7434da

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

library/core/src/sync/atomic.rs

+21-32
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ impl AtomicBool {
581581
/// `failure` describes the required ordering for the load operation that takes place when
582582
/// the comparison fails. Using [`Acquire`] as success ordering makes the store part
583583
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
584-
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
585-
/// and must be equivalent to or weaker than the success ordering.
584+
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
586585
///
587586
/// **Note:** This method is only available on platforms that support atomic
588587
/// operations on `u8`.
@@ -640,8 +639,7 @@ impl AtomicBool {
640639
/// `failure` describes the required ordering for the load operation that takes place when
641640
/// the comparison fails. Using [`Acquire`] as success ordering makes the store part
642641
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
643-
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
644-
/// and must be equivalent to or weaker than the success ordering.
642+
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
645643
///
646644
/// **Note:** This method is only available on platforms that support atomic
647645
/// operations on `u8`.
@@ -905,8 +903,7 @@ impl AtomicBool {
905903
/// Using [`Acquire`] as success ordering makes the store part of this
906904
/// operation [`Relaxed`], and using [`Release`] makes the final successful
907905
/// load [`Relaxed`]. The (failed) load ordering can only be [`SeqCst`],
908-
/// [`Acquire`] or [`Relaxed`] and must be equivalent to or weaker than the
909-
/// success ordering.
906+
/// [`Acquire`] or [`Relaxed`].
910907
///
911908
/// **Note:** This method is only available on platforms that support atomic
912909
/// operations on `u8`.
@@ -1265,8 +1262,7 @@ impl<T> AtomicPtr<T> {
12651262
/// `failure` describes the required ordering for the load operation that takes place when
12661263
/// the comparison fails. Using [`Acquire`] as success ordering makes the store part
12671264
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
1268-
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1269-
/// and must be equivalent to or weaker than the success ordering.
1265+
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
12701266
///
12711267
/// **Note:** This method is only available on platforms that support atomic
12721268
/// operations on pointers.
@@ -1311,8 +1307,7 @@ impl<T> AtomicPtr<T> {
13111307
/// `failure` describes the required ordering for the load operation that takes place when
13121308
/// the comparison fails. Using [`Acquire`] as success ordering makes the store part
13131309
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
1314-
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1315-
/// and must be equivalent to or weaker than the success ordering.
1310+
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
13161311
///
13171312
/// **Note:** This method is only available on platforms that support atomic
13181313
/// operations on pointers.
@@ -1368,8 +1363,7 @@ impl<T> AtomicPtr<T> {
13681363
/// Using [`Acquire`] as success ordering makes the store part of this
13691364
/// operation [`Relaxed`], and using [`Release`] makes the final successful
13701365
/// load [`Relaxed`]. The (failed) load ordering can only be [`SeqCst`],
1371-
/// [`Acquire`] or [`Relaxed`] and must be equivalent to or weaker than the
1372-
/// success ordering.
1366+
/// [`Acquire`] or [`Relaxed`].
13731367
///
13741368
/// **Note:** This method is only available on platforms that support atomic
13751369
/// operations on pointers.
@@ -1850,8 +1844,7 @@ macro_rules! atomic_int {
18501844
/// `failure` describes the required ordering for the load operation that takes place when
18511845
/// the comparison fails. Using [`Acquire`] as success ordering makes the store part
18521846
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
1853-
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1854-
/// and must be equivalent to or weaker than the success ordering.
1847+
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
18551848
///
18561849
/// **Note**: This method is only available on platforms that support atomic operations on
18571850
#[doc = concat!("[`", $s_int_type, "`].")]
@@ -1902,8 +1895,7 @@ macro_rules! atomic_int {
19021895
/// `failure` describes the required ordering for the load operation that takes place when
19031896
/// the comparison fails. Using [`Acquire`] as success ordering makes the store part
19041897
/// of this operation [`Relaxed`], and using [`Release`] makes the successful load
1905-
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
1906-
/// and must be equivalent to or weaker than the success ordering.
1898+
/// [`Relaxed`]. The failure ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
19071899
///
19081900
/// **Note**: This method is only available on platforms that support atomic operations on
19091901
#[doc = concat!("[`", $s_int_type, "`].")]
@@ -2140,8 +2132,7 @@ macro_rules! atomic_int {
21402132
///
21412133
/// Using [`Acquire`] as success ordering makes the store part
21422134
/// of this operation [`Relaxed`], and using [`Release`] makes the final successful load
2143-
/// [`Relaxed`]. The (failed) load ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`]
2144-
/// and must be equivalent to or weaker than the success ordering.
2135+
/// [`Relaxed`]. The (failed) load ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
21452136
///
21462137
/// **Note**: This method is only available on platforms that support atomic operations on
21472138
#[doc = concat!("[`", $s_int_type, "`].")]
@@ -2658,23 +2649,22 @@ unsafe fn atomic_compare_exchange<T: Copy>(
26582649
let (val, ok) = unsafe {
26592650
match (success, failure) {
26602651
(Relaxed, Relaxed) => intrinsics::atomic_cxchg_relaxed_relaxed(dst, old, new),
2661-
//(Relaxed, Acquire) => intrinsics::atomic_cxchg_relaxed_acquire(dst, old, new),
2662-
//(Relaxed, SeqCst) => intrinsics::atomic_cxchg_relaxed_seqcst(dst, old, new),
2652+
(Relaxed, Acquire) => intrinsics::atomic_cxchg_relaxed_acquire(dst, old, new),
2653+
(Relaxed, SeqCst) => intrinsics::atomic_cxchg_relaxed_seqcst(dst, old, new),
26632654
(Acquire, Relaxed) => intrinsics::atomic_cxchg_acquire_relaxed(dst, old, new),
26642655
(Acquire, Acquire) => intrinsics::atomic_cxchg_acquire_acquire(dst, old, new),
2665-
//(Acquire, SeqCst) => intrinsics::atomic_cxchg_acquire_seqcst(dst, old, new),
2656+
(Acquire, SeqCst) => intrinsics::atomic_cxchg_acquire_seqcst(dst, old, new),
26662657
(Release, Relaxed) => intrinsics::atomic_cxchg_release_relaxed(dst, old, new),
2667-
//(Release, Acquire) => intrinsics::atomic_cxchg_release_acquire(dst, old, new),
2668-
//(Release, SeqCst) => intrinsics::atomic_cxchg_release_seqcst(dst, old, new),
2658+
(Release, Acquire) => intrinsics::atomic_cxchg_release_acquire(dst, old, new),
2659+
(Release, SeqCst) => intrinsics::atomic_cxchg_release_seqcst(dst, old, new),
26692660
(AcqRel, Relaxed) => intrinsics::atomic_cxchg_acqrel_relaxed(dst, old, new),
26702661
(AcqRel, Acquire) => intrinsics::atomic_cxchg_acqrel_acquire(dst, old, new),
2671-
//(AcqRel, SeqCst) => intrinsics::atomic_cxchg_acqrel_seqcst(dst, old, new),
2662+
(AcqRel, SeqCst) => intrinsics::atomic_cxchg_acqrel_seqcst(dst, old, new),
26722663
(SeqCst, Relaxed) => intrinsics::atomic_cxchg_seqcst_relaxed(dst, old, new),
26732664
(SeqCst, Acquire) => intrinsics::atomic_cxchg_seqcst_acquire(dst, old, new),
26742665
(SeqCst, SeqCst) => intrinsics::atomic_cxchg_seqcst_seqcst(dst, old, new),
26752666
(_, AcqRel) => panic!("there is no such thing as an acquire-release failure ordering"),
26762667
(_, Release) => panic!("there is no such thing as a release failure ordering"),
2677-
_ => panic!("a failure ordering can't be stronger than a success ordering"),
26782668
}
26792669
};
26802670
if ok { Ok(val) } else { Err(val) }
@@ -2693,23 +2683,22 @@ unsafe fn atomic_compare_exchange_weak<T: Copy>(
26932683
let (val, ok) = unsafe {
26942684
match (success, failure) {
26952685
(Relaxed, Relaxed) => intrinsics::atomic_cxchgweak_relaxed_relaxed(dst, old, new),
2696-
//(Relaxed, Acquire) => intrinsics::atomic_cxchgweak_relaxed_acquire(dst, old, new),
2697-
//(Relaxed, SeqCst) => intrinsics::atomic_cxchgweak_relaxed_seqcst(dst, old, new),
2686+
(Relaxed, Acquire) => intrinsics::atomic_cxchgweak_relaxed_acquire(dst, old, new),
2687+
(Relaxed, SeqCst) => intrinsics::atomic_cxchgweak_relaxed_seqcst(dst, old, new),
26982688
(Acquire, Relaxed) => intrinsics::atomic_cxchgweak_acquire_relaxed(dst, old, new),
26992689
(Acquire, Acquire) => intrinsics::atomic_cxchgweak_acquire_acquire(dst, old, new),
2700-
//(Acquire, SeqCst) => intrinsics::atomic_cxchgweak_acquire_seqcst(dst, old, new),
2690+
(Acquire, SeqCst) => intrinsics::atomic_cxchgweak_acquire_seqcst(dst, old, new),
27012691
(Release, Relaxed) => intrinsics::atomic_cxchgweak_release_relaxed(dst, old, new),
2702-
//(Release, Acquire) => intrinsics::atomic_cxchgweak_release_acquire(dst, old, new),
2703-
//(Release, SeqCst) => intrinsics::atomic_cxchgweak_release_seqcst(dst, old, new),
2692+
(Release, Acquire) => intrinsics::atomic_cxchgweak_release_acquire(dst, old, new),
2693+
(Release, SeqCst) => intrinsics::atomic_cxchgweak_release_seqcst(dst, old, new),
27042694
(AcqRel, Relaxed) => intrinsics::atomic_cxchgweak_acqrel_relaxed(dst, old, new),
27052695
(AcqRel, Acquire) => intrinsics::atomic_cxchgweak_acqrel_acquire(dst, old, new),
2706-
//(AcqRel, SeqCst) => intrinsics::atomic_cxchgweak_acqrel_seqcst(dst, old, new),
2696+
(AcqRel, SeqCst) => intrinsics::atomic_cxchgweak_acqrel_seqcst(dst, old, new),
27072697
(SeqCst, Relaxed) => intrinsics::atomic_cxchgweak_seqcst_relaxed(dst, old, new),
27082698
(SeqCst, Acquire) => intrinsics::atomic_cxchgweak_seqcst_acquire(dst, old, new),
27092699
(SeqCst, SeqCst) => intrinsics::atomic_cxchgweak_seqcst_seqcst(dst, old, new),
27102700
(_, AcqRel) => panic!("there is no such thing as an acquire-release failure ordering"),
27112701
(_, Release) => panic!("there is no such thing as a release failure ordering"),
2712-
_ => panic!("a failure ordering can't be stronger than a success ordering"),
27132702
}
27142703
};
27152704
if ok { Ok(val) } else { Err(val) }

0 commit comments

Comments
 (0)