From 6b476c55bc81d8d8f5232459d0266d12bdca1151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 15:16:42 +0300 Subject: [PATCH] S2: SurfacePool uses RefCell; the pool is Rc-shared on one thread, so the Mutex poison branches were dead --- crates/ec-hw/src/pool.rs | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/crates/ec-hw/src/pool.rs b/crates/ec-hw/src/pool.rs index b795188b..1896c3ed 100644 --- a/crates/ec-hw/src/pool.rs +++ b/crates/ec-hw/src/pool.rs @@ -13,12 +13,12 @@ use ec_va::{Surface, SurfaceSpec}; use std::ops::Deref; use std::rc::{Rc, Weak}; -use std::sync::Mutex; +use std::cell::RefCell; struct PoolInner { /// Every surface, in allocation order. - all: Mutex>>, - free: Mutex>>, + all: RefCell>>, + free: RefCell>>, } /// A fixed-size pool of identically specified surfaces. @@ -36,8 +36,8 @@ impl SurfacePool { let all: Vec> = surfaces.into_iter().map(Rc::new).collect(); SurfacePool { inner: Rc::new(PoolInner { - free: Mutex::new(all.clone()), - all: Mutex::new(all), + free: RefCell::new(all.clone()), + all: RefCell::new(all), }), spec: *spec, } @@ -50,7 +50,7 @@ impl SurfacePool { /// Total surfaces in the pool. pub fn len(&self) -> usize { - self.inner.all.lock().map(|all| all.len()).unwrap_or(0) + self.inner.all.borrow().len() } /// True when the pool holds no surfaces at all. @@ -61,17 +61,13 @@ impl SurfacePool { /// Add surfaces allocated with the pool's spec, free for [`SurfacePool::acquire`]. pub fn grow(&self, surfaces: Vec) { let surfaces: Vec> = surfaces.into_iter().map(Rc::new).collect(); - if let Ok(mut all) = self.inner.all.lock() { - all.extend(surfaces.iter().cloned()); - } - if let Ok(mut free) = self.inner.free.lock() { - free.extend(surfaces); - } + self.inner.all.borrow_mut().extend(surfaces.iter().cloned()); + self.inner.free.borrow_mut().extend(surfaces); } /// Surfaces currently available. pub fn available(&self) -> usize { - self.inner.free.lock().map(|f| f.len()).unwrap_or(0) + self.inner.free.borrow().len() } /// Take a free surface, or `None` when every one is still in use. @@ -79,13 +75,7 @@ impl SurfacePool { /// A `None` is the caller's cue to release output frames, not an error: a /// decoder that has handed out its whole pool is waiting on the consumer. pub fn acquire(&self) -> Option> { - // A poisoned lock means another thread panicked while holding it; the - // free list is a plain Vec, so its contents are still consistent. - let mut free = match self.inner.free.lock() { - Ok(free) => free, - Err(poisoned) => poisoned.into_inner(), - }; - let surface = free.pop()?; + let surface = self.inner.free.borrow_mut().pop()?; Some(Rc::new(PooledSurface { surface, pool: Rc::downgrade(&self.inner), @@ -128,10 +118,6 @@ impl Drop for PooledSurface { // The pool is gone, so the surface simply drops with this handle. return; }; - let mut free = match pool.free.lock() { - Ok(free) => free, - Err(poisoned) => poisoned.into_inner(), - }; - free.push(Rc::clone(&self.surface)); + pool.free.borrow_mut().push(Rc::clone(&self.surface)); } }