Implement Stealer::will_steal_from#1103
Implement Stealer::will_steal_from#1103james7132 wants to merge 5 commits intocrossbeam-rs:masterfrom
Conversation
taiki-e
left a comment
There was a problem hiding this comment.
Thanks for the PR! I'm positive about adding such a method.
| /// 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 { |
There was a problem hiding this comment.
I don't feel this method name is easy to understand, but I'm not sure what the good name would be.
There was a problem hiding this comment.
Not sure if Worker::ptr_eq is better. I can't seem to come up with a better name here either.
There was a problem hiding this comment.
Went ahead and renamed the function as @notgull requested.
|
As for naming: While looking at several unrelated APIs ( stealer.will_steal(&worker)
// or
stealer.will_steal_from(&worker) |
|
@taiki-e, went ahead with the suggested rename. |
| /// assert!(!s_1.will_steal_fromq(&w_1)); | ||
| /// assert!(!s_2.will_steal_fromq(&w_2)); | ||
| /// assert!(s_1.will_steal_fromq(&w_2)); | ||
| /// assert!(s_2.will_steal_fromq(&w_1)); | ||
| /// ``` | ||
| pub fn will_steal_fromq(&self, worker: &Worker<T>) -> bool { |
There was a problem hiding this comment.
| /// assert!(!s_1.will_steal_fromq(&w_1)); | |
| /// assert!(!s_2.will_steal_fromq(&w_2)); | |
| /// assert!(s_1.will_steal_fromq(&w_2)); | |
| /// assert!(s_2.will_steal_fromq(&w_1)); | |
| /// ``` | |
| pub fn will_steal_fromq(&self, worker: &Worker<T>) -> bool { | |
| /// assert!(!s_1.will_steal_from(&w_1)); | |
| /// assert!(!s_2.will_steal_from(&w_2)); | |
| /// assert!(s_1.will_steal_from(&w_2)); | |
| /// assert!(s_2.will_steal_from(&w_1)); | |
| /// ``` | |
| pub fn will_steal_from(&self, worker: &Worker<T>) -> bool { |
|
|
||
| /// Checks if the stealer will steal from the provided worker. | ||
| /// | ||
| /// If both are pointing to the same underlying queue, this will return false. |
There was a problem hiding this comment.
Isn't that the reverse?
stealsteals from the underlying queue.steal_batchsteals from the underlying queue and pushes to other worker.
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.