Skip to content

Commit d7cd28a

Browse files
committed
Implement a Worker::is_same_as function
1 parent 983d56b commit d7cd28a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crossbeam-deque/src/deque.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,28 @@ impl<T> Worker<T> {
284284
}
285285
}
286286

287+
/// Checks if the worker and the provided stealer are pointing to the same underlying queue.
288+
///
289+
/// # Examples
290+
///
291+
/// ```
292+
/// use crossbeam_deque::Worker;
293+
///
294+
/// let w_1 = Worker::<i32>::new_lifo();
295+
/// let w_2 = Worker::<i32>::new_fifo();
296+
///
297+
/// let s_1 = w.stealer();
298+
/// let s_2 = w.stealer();
299+
///
300+
/// assert!(w_1.is_same_as(&s_1));
301+
/// assert!(w_2.is_same_as(&s_2));
302+
/// assert!(!w_1.is_same_as(&s_2));
303+
/// assert!(!w_2.is_same_as(&s_1));
304+
/// ```
305+
pub fn is_same_as(&self, stealer: &Stealer<T>) -> bool {
306+
Arc::ptr_eq(&self.inner, &stealer.inner)
307+
}
308+
287309
/// Resizes the internal buffer to the new capacity of `new_cap`.
288310
#[cold]
289311
unsafe fn resize(&self, new_cap: usize) {

0 commit comments

Comments
 (0)