avoid tls access while iterating through mpsc thread entries
This commit is contained in:
@@ -66,11 +66,16 @@ impl Waker {
|
|||||||
/// Attempts to find another thread's entry, select the operation, and wake it up.
|
/// Attempts to find another thread's entry, select the operation, and wake it up.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn try_select(&mut self) -> Option<Entry> {
|
pub(crate) fn try_select(&mut self) -> Option<Entry> {
|
||||||
|
if self.selectors.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let thread_id = current_thread_id();
|
||||||
|
|
||||||
self.selectors
|
self.selectors
|
||||||
.iter()
|
.iter()
|
||||||
.position(|selector| {
|
.position(|selector| {
|
||||||
// Does the entry belong to a different thread?
|
// Does the entry belong to a different thread?
|
||||||
selector.cx.thread_id() != current_thread_id()
|
selector.cx.thread_id() != thread_id
|
||||||
&& selector // Try selecting this operation.
|
&& selector // Try selecting this operation.
|
||||||
.cx
|
.cx
|
||||||
.try_select(Selected::Operation(selector.oper))
|
.try_select(Selected::Operation(selector.oper))
|
||||||
@@ -87,6 +92,7 @@ impl Waker {
|
|||||||
// performance.
|
// performance.
|
||||||
.map(|pos| self.selectors.remove(pos))
|
.map(|pos| self.selectors.remove(pos))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Notifies all operations waiting to be ready.
|
/// Notifies all operations waiting to be ready.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
Reference in New Issue
Block a user