about summary refs log tree commit diff
path: root/src/libcore/sync
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2020-05-03 06:23:15 -0700
committerSteven Fackler <sfackler@gmail.com>2020-05-03 07:16:51 -0700
commit2ce3f85d46edbf5105f2e93d2cbe56ad777b41e6 (patch)
tree0ebcf1646dea30c4e7725fc699aff1cb24edff2f /src/libcore/sync
parentd626e4dadc37d7027d65f087da0ad1ddb460959f (diff)
downloadrust-2ce3f85d46edbf5105f2e93d2cbe56ad777b41e6.tar.gz
rust-2ce3f85d46edbf5105f2e93d2cbe56ad777b41e6.zip
Tweak and stabilize AtomicN::fetch_update
Diffstat (limited to 'src/libcore/sync')
-rw-r--r--src/libcore/sync/atomic.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs
index 220f221cdd3..f9d31f0a7d7 100644
--- a/src/libcore/sync/atomic.rs
+++ b/src/libcore/sync/atomic.rs
@@ -1809,11 +1809,10 @@ Note: This may call the function multiple times if the value has been changed fr
 the meantime, as long as the function returns `Some(_)`, but the function will have been applied
 but once to the stored value.
 
-`fetch_update` takes two [`Ordering`] arguments to describe the memory
-ordering of this operation. The first describes the required ordering for loads
-and failed updates while the second describes the required ordering when the
-operation finally succeeds. Beware that this is different from the two
-modes in [`compare_exchange`]!
+`fetch_update` takes two [`Ordering`] arguments to describe the memory ordering of this operation.
+The first describes the required ordering for when the operation finally succeeds while the second
+describes the required ordering for loads. These correspond to the success and failure orderings of
+[`compare_exchange`] respectively.
 
 Using [`Acquire`] as success ordering makes the store part
 of this operation [`Relaxed`], and using [`Release`] makes the final successful load
@@ -1831,24 +1830,21 @@ and must be equivalent to or weaker than the success ordering.
 # Examples
 
 ```rust
-#![feature(no_more_cas)]
 ", $extra_feature, "use std::sync::atomic::{", stringify!($atomic_type), ", Ordering};
 
 let x = ", stringify!($atomic_type), "::new(7);
-assert_eq!(x.fetch_update(|_| None, Ordering::SeqCst, Ordering::SeqCst), Err(7));
-assert_eq!(x.fetch_update(|x| Some(x + 1), Ordering::SeqCst, Ordering::SeqCst), Ok(7));
-assert_eq!(x.fetch_update(|x| Some(x + 1), Ordering::SeqCst, Ordering::SeqCst), Ok(8));
+assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
+assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
+assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
 assert_eq!(x.load(Ordering::SeqCst), 9);
 ```"),
                 #[inline]
-                #[unstable(feature = "no_more_cas",
-                       reason = "no more CAS loops in user code",
-                       issue = "48655")]
+                #[stable(feature = "no_more_cas", since = "1.45.0")]
                 #[$cfg_cas]
                 pub fn fetch_update<F>(&self,
-                                       mut f: F,
+                                       set_order: Ordering,
                                        fetch_order: Ordering,
-                                       set_order: Ordering) -> Result<$int_type, $int_type>
+                                       mut f: F) -> Result<$int_type, $int_type>
                 where F: FnMut($int_type) -> Option<$int_type> {
                     let mut prev = self.load(fetch_order);
                     while let Some(next) = f(prev) {