Skip to content

Commit

Permalink
fix crash, still some leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Dec 8, 2024
1 parent 200a8c7 commit c64b08e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/symmetric_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use executor::exports::symmetric::runtime::symmetric_executor::{
self, CallbackData, CallbackState, GuestEventSubscription,
self, CallbackState, GuestEventSubscription,
};

mod executor;
Expand Down Expand Up @@ -122,8 +122,8 @@ impl symmetric_executor::Guest for Guest {
let mut ex = EXECUTOR.lock().unwrap();
ex.active_tasks.iter_mut().for_each(|task| {
if task.ready() {
task.callback.take_if(|(f, data)| {
matches!((f)(data.handle() as *mut ()), CallbackState::Ready)
task.callback.take_if(|CallbackEntry(f, data)| {
matches!((f)(*data), CallbackState::Ready)
});
} else {
match &task.inner {
Expand Down Expand Up @@ -151,11 +151,8 @@ impl symmetric_executor::Guest for Guest {
}
tvptr = core::ptr::from_mut(&mut wait);
} else {
task.callback.take_if(|(f, data)| {
matches!(
(f)(data.handle() as *mut ()),
CallbackState::Ready
)
task.callback.take_if(|CallbackEntry(f, data)| {
matches!((f)(*data), CallbackState::Ready)
});
}
}
Expand Down Expand Up @@ -216,7 +213,8 @@ impl symmetric_executor::Guest for Guest {
&mut *(trigger.take_handle() as *mut EventSubscription)
});
let cb: fn(*mut ()) -> CallbackState = unsafe { transmute(callback.take_handle()) };
subscr.callback.replace((cb, data));
let data = data.take_handle() as *mut ();
subscr.callback.replace(CallbackEntry(cb, data));
EXECUTOR.lock().unwrap().active_tasks.push(subscr);
}
}
Expand All @@ -231,7 +229,9 @@ struct EventInner {

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

type CallbackEntry = (fn(*mut ()) -> CallbackState, CallbackData);
struct CallbackEntry(fn(*mut ()) -> CallbackState, *mut ());

unsafe impl Send for CallbackEntry {}

struct EventSubscription {
inner: EventType,
Expand Down

0 comments on commit c64b08e

Please sign in to comment.