Avoid a deadlock in Device::lose (#5197)

This commit is contained in:
Nicolas Silva 2024-02-05 16:01:05 +01:00 committed by GitHub
parent 563d9202c3
commit 4da46f35ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3362,9 +3362,11 @@ impl<A: HalApi> Device<A> {
// 1) Resolve the GPUDevice device.lost promise.
let mut life_lock = self.lock_life();
let closure = life_lock.device_lost_closure.take();
// It's important to not hold the lock while calling the closure and while calling
// release_gpu_resources which may take the lock again.
drop(life_lock);
if let Some(device_lost_closure) = closure {
// It's important to not hold the lock while calling the closure.
drop(life_lock);
device_lost_closure.call(DeviceLostReason::Unknown, message.to_string());
}