@@ -10,7 +10,6 @@ use std::time::{Duration, Instant};
10
10
use async_lock:: OnceCell ;
11
11
use futures_lite:: pin;
12
12
use parking:: Parker ;
13
- use waker_fn:: waker_fn;
14
13
15
14
use crate :: reactor:: Reactor ;
16
15
@@ -131,17 +130,7 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
131
130
let io_blocked = Arc :: new ( AtomicBool :: new ( false ) ) ;
132
131
133
132
// Prepare the waker.
134
- let waker = waker_fn ( {
135
- let io_blocked = io_blocked. clone ( ) ;
136
- move || {
137
- if u. unpark ( ) {
138
- // Check if waking from another thread and if currently blocked on I/O.
139
- if !IO_POLLING . with ( Cell :: get) && io_blocked. load ( Ordering :: SeqCst ) {
140
- Reactor :: get ( ) . notify ( ) ;
141
- }
142
- }
143
- }
144
- } ) ;
133
+ let waker = BlockOnWaker :: create ( io_blocked. clone ( ) , u) ;
145
134
146
135
( p, waker, io_blocked)
147
136
}
@@ -154,6 +143,35 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
154
143
static IO_POLLING : Cell <bool > = Cell :: new( false ) ;
155
144
}
156
145
146
+ struct BlockOnWaker {
147
+ io_blocked : Arc < AtomicBool > ,
148
+ unparker : parking:: Unparker ,
149
+ }
150
+
151
+ impl BlockOnWaker {
152
+ fn create ( io_blocked : Arc < AtomicBool > , unparker : parking:: Unparker ) -> Waker {
153
+ Waker :: from ( Arc :: new ( BlockOnWaker {
154
+ io_blocked,
155
+ unparker,
156
+ } ) )
157
+ }
158
+ }
159
+
160
+ impl std:: task:: Wake for BlockOnWaker {
161
+ fn wake_by_ref ( self : & Arc < Self > ) {
162
+ if self . unparker . unpark ( ) {
163
+ // Check if waking from another thread and if currently blocked on I/O.
164
+ if !IO_POLLING . with ( Cell :: get) && self . io_blocked . load ( Ordering :: SeqCst ) {
165
+ Reactor :: get ( ) . notify ( ) ;
166
+ }
167
+ }
168
+ }
169
+
170
+ fn wake ( self : Arc < Self > ) {
171
+ self . wake_by_ref ( )
172
+ }
173
+ }
174
+
157
175
CACHE . with ( |cache| {
158
176
// Try grabbing the cached parker and waker.
159
177
let tmp_cached;
0 commit comments