rusticl: add a safe abstraction to execute a DeleteContextCB

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25669>
This commit is contained in:
LingMan 2023-10-12 01:10:51 +02:00 committed by Marge Bot
parent 16383332a9
commit d9e2463ef3
2 changed files with 13 additions and 3 deletions

View file

@ -1,4 +1,6 @@
use crate::api::icd::CLResult;
use crate::api::icd::ReferenceCountedAPIPointer;
use crate::core::context::Context;
use rusticl_opencl_gen::*;
@ -110,6 +112,15 @@ cl_callback!(
}
);
impl DeleteContextCB {
pub fn call(self, ctx: &Context) {
let cl = cl_context::from_ptr(ctx);
// SAFETY: `cl` must have pointed to an OpenCL context, which is where we just got it from.
// All other requirements are covered by this callback's type invariants.
unsafe { (self.func)(cl, self.data) };
}
}
cl_callback!(
EventCB(FuncEventCB) {
event: cl_event,

View file

@ -203,12 +203,11 @@ impl Context {
impl Drop for Context {
fn drop(&mut self) {
let cl = cl_context::from_ptr(self);
self.dtors
.lock()
.unwrap()
.iter()
.drain(..)
.rev()
.for_each(|cb| unsafe { (cb.func)(cl, cb.data) });
.for_each(|cb| cb.call(self));
}
}