Skip to content

Commit

Permalink
Revert "avoid bounds check in Waker::try_select method"
Browse files Browse the repository at this point in the history
This reverts commit 10009bd.
  • Loading branch information
taiki-e committed Mar 16, 2022
1 parent 5b4d808 commit 7736b11
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions crossbeam-channel/src/waker.rs
Expand Up @@ -77,26 +77,34 @@ 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| {
let mut entry = None;

if !self.selectors.is_empty() {
let thread_id = current_thread_id();

for i in 0..self.selectors.len() {
// 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()
&& {
if self.selectors[i].cx.thread_id() != thread_id {
// Try selecting this operation.
let sel = Selected::Operation(self.selectors[i].oper);
let res = self.selectors[i].cx.try_select(sel);

if res.is_ok() {
// Provide the packet.
selector.cx.store_packet(selector.packet);
self.selectors[i].cx.store_packet(self.selectors[i].packet);
// Wake the thread up.
selector.cx.unpark();
true
self.selectors[i].cx.unpark();

// Remove the entry from the queue to keep it clean and improve
// performance.
entry = Some(self.selectors.remove(i));
break;
}
})
// Remove the entry from the queue to keep it clean and improve
// performance.
.map(|pos| self.selectors.remove(pos))
}
}
}

entry
}

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

0 comments on commit 7736b11

Please sign in to comment.