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

Replace deprecated compare_and_swap with compare_exchange #617

Merged
merged 1 commit into from
Dec 24, 2020

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Dec 24, 2020

compare_and_swap is deprecated in 1.50. (rust-lang/rust#79261)
This patch replaces the uses of compare_and_swap with compare_exchange.

See also the document about compare_and_swap -> compare_exchange(_weak) migration: https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicUsize.html#migrating-to-compare_exchange-and-compare_exchange_weak

@taiki-e taiki-e requested a review from jeehoonkang December 24, 2020 03:44
pub fn compare_and_swap(&self, current: Epoch, new: Epoch, ord: Ordering) -> Epoch {
let data = self.data.compare_and_swap(current.data, new.data, ord);
Epoch { data }
pub fn compare_exchange(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is marked as pub, but this is a function used only within the crate and not exposed, so this change does not break the public API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • By "exposed", you mean it's not part of the public API?
  • Even if it is public, I vote for chaging like you suggested. We're before 1.0 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • By "exposed", you mean it's not part of the public API?

Yes, this function and AtomicEpoch that implements this function is not part of the public API: https://docs.rs/crossbeam-epoch/0.9.1/crossbeam_epoch/#structs

Copy link
Contributor

@jeehoonkang jeehoonkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

bors r+

pub fn compare_and_swap(&self, current: Epoch, new: Epoch, ord: Ordering) -> Epoch {
let data = self.data.compare_and_swap(current.data, new.data, ord);
Epoch { data }
pub fn compare_exchange(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • By "exposed", you mean it's not part of the public API?
  • Even if it is public, I vote for chaging like you suggested. We're before 1.0 :)

@jeehoonkang
Copy link
Contributor

Just one more thing: do you think it's also worth changing the APIs of Atomic? We can deprecate compare_and_swap and encourage compare_exchange for the struct, too.

@taiki-e
Copy link
Member Author

taiki-e commented Dec 24, 2020

Just one more thing: do you think it's also worth changing the APIs of Atomic? We can deprecate compare_and_swap and encourage compare_exchange for the struct, too.

Did you mean AtomicCell? (crossbeam_epoch::Atomic does not have compare_and_swap method)
If so I've opened #618 for this (I'm in favor of deprecating compare_and_swap).

@bors
Copy link
Contributor

bors bot commented Dec 24, 2020

Build succeeded:

@bors bors bot merged commit 0fe6e3d into crossbeam-rs:master Dec 24, 2020
@taiki-e taiki-e deleted the compare_and_swap branch December 24, 2020 04:11
bors bot added a commit that referenced this pull request Jan 4, 2021
637: Apply unreachable_pub lint r=jeehoonkang a=taiki-e

`unreachable_pub` lint warns items that are marked as `pub` but are not actually included in the public API, and suggests using `pub(crate)` instead.

`pub(crate)` is a bit more verbose than `pub`, but this should make it easier to review changes that make it difficult to tell if it will break API or not just by looking at the diff like #617 (comment). Especially, there are many such codes in crossbeam-channel and crossbeam-epoch. (Hopefully, after this patch, we can basically consider all items marked `pub` are public APIs, except for items that have been explicitly hidden from the public API by `#[doc(hidden)]`.)

This lint is known to have some false positives, but the crossbeam doesn't seem to be affected.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants