File tree Expand file tree Collapse file tree 1 file changed +26
-20
lines changed
library/std/src/sync/mpmc Expand file tree Collapse file tree 1 file changed +26
-20
lines changed Original file line number Diff line number Diff line change @@ -66,26 +66,32 @@ impl Waker {
66
66
/// Attempts to find another thread's entry, select the operation, and wake it up.
67
67
#[inline]
68
68
pub(crate) fn try_select(&mut self) -> Option<Entry> {
69
- self.selectors
70
- .iter()
71
- .position(|selector| {
72
- // Does the entry belong to a different thread?
73
- selector.cx.thread_id() != current_thread_id()
74
- && selector // Try selecting this operation.
75
- .cx
76
- .try_select(Selected::Operation(selector.oper))
77
- .is_ok()
78
- && {
79
- // Provide the packet.
80
- selector.cx.store_packet(selector.packet);
81
- // Wake the thread up.
82
- selector.cx.unpark();
83
- true
84
- }
85
- })
86
- // Remove the entry from the queue to keep it clean and improve
87
- // performance.
88
- .map(|pos| self.selectors.remove(pos))
69
+ if self.selectors.is_empty() {
70
+ None
71
+ } else {
72
+ let thread_id = current_thread_id();
73
+
74
+ self.selectors
75
+ .iter()
76
+ .position(|selector| {
77
+ // Does the entry belong to a different thread?
78
+ selector.cx.thread_id() != thread_id
79
+ && selector // Try selecting this operation.
80
+ .cx
81
+ .try_select(Selected::Operation(selector.oper))
82
+ .is_ok()
83
+ && {
84
+ // Provide the packet.
85
+ selector.cx.store_packet(selector.packet);
86
+ // Wake the thread up.
87
+ selector.cx.unpark();
88
+ true
89
+ }
90
+ })
91
+ // Remove the entry from the queue to keep it clean and improve
92
+ // performance.
93
+ .map(|pos| self.selectors.remove(pos))
94
+ }
89
95
}
90
96
91
97
/// Notifies all operations waiting to be ready.
You can’t perform that action at this time.
0 commit comments