Skip to content

Commit 4fd3674

Browse files
bors[bot]taiki-e
andauthored
Merge #619
619: Deprecate AtomicCell::compare_and_swap r=jeehoonkang a=taiki-e The standard library deprecated `compare_and_swap` in favor of `compare_exchange(_weak)` in 1.50. (rust-lang/rust#79261) Given why std `compare_and_swap` was deprecated, it probably makes sense to do the same with `AtomicCell::compare_and_swap`. Closes #618 Co-authored-by: Taiki Endo <[email protected]>
2 parents 0fe6e3d + ff10e23 commit 4fd3674

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

crossbeam-utils/benches/atomic_cell.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ fn fetch_add_u8(b: &mut test::Bencher) {
2828
}
2929

3030
#[bench]
31-
fn compare_and_swap_u8(b: &mut test::Bencher) {
31+
fn compare_exchange_u8(b: &mut test::Bencher) {
3232
let a = AtomicCell::new(0u8);
3333
let mut i = 0;
3434
b.iter(|| {
35-
a.compare_and_swap(i, i.wrapping_add(1));
35+
let _ = a.compare_exchange(i, i.wrapping_add(1));
3636
i = i.wrapping_add(1);
3737
});
3838
}
@@ -102,11 +102,11 @@ fn fetch_add_usize(b: &mut test::Bencher) {
102102
}
103103

104104
#[bench]
105-
fn compare_and_swap_usize(b: &mut test::Bencher) {
105+
fn compare_exchange_usize(b: &mut test::Bencher) {
106106
let a = AtomicCell::new(0usize);
107107
let mut i = 0;
108108
b.iter(|| {
109-
a.compare_and_swap(i, i.wrapping_add(1));
109+
let _ = a.compare_exchange(i, i.wrapping_add(1));
110110
i = i.wrapping_add(1);
111111
});
112112
}

crossbeam-utils/src/atomic/atomic_cell.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl<T: Copy + Eq> AtomicCell<T> {
213213
/// # Examples
214214
///
215215
/// ```
216+
/// # #![allow(deprecated)]
216217
/// use crossbeam_utils::atomic::AtomicCell;
217218
///
218219
/// let a = AtomicCell::new(1);
@@ -223,6 +224,7 @@ impl<T: Copy + Eq> AtomicCell<T> {
223224
/// assert_eq!(a.compare_and_swap(1, 2), 1);
224225
/// assert_eq!(a.load(), 2);
225226
/// ```
227+
#[deprecated(note = "Use `compare_exchange` instead")]
226228
pub fn compare_and_swap(&self, current: T, new: T) -> T {
227229
match self.compare_exchange(current, new) {
228230
Ok(v) => v,

0 commit comments

Comments
 (0)