use crate::api::icd::CLResult;
use crate::api::icd::ReferenceCountedAPIPointer;
use crate::core::context::Context;
+use crate::core::event::Event;
use rusticl_opencl_gen::*;
}
);
+impl EventCB {
+ pub fn call(self, event: &Event, status: cl_int) {
+ let cl = cl_event::from_ptr(event);
+ // SAFETY: `cl` must be a valid pointer to an OpenCL event, which is where we just got it from.
+ // All other requirements are covered by this callback's type invariants.
+ unsafe { (self.func)(cl, status, self.data) };
+ }
+}
+
cl_callback!(
MemCB(FuncMemCB) {
memobj: cl_mem,
}
if [CL_COMPLETE, CL_RUNNING, CL_SUBMITTED].contains(&(new as u32)) {
- if let Some(cbs) = lock.cbs.get(new as usize) {
- cbs.iter()
- .for_each(|cb| unsafe { (cb.func)(cl_event::from_ptr(self), new, cb.data) });
+ if let Some(cbs) = lock.cbs.get_mut(new as usize) {
+ cbs.drain(..).for_each(|cb| cb.call(self, new));
}
}
}
// call cb if the status was already reached
if state >= status {
drop(lock);
- unsafe { (cb.func)(cl_event::from_ptr(self), status, cb.data) };
+ cb.call(self, state);
} else {
lock.cbs.get_mut(state as usize).unwrap().push(cb);
}