From: Ian Jackson Date: Sat, 1 May 2021 12:19:04 +0000 (+0100) Subject: global: Introduce InstanceOuter X-Git-Tag: otter-0.6.0~495 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0f50fa98531d2297232248b9226376fc79113a25;p=otter.git global: Introduce InstanceOuter This will let us put bundle information within a separate lock. Signed-off-by: Ian Jackson --- diff --git a/src/global.rs b/src/global.rs index b561326d..cc247f42 100644 --- a/src/global.rs +++ b/src/global.rs @@ -28,10 +28,15 @@ pub struct InstanceName { } #[derive(Debug,Clone)] -pub struct InstanceRef (Arc>); +pub struct InstanceRef(Arc); #[derive(Debug,Clone)] -pub struct InstanceWeakRef (std::sync::Weak>); +pub struct InstanceWeakRef(std::sync::Weak); + +#[derive(Debug)] +pub struct InstanceOuter { + c: Mutex, +} #[derive(Debug,Clone,Serialize,Deserialize,Default)] #[serde(transparent)] @@ -271,13 +276,13 @@ impl Debug for Instance { impl InstanceRef { #[throws(GameBeingDestroyed)] pub fn lock(&self) -> InstanceGuard<'_> { - let c = self.0.lock(); + let c = self.0.c.lock(); if !c.live { throw!(GameBeingDestroyed) } InstanceGuard { c, gref: self.clone() } } pub fn lock_even_destroying(&self) -> MutexGuard { - self.0.lock() + self.0.c.lock() } pub fn downgrade_to_weak(&self) -> InstanceWeakRef { @@ -337,7 +342,7 @@ impl Instance { g, }; - let gref = InstanceRef(Arc::new(Mutex::new(cont))); + let gref = InstanceRef(Arc::new(InstanceOuter { c: Mutex::new(cont) })); let mut ig = gref.lock()?; let entry = games.entry(name); @@ -1122,7 +1127,7 @@ impl InstanceGuard<'_> { aux_dirty: false, g, }; - let gref = InstanceRef(Arc::new(Mutex::new(cont))); + let gref = InstanceRef(Arc::new(InstanceOuter { c: Mutex::new(cont) })); let mut g = gref.lock().unwrap(); let ig = &mut *g;