HeapJob drops Job and Self

This commit is contained in:
Janis 2025-02-21 20:05:02 +01:00
parent c25b62ee3e
commit 11514efd30

View file

@ -803,15 +803,22 @@ mod job {
#[allow(dead_code)] #[allow(dead_code)]
pub struct HeapJob<F> { pub struct HeapJob<F> {
f: F, f: F,
_phantom: PhantomPinned,
} }
impl<F> HeapJob<F> { impl<F> HeapJob<F> {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new(f: F) -> Box<Self> { pub fn new(f: F) -> Box<Self> {
Box::new(Self { f }) Box::new(Self {
f,
_phantom: PhantomPinned,
})
}
pub fn into_inner(self) -> F {
self.f
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn into_boxed_job<T>(self: Box<Self>) -> Box<Job<()>> pub fn into_boxed_job<T>(self: Box<Self>) -> Pin<Box<Job<()>>>
where where
F: FnOnce(&super::Scope) -> T + Send, F: FnOnce(&super::Scope) -> T + Send,
T: Send, T: Send,
@ -824,13 +831,12 @@ mod job {
let this = unsafe { Box::from_raw(this.cast::<HeapJob<F>>().cast_mut()) }; let this = unsafe { Box::from_raw(this.cast::<HeapJob<F>>().cast_mut()) };
let f = this.f; let f = this.f;
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(scope))); _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(scope)));
let job = unsafe { &*job.cast::<Job<T>>() }; _ = unsafe { Box::from_raw(job.cast_mut()) };
job.complete(result);
} }
Box::new(Job::new(harness::<F, T>, unsafe { Box::pin(Job::new(harness::<F, T>, unsafe {
NonNull::new_unchecked(Box::into_raw(self)).cast() NonNull::new_unchecked(Box::into_raw(self)).cast()
})) }))
} }