Skip to content

Commit b44be3f

Browse files
committed
use of AsyncPollable in WaitFor future should increment reference count of Registration
1 parent 5b7c706 commit b44be3f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/runtime/reactor.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::collections::HashMap;
1111
use std::rc::Rc;
1212
use wasi::io::poll::Pollable;
1313

14-
#[derive(Debug)]
14+
#[derive(Debug, PartialEq, Eq, Hash)]
1515
struct Registration {
1616
key: EventKey,
1717
}
@@ -22,25 +22,27 @@ impl Drop for Registration {
2222
}
2323
}
2424

25-
#[derive(Debug, Clone)]
25+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2626
pub struct AsyncPollable(Rc<Registration>);
2727

2828
impl AsyncPollable {
2929
pub fn wait_for(&self) -> WaitFor {
3030
use std::sync::atomic::{AtomicUsize, Ordering};
3131
static COUNTER: AtomicUsize = AtomicUsize::new(0);
3232
let unique = COUNTER.fetch_add(1, Ordering::Relaxed);
33-
let key = self.0.key;
3433
WaitFor {
35-
waitee: Waitee { key, unique },
34+
waitee: Waitee {
35+
pollable: self.clone(),
36+
unique,
37+
},
3638
needs_deregistration: false,
3739
}
3840
}
3941
}
4042

4143
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
4244
struct Waitee {
43-
key: EventKey,
45+
pollable: AsyncPollable,
4446
unique: usize,
4547
}
4648

@@ -125,7 +127,7 @@ impl Reactor {
125127
let mut reactor = self.inner.borrow_mut();
126128
for key in reactor.poller.block_until() {
127129
for (waitee, waker) in reactor.wakers.iter() {
128-
if waitee.key == key {
130+
if waitee.pollable.0.key == key {
129131
waker.wake_by_ref()
130132
}
131133
}
@@ -156,7 +158,7 @@ impl Reactor {
156158
let mut reactor = self.inner.borrow_mut();
157159
let ready = reactor
158160
.poller
159-
.get(&waitee.key)
161+
.get(&waitee.pollable.0.key)
160162
.expect("only live EventKey can be checked for readiness")
161163
.ready();
162164
if !ready {

0 commit comments

Comments
 (0)