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

Implement Worker::is_same_as #1103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crossbeam-deque/src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,28 @@ impl<T> Worker<T> {
}
}

/// Returns true if the given stealer was derived from this worker.
///
/// # Examples
///
/// ```
/// use crossbeam_deque::Worker;
///
/// let w_1 = Worker::<i32>::new_lifo();
/// let w_2 = Worker::<i32>::new_fifo();
///
/// let s_1 = w_1.stealer();
/// let s_2 = w_2.stealer();
///
/// assert!(w_1.is_same_as(&s_1));
/// assert!(w_2.is_same_as(&s_2));
/// assert!(!w_1.is_same_as(&s_2));
/// assert!(!w_2.is_same_as(&s_1));
/// ```
pub fn is_same_as(&self, stealer: &Stealer<T>) -> bool {
Copy link
Member

@taiki-e taiki-e Apr 25, 2024

Choose a reason for hiding this comment

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

I don't feel this method name is easy to understand, but I'm not sure what the good name would be.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure if Worker::ptr_eq is better. I can't seem to come up with a better name here either.

Copy link

Choose a reason for hiding this comment

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

How about Worker::donates_to?

Arc::ptr_eq(&self.inner, &stealer.inner)
}

/// Resizes the internal buffer to the new capacity of `new_cap`.
#[cold]
unsafe fn resize(&self, new_cap: usize) {
Expand Down
Loading