@@ -126,7 +126,15 @@ impl Reactor {
126
126
}
127
127
}
128
128
129
+ /// The reactor tracks the set of WASI pollables which have an associated
130
+ /// Future pending on their readiness. This function returns indicating
131
+ /// that set of pollables is not empty.
132
+ pub ( crate ) fn nonempty_pending_pollables ( & self ) -> bool {
133
+ !self . inner . borrow ( ) . wakers . is_empty ( )
134
+ }
135
+
129
136
/// Block until at least one pending pollable is ready, waking a pending future.
137
+ /// Precondition: self.nonempty_pending_pollables() is true.
130
138
pub ( crate ) fn block_on_pollables ( & self ) {
131
139
self . check_pollables ( |targets| {
132
140
debug_assert_ne ! (
@@ -142,6 +150,11 @@ impl Reactor {
142
150
/// Without blocking, check for any ready pollables and wake the
143
151
/// associated futures.
144
152
pub ( crate ) fn nonblock_check_pollables ( & self ) {
153
+ // If there are no pollables with associated pending futures, there is
154
+ // no work to do here, so return immediately.
155
+ if !self . nonempty_pending_pollables ( ) {
156
+ return ;
157
+ }
145
158
// Lazily create a pollable which always resolves to ready.
146
159
use std:: sync:: LazyLock ;
147
160
static READY_POLLABLE : LazyLock < Pollable > =
@@ -168,18 +181,13 @@ impl Reactor {
168
181
/// Common core of blocking and nonblocking pollable checks. Wakes any
169
182
/// futures which are pending on the pollables, according to the result of
170
183
/// the check_ready function.
184
+ /// Precondition: self.nonempty_pending_pollables() is true.
171
185
fn check_pollables < F > ( & self , check_ready : F )
172
186
where
173
187
F : FnOnce ( & [ & Pollable ] ) -> Vec < u32 > ,
174
188
{
175
189
let reactor = self . inner . borrow ( ) ;
176
190
177
- // If no wakers are pending on pollables, there is no work to be done
178
- // here:
179
- if reactor. wakers . is_empty ( ) {
180
- return ;
181
- }
182
-
183
191
// We're about to wait for a number of pollables. When they wake we get
184
192
// the *indexes* back for the pollables whose events were available - so
185
193
// we need to be able to associate the index with the right waker.
0 commit comments