Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate AtomicCell::compare_and_swap #619

Merged
merged 1 commit into from Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions crossbeam-utils/benches/atomic_cell.rs
Expand Up @@ -28,11 +28,11 @@ fn fetch_add_u8(b: &mut test::Bencher) {
}

#[bench]
fn compare_and_swap_u8(b: &mut test::Bencher) {
fn compare_exchange_u8(b: &mut test::Bencher) {
let a = AtomicCell::new(0u8);
let mut i = 0;
b.iter(|| {
a.compare_and_swap(i, i.wrapping_add(1));
let _ = a.compare_exchange(i, i.wrapping_add(1));
i = i.wrapping_add(1);
});
}
Expand Down Expand Up @@ -102,11 +102,11 @@ fn fetch_add_usize(b: &mut test::Bencher) {
}

#[bench]
fn compare_and_swap_usize(b: &mut test::Bencher) {
fn compare_exchange_usize(b: &mut test::Bencher) {
let a = AtomicCell::new(0usize);
let mut i = 0;
b.iter(|| {
a.compare_and_swap(i, i.wrapping_add(1));
let _ = a.compare_exchange(i, i.wrapping_add(1));
i = i.wrapping_add(1);
});
}
Expand Down
2 changes: 2 additions & 0 deletions crossbeam-utils/src/atomic/atomic_cell.rs
Expand Up @@ -213,6 +213,7 @@ impl<T: Copy + Eq> AtomicCell<T> {
/// # Examples
///
/// ```
/// # #![allow(deprecated)]
/// use crossbeam_utils::atomic::AtomicCell;
///
/// let a = AtomicCell::new(1);
Expand All @@ -223,6 +224,7 @@ impl<T: Copy + Eq> AtomicCell<T> {
/// assert_eq!(a.compare_and_swap(1, 2), 1);
/// assert_eq!(a.load(), 2);
/// ```
#[deprecated(note = "Use `compare_exchange` instead")]
pub fn compare_and_swap(&self, current: T, new: T) -> T {
match self.compare_exchange(current, new) {
Ok(v) => v,
Expand Down