wrap Mutex and Condvar to handle poison

This centralizes a major source of `.unwrap()` throughout the code,
and one that would otherwise grow with upcoming changes. The new
error message should be more clear.
This commit is contained in:
Scott Lamb
2025-04-03 08:36:56 -07:00
parent 2903b680df
commit 0ccc6d0769
8 changed files with 120 additions and 62 deletions

View File

@@ -7,8 +7,8 @@
//! Note these types are in a more standard nanosecond-based format, where
//! [`crate::time`] uses Moonfire's 90 kHz time base.
use crate::Mutex;
use nix::sys::time::{TimeSpec, TimeValLike as _};
use std::sync::Mutex;
use std::sync::{mpsc, Arc};
use std::thread;
pub use std::time::Duration;
@@ -220,15 +220,15 @@ impl SimulatedClocks {
impl Clocks for SimulatedClocks {
fn realtime(&self) -> SystemTime {
self.0.boot + *self.0.uptime.lock().unwrap()
self.0.boot + *self.0.uptime.lock()
}
fn monotonic(&self) -> Instant {
Instant(TimeSpec::from(*self.0.uptime.lock().unwrap()))
Instant(TimeSpec::from(*self.0.uptime.lock()))
}
/// Advances the clock by the specified amount without actually sleeping.
fn sleep(&self, how_long: Duration) {
let mut l = self.0.uptime.lock().unwrap();
let mut l = self.0.uptime.lock();
*l += how_long;
}