S2: decode Session uses RefCell and Cell instead of Mutex and AtomicBool; the poison branches go with the lock
Browse files at this commit61fc29d11c42919934f64a6a6c5a853974838073Parent: 6b476c51 changed file +9 -16
- crates/ec-hw/src/dec/mod.rs +9 -16
crates/ec-hw/src/dec/mod.rsmodified+9 -16
| @@ -19,7 +19,6 @@ | |||
| 19 | 19 | ||
| 20 | use std::collections::VecDeque; | 20 | use std::collections::VecDeque; |
| 21 | use std::rc::Rc; | 21 | use std::rc::Rc; |
| 22 | -use std::sync::atomic::Ordering; | ||
| 23 | use std::time::{Duration, Instant}; | 22 | use std::time::{Duration, Instant}; |
| 24 | 23 | ||
| 25 | use ec_va::caps::{Entrypoint, Profile}; | 24 | use ec_va::caps::{Entrypoint, Profile}; |
| @@ -264,12 +263,12 @@ pub(crate) struct Session { | |||
| 264 | born_epoch: u64, | 263 | born_epoch: u64, |
| 265 | /// The last submitted picture, waited for after the next one is submitted | 264 | /// The last submitted picture, waited for after the next one is submitted |
| 266 | /// (depth-1 pipelining; see [`Session::submit`]). | 265 | /// (depth-1 pipelining; see [`Session::submit`]). |
| 267 | - pending: std::sync::Mutex<Option<Pending>>, | 266 | + pending: std::cell::RefCell<Option<Pending>>, |
| 268 | /// Set once a picture hung or lost the GPU context. Every submission after | 267 | /// Set once a picture hung or lost the GPU context. Every submission after |
| 269 | /// that is refused: on Mesa, submitting to a context the kernel has reset | 268 | /// that is refused: on Mesa, submitting to a context the kernel has reset |
| 270 | /// aborts the whole process from the driver's own thread, which no | 269 | /// aborts the whole process from the driver's own thread, which no |
| 271 | /// `catch_unwind` can stop. | 270 | /// `catch_unwind` can stop. |
| 272 | - pub(crate) poisoned: std::sync::atomic::AtomicBool, | 271 | + pub(crate) poisoned: std::cell::Cell<bool>, |
| 273 | pub(crate) context: Rc<Context>, | 272 | pub(crate) context: Rc<Context>, |
| 274 | display: Rc<Display>, | 273 | display: Rc<Display>, |
| 275 | /// The readback image every frame of this stream reuses. | 274 | /// The readback image every frame of this stream reuses. |
| @@ -363,8 +362,8 @@ impl Session { | |||
| 363 | } | 362 | } |
| 364 | Ok(Session { | 363 | Ok(Session { |
| 365 | born_epoch, | 364 | born_epoch, |
| 366 | - pending: std::sync::Mutex::new(None), | 365 | + pending: std::cell::RefCell::new(None), |
| 367 | - poisoned: std::sync::atomic::AtomicBool::new(false), | 366 | + poisoned: std::cell::Cell::new(false), |
| 368 | context, | 367 | context, |
| 369 | display: Rc::clone(display), | 368 | display: Rc::clone(display), |
| 370 | pool, | 369 | pool, |
| @@ -416,7 +415,8 @@ impl Session { | |||
| 416 | // An old pending picture is waited for first: its wait is instant when | 415 | // An old pending picture is waited for first: its wait is instant when |
| 417 | // it is done, and an error condemns the session before we submit. | 416 | // it is done, and an error condemns the session before we submit. |
| 418 | let stale = self | 417 | let stale = self |
| 419 | - .pending_slot() | 418 | + .pending |
| 419 | + .borrow() | ||
| 420 | .as_ref() | 420 | .as_ref() |
| 421 | .filter(|p| p.since.elapsed() > IDLE_SETTLE) | 421 | .filter(|p| p.since.elapsed() > IDLE_SETTLE) |
| 422 | .map(|p| Rc::clone(&p.surface)); | 422 | .map(|p| Rc::clone(&p.surface)); |
| @@ -443,7 +443,7 @@ impl Session { | |||
| 443 | } | 443 | } |
| 444 | return Err(e.into()); | 444 | return Err(e.into()); |
| 445 | } | 445 | } |
| 446 | - let previous = self.pending_slot().replace(Pending { | 446 | + let previous = self.pending.borrow_mut().replace(Pending { |
| 447 | surface: Rc::clone(target), | 447 | surface: Rc::clone(target), |
| 448 | since: Instant::now(), | 448 | since: Instant::now(), |
| 449 | }); | 449 | }); |
| @@ -453,27 +453,20 @@ impl Session { | |||
| 453 | Ok(()) | 453 | Ok(()) |
| 454 | } | 454 | } |
| 455 | 455 | ||
| 456 | - fn pending_slot(&self) -> std::sync::MutexGuard<'_, Option<Pending>> { | ||
| 457 | - match self.pending.lock() { | ||
| 458 | - Ok(slot) => slot, | ||
| 459 | - Err(poisoned) => poisoned.into_inner(), | ||
| 460 | - } | ||
| 461 | - } | ||
| 462 | - | ||
| 463 | fn check_alive(&self) -> Result<()> { | 456 | fn check_alive(&self) -> Result<()> { |
| 464 | if crate::reset::gpu_reset_epoch() != self.born_epoch { | 457 | if crate::reset::gpu_reset_epoch() != self.born_epoch { |
| 465 | return Err(Error::hw_reset( | 458 | return Err(Error::hw_reset( |
| 466 | "the GPU was reset after this session was created; its context is lost", | 459 | "the GPU was reset after this session was created; its context is lost", |
| 467 | )); | 460 | )); |
| 468 | } | 461 | } |
| 469 | - if self.poisoned.load(Ordering::Acquire) { | 462 | + if self.poisoned.get() { |
| 470 | return Err(Error::poisoned("an earlier picture failed on the GPU")); | 463 | return Err(Error::poisoned("an earlier picture failed on the GPU")); |
| 471 | } | 464 | } |
| 472 | Ok(()) | 465 | Ok(()) |
| 473 | } | 466 | } |
| 474 | 467 | ||
| 475 | fn poison(&self) { | 468 | fn poison(&self) { |
| 476 | - if !self.poisoned.swap(true, Ordering::AcqRel) { | 469 | + if !self.poisoned.replace(true) { |
| 477 | crate::reset::report_gpu_reset(); | 470 | crate::reset::report_gpu_reset(); |
| 478 | } | 471 | } |
| 479 | } | 472 | } |