@@ -1807,13 +1807,12 @@ new value. Returns a `Result` of `Ok(previous_value)` if the function returned `
1807
1807
1808
1808
Note: This may call the function multiple times if the value has been changed from other threads in
1809
1809
the meantime, as long as the function returns `Some(_)`, but the function will have been applied
1810
- but once to the stored value.
1810
+ only once to the stored value.
1811
1811
1812
- `fetch_update` takes two [`Ordering`] arguments to describe the memory
1813
- ordering of this operation. The first describes the required ordering for loads
1814
- and failed updates while the second describes the required ordering when the
1815
- operation finally succeeds. Beware that this is different from the two
1816
- modes in [`compare_exchange`]!
1812
+ `fetch_update` takes two [`Ordering`] arguments to describe the memory ordering of this operation.
1813
+ The first describes the required ordering for when the operation finally succeeds while the second
1814
+ describes the required ordering for loads. These correspond to the success and failure orderings of
1815
+ [`compare_exchange`] respectively.
1817
1816
1818
1817
Using [`Acquire`] as success ordering makes the store part
1819
1818
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.
1831
1830
# Examples
1832
1831
1833
1832
```rust
1834
- #![feature(no_more_cas)]
1835
1833
" , $extra_feature, "use std::sync::atomic::{" , stringify!( $atomic_type) , ", Ordering};
1836
1834
1837
1835
let x = " , stringify!( $atomic_type) , "::new(7);
1838
- assert_eq!(x.fetch_update(|_| None, Ordering::SeqCst, Ordering::SeqCst), Err(7));
1839
- assert_eq!(x.fetch_update(|x| Some(x + 1), Ordering::SeqCst, Ordering::SeqCst ), Ok(7));
1840
- assert_eq!(x.fetch_update(|x| Some(x + 1), Ordering::SeqCst, Ordering::SeqCst ), Ok(8));
1836
+ assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None ), Err(7));
1837
+ assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
1838
+ assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
1841
1839
assert_eq!(x.load(Ordering::SeqCst), 9);
1842
1840
```" ) ,
1843
1841
#[ inline]
1844
- #[ unstable( feature = "no_more_cas" ,
1845
- reason = "no more CAS loops in user code" ,
1846
- issue = "48655" ) ]
1842
+ #[ stable( feature = "no_more_cas" , since = "1.45.0" ) ]
1847
1843
#[ $cfg_cas]
1848
1844
pub fn fetch_update<F >( & self ,
1849
- mut f : F ,
1845
+ set_order : Ordering ,
1850
1846
fetch_order: Ordering ,
1851
- set_order : Ordering ) -> Result <$int_type, $int_type>
1847
+ mut f : F ) -> Result <$int_type, $int_type>
1852
1848
where F : FnMut ( $int_type) -> Option <$int_type> {
1853
1849
let mut prev = self . load( fetch_order) ;
1854
1850
while let Some ( next) = f( prev) {
@@ -1882,7 +1878,6 @@ using [`Release`] makes the load part [`Relaxed`].
1882
1878
# Examples
1883
1879
1884
1880
```
1885
- #![feature(atomic_min_max)]
1886
1881
" , $extra_feature, "use std::sync::atomic::{" , stringify!( $atomic_type) , ", Ordering};
1887
1882
1888
1883
let foo = " , stringify!( $atomic_type) , "::new(23);
@@ -1893,7 +1888,6 @@ assert_eq!(foo.load(Ordering::SeqCst), 42);
1893
1888
If you want to obtain the maximum value in one step, you can use the following:
1894
1889
1895
1890
```
1896
- #![feature(atomic_min_max)]
1897
1891
" , $extra_feature, "use std::sync::atomic::{" , stringify!( $atomic_type) , ", Ordering};
1898
1892
1899
1893
let foo = " , stringify!( $atomic_type) , "::new(23);
@@ -1902,9 +1896,7 @@ let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
1902
1896
assert!(max_foo == 42);
1903
1897
```" ) ,
1904
1898
#[ inline]
1905
- #[ unstable( feature = "atomic_min_max" ,
1906
- reason = "easier and faster min/max than writing manual CAS loop" ,
1907
- issue = "48655" ) ]
1899
+ #[ stable( feature = "atomic_min_max" , since = "1.45.0" ) ]
1908
1900
#[ $cfg_cas]
1909
1901
pub fn fetch_max( & self , val: $int_type, order: Ordering ) -> $int_type {
1910
1902
// SAFETY: data races are prevented by atomic intrinsics.
@@ -1933,7 +1925,6 @@ using [`Release`] makes the load part [`Relaxed`].
1933
1925
# Examples
1934
1926
1935
1927
```
1936
- #![feature(atomic_min_max)]
1937
1928
" , $extra_feature, "use std::sync::atomic::{" , stringify!( $atomic_type) , ", Ordering};
1938
1929
1939
1930
let foo = " , stringify!( $atomic_type) , "::new(23);
@@ -1946,7 +1937,6 @@ assert_eq!(foo.load(Ordering::Relaxed), 22);
1946
1937
If you want to obtain the minimum value in one step, you can use the following:
1947
1938
1948
1939
```
1949
- #![feature(atomic_min_max)]
1950
1940
" , $extra_feature, "use std::sync::atomic::{" , stringify!( $atomic_type) , ", Ordering};
1951
1941
1952
1942
let foo = " , stringify!( $atomic_type) , "::new(23);
@@ -1955,9 +1945,7 @@ let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
1955
1945
assert_eq!(min_foo, 12);
1956
1946
```" ) ,
1957
1947
#[ inline]
1958
- #[ unstable( feature = "atomic_min_max" ,
1959
- reason = "easier and faster min/max than writing manual CAS loop" ,
1960
- issue = "48655" ) ]
1948
+ #[ stable( feature = "atomic_min_max" , since = "1.45.0" ) ]
1961
1949
#[ $cfg_cas]
1962
1950
pub fn fetch_min( & self , val: $int_type, order: Ordering ) -> $int_type {
1963
1951
// SAFETY: data races are prevented by atomic intrinsics.
0 commit comments