Skip to content

Commit 02be369

Browse files
committed
removed AtomicBool from Waker struct
1 parent 45d2c7c commit 02be369

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

crates/futures/src/atomics.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cell::{Cell, RefCell};
22
use std::fmt;
33
use std::rc::Rc;
4-
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
4+
use std::sync::atomic::{AtomicI32, Ordering};
55
use std::sync::Arc;
66

77
use futures::executor::{self, Notify, Spawn};
@@ -196,23 +196,18 @@ fn _future_to_promise(future: Box<dyn Future<Item = JsValue, Error = JsValue>>)
196196
Waiting(Arc<Package>),
197197
}
198198

199+
#[derive(Default)]
199200
struct Waker {
201+
// worker will be waiting on this value
202+
// 0 by default, which means not notified
200203
value: AtomicI32,
201-
notified: AtomicBool,
202204
};
203205

204-
impl Default for Waker {
205-
fn default() -> Self {
206-
Waker {
207-
value: AtomicI32::new(0),
208-
notified: AtomicBool::new(false),
209-
}
210-
}
211-
}
212-
213206
impl Notify for Waker {
214207
fn notify(&self, _id: usize) {
215-
if !self.notified.swap(true, Ordering::SeqCst) {
208+
// since we have only value field here
209+
// let it be 1 if notified, 0 if not
210+
if self.value.swap(1, Ordering::SeqCst) == 0 {
216211
let _ = unsafe {
217212
core::arch::wasm32::atomic_notify(
218213
&self.value as *const AtomicI32 as *mut i32,
@@ -256,9 +251,9 @@ fn _future_to_promise(future: Box<dyn Future<Item = JsValue, Error = JsValue>>)
256251
// helps avoid blowing the stack by accident.
257252
let promise =
258253
crate::polyfill::wait_async(&package.waker.value).expect("Should create a Promise");
259-
let closure = Closure::once(Box::new(move |_| {
254+
let closure = Closure::once(move |_| {
260255
Package::poll(&me);
261-
}) as Box<dyn FnMut(JsValue)>);
256+
});
262257
promise.then(&closure);
263258
closure.forget();
264259
}

0 commit comments

Comments
 (0)