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

Cc: mesa-stable
Reviewed-by: Adam Jackson <ajax@redhat.com>
(cherry picked from commit ccfeda77bd)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33113>
This commit is contained in:
Karol Herbst
2024-12-23 13:17:25 +01:00
committed by Dylan Baker
parent ded1ec58f7
commit 32a93c197e
3 changed files with 15 additions and 3 deletions

View File

@@ -104,7 +104,7 @@
"description": "rusticl/queue: add a life check to prevent applications dead locking",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

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: Option<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
}