Skip to content

Commit

Permalink
Merge #802
Browse files Browse the repository at this point in the history
802: channel: Do not call current_thread_id inside iteration r=taiki-e a=taiki-e

This should result in the same behavior as before 10009bd.

This works around an upstream bug related to TLS access on aarch64 linux, which was [reported in firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1757571).

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored Mar 18, 2022
2 parents 5b4d808 + 81fda54 commit eb6cb05
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions crossbeam-channel/src/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,32 @@ impl Waker {
/// Attempts to find another thread's entry, select the operation, and wake it up.
#[inline]
pub(crate) fn try_select(&mut self) -> Option<Entry> {
self.selectors
.iter()
.position(|selector| {
// Does the entry belong to a different thread?
selector.cx.thread_id() != current_thread_id()
&& selector // Try selecting this operation.
.cx
.try_select(Selected::Operation(selector.oper))
.is_ok()
&& {
// Provide the packet.
selector.cx.store_packet(selector.packet);
// Wake the thread up.
selector.cx.unpark();
true
}
})
// Remove the entry from the queue to keep it clean and improve
// performance.
.map(|pos| self.selectors.remove(pos))
if self.selectors.is_empty() {
None
} else {
let thread_id = current_thread_id();

self.selectors
.iter()
.position(|selector| {
// Does the entry belong to a different thread?
selector.cx.thread_id() != thread_id
&& selector // Try selecting this operation.
.cx
.try_select(Selected::Operation(selector.oper))
.is_ok()
&& {
// Provide the packet.
selector.cx.store_packet(selector.packet);
// Wake the thread up.
selector.cx.unpark();
true
}
})
// Remove the entry from the queue to keep it clean and improve
// performance.
.map(|pos| self.selectors.remove(pos))
}
}

/// Returns `true` if there is an entry which can be selected by the current thread.
Expand Down

0 comments on commit eb6cb05

Please sign in to comment.