rusticl/core: don't take a lock while dropping Context

We have exclusive access in Drop, so we can use `get_mut` instead of having to `lock`.

Since that borrows `self` mutably but `call` also needs to borrow `self`, we `take` the Vec with
callbacks out of `self` so the mutable borrow can end before running `call`.

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-14 16:58:43 +02:00 committed by Marge Bot
parent 54c74164a8
commit 8b6b405a01

View file

@ -15,6 +15,7 @@ use std::alloc::Layout;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::convert::TryInto;
use std::mem;
use std::os::raw::c_void;
use std::sync::Arc;
use std::sync::Mutex;
@ -203,11 +204,9 @@ impl Context {
impl Drop for Context {
fn drop(&mut self) {
self.dtors
.lock()
.unwrap()
.drain(..)
.rev()
.for_each(|cb| cb.call(self));
let cbs = mem::take(self.dtors.get_mut().unwrap());
for cb in cbs.into_iter().rev() {
cb.call(self);
}
}
}