avoid tls access while iterating through mpsc thread entries
This commit is contained in:
parent
77e24f90f5
commit
fb31a1ac21
@ -66,26 +66,32 @@ 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> {
|
||||||
self.selectors
|
if self.selectors.is_empty() {
|
||||||
.iter()
|
None
|
||||||
.position(|selector| {
|
} else {
|
||||||
// Does the entry belong to a different thread?
|
let thread_id = current_thread_id();
|
||||||
selector.cx.thread_id() != current_thread_id()
|
|
||||||
&& selector // Try selecting this operation.
|
self.selectors
|
||||||
.cx
|
.iter()
|
||||||
.try_select(Selected::Operation(selector.oper))
|
.position(|selector| {
|
||||||
.is_ok()
|
// Does the entry belong to a different thread?
|
||||||
&& {
|
selector.cx.thread_id() != thread_id
|
||||||
// Provide the packet.
|
&& selector // Try selecting this operation.
|
||||||
selector.cx.store_packet(selector.packet);
|
.cx
|
||||||
// Wake the thread up.
|
.try_select(Selected::Operation(selector.oper))
|
||||||
selector.cx.unpark();
|
.is_ok()
|
||||||
true
|
&& {
|
||||||
}
|
// Provide the packet.
|
||||||
})
|
selector.cx.store_packet(selector.packet);
|
||||||
// Remove the entry from the queue to keep it clean and improve
|
// Wake the thread up.
|
||||||
// performance.
|
selector.cx.unpark();
|
||||||
.map(|pos| self.selectors.remove(pos))
|
true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// Remove the entry from the queue to keep it clean and improve
|
||||||
|
// performance.
|
||||||
|
.map(|pos| self.selectors.remove(pos))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Notifies all operations waiting to be ready.
|
/// Notifies all operations waiting to be ready.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user