Skip to content

Commit c64b08e

Browse files
committed
fix crash, still some leaks
1 parent 200a8c7 commit c64b08e

File tree

1 file changed

+10
-10
lines changed
  • crates/symmetric_executor/src

1 file changed

+10
-10
lines changed

crates/symmetric_executor/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use executor::exports::symmetric::runtime::symmetric_executor::{
9-
self, CallbackData, CallbackState, GuestEventSubscription,
9+
self, CallbackState, GuestEventSubscription,
1010
};
1111

1212
mod executor;
@@ -122,8 +122,8 @@ impl symmetric_executor::Guest for Guest {
122122
let mut ex = EXECUTOR.lock().unwrap();
123123
ex.active_tasks.iter_mut().for_each(|task| {
124124
if task.ready() {
125-
task.callback.take_if(|(f, data)| {
126-
matches!((f)(data.handle() as *mut ()), CallbackState::Ready)
125+
task.callback.take_if(|CallbackEntry(f, data)| {
126+
matches!((f)(*data), CallbackState::Ready)
127127
});
128128
} else {
129129
match &task.inner {
@@ -151,11 +151,8 @@ impl symmetric_executor::Guest for Guest {
151151
}
152152
tvptr = core::ptr::from_mut(&mut wait);
153153
} else {
154-
task.callback.take_if(|(f, data)| {
155-
matches!(
156-
(f)(data.handle() as *mut ()),
157-
CallbackState::Ready
158-
)
154+
task.callback.take_if(|CallbackEntry(f, data)| {
155+
matches!((f)(*data), CallbackState::Ready)
159156
});
160157
}
161158
}
@@ -216,7 +213,8 @@ impl symmetric_executor::Guest for Guest {
216213
&mut *(trigger.take_handle() as *mut EventSubscription)
217214
});
218215
let cb: fn(*mut ()) -> CallbackState = unsafe { transmute(callback.take_handle()) };
219-
subscr.callback.replace((cb, data));
216+
let data = data.take_handle() as *mut ();
217+
subscr.callback.replace(CallbackEntry(cb, data));
220218
EXECUTOR.lock().unwrap().active_tasks.push(subscr);
221219
}
222220
}
@@ -231,7 +229,9 @@ struct EventInner {
231229

232230
struct EventGenerator(Arc<Mutex<EventInner>>);
233231

234-
type CallbackEntry = (fn(*mut ()) -> CallbackState, CallbackData);
232+
struct CallbackEntry(fn(*mut ()) -> CallbackState, *mut ());
233+
234+
unsafe impl Send for CallbackEntry {}
235235

236236
struct EventSubscription {
237237
inner: EventType,

0 commit comments

Comments
 (0)