rusticl/queue: add a life check to prevent applications dead locking

Cc: mesa-stable
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32821>
This commit is contained in:
Karol Herbst
2024-12-23 13:17:25 +01:00
committed by Marge Bot
parent f70ef03100
commit ccfeda77bd
2 changed files with 14 additions and 2 deletions

View File

@@ -212,6 +212,14 @@ impl Event {
.wait_timeout(lock, Duration::from_secs(1))
.unwrap()
.0;
if let Some(queue) = &self.queue {
// in case the queue worker thread exited abnormally we'll need to stop spinning on
// the cv here, because otherwise we'll end up spinning endlessly.
if queue.is_dead() {
return CL_OUT_OF_HOST_MEMORY;
}
}
}
lock.status
}

View File

@@ -88,7 +88,7 @@ pub struct Queue {
pub props: cl_command_queue_properties,
pub props_v2: Properties<cl_queue_properties>,
state: Mutex<QueueState>,
_thrd: JoinHandle<()>,
thrd: JoinHandle<()>,
}
impl_cl_type_trait!(cl_command_queue, Queue, CL_INVALID_COMMAND_QUEUE);
@@ -122,7 +122,7 @@ impl Queue {
last: Weak::new(),
chan_in: tx_q,
}),
_thrd: thread::Builder::new()
thrd: thread::Builder::new()
.name("rusticl queue thread".into())
.spawn(move || {
// Track the error of all executed events. This is only needed for in-order
@@ -250,6 +250,10 @@ impl Queue {
Ok(())
}
pub fn is_dead(&self) -> bool {
self.thrd.is_finished()
}
pub fn is_profiling_enabled(&self) -> bool {
(self.props & (CL_QUEUE_PROFILING_ENABLE as u64)) != 0
}