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 2 commits into
base: master
Choose a base branch
from

Conversation

james7132
Copy link

Currently it's not possible to tell if a Worker and a Stealer point to the same underlying queue. This make it difficult to tell which stealer to remove from a list and you have a local Worker on hand, or skip stealing from when given a global list of stealers. The implementation just forwards to Arc::ptr_eq on the inner buffer. Added a doctest as well.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I'm positive about adding such a method.

@@ -284,6 +284,28 @@ impl<T> Worker<T> {
}
}

/// Checks if the worker and the provided stealer are pointing to the same underlying queue.
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 feel it would be easier to understand documentation something like "Returns true if the given stealer was derived from this worker".

/// 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.

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.

None yet

2 participants