diff options
| -rw-r--r-- | Cargo.lock | 49 | ||||
| -rw-r--r-- | ecs/Cargo.toml | 1 | ||||
| -rw-r--r-- | ecs/src/lock.rs | 19 | ||||
| -rw-r--r-- | ecs/src/system.rs | 7 | 
4 files changed, 60 insertions, 16 deletions
@@ -232,6 +232,7 @@ dependencies = [   "ecs-macros",   "hashbrown 0.15.2",   "linkme", + "parking_lot",   "paste",   "seq-macro",   "thiserror", @@ -493,6 +494,16 @@ dependencies = [  ]  [[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]]  name = "log"  version = "0.4.20"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -598,6 +609,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"  [[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]]  name = "paste"  version = "1.0.14"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -647,6 +681,15 @@ dependencies = [  ]  [[package]] +name = "redox_syscall" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" +dependencies = [ + "bitflags 2.4.0", +] + +[[package]]  name = "regex"  version = "1.9.6"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -712,6 +755,12 @@ dependencies = [  ]  [[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]]  name = "seq-macro"  version = "0.3.5"  source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/ecs/Cargo.toml b/ecs/Cargo.toml index 738998f..4945171 100644 --- a/ecs/Cargo.toml +++ b/ecs/Cargo.toml @@ -10,6 +10,7 @@ thiserror = "1.0.49"  tracing = "0.1.39"  linkme = "0.3.29"  hashbrown = "0.15.2" +parking_lot = "0.12.3"  ecs-macros = { path = "../ecs-macros" }  util-macros = { path = "../util-macros" } diff --git a/ecs/src/lock.rs b/ecs/src/lock.rs index bc5351f..74b0415 100644 --- a/ecs/src/lock.rs +++ b/ecs/src/lock.rs @@ -1,6 +1,7 @@  use std::mem::transmute;  use std::ops::{Deref, DerefMut}; -use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard, TryLockError}; + +use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};  use crate::type_name::TypeName; @@ -27,10 +28,8 @@ where      /// Returns `Err` if unavailable (A mutable handle is hold).      pub fn read_nonblock(&self) -> Result<ReadGuard<Value>, Error>      { -        let guard = self.inner.try_read().or_else(|err| match err { -            TryLockError::WouldBlock => Err(Error::ReadUnavailable), -            TryLockError::Poisoned(poison_err) => Ok(poison_err.into_inner()), -        })?; +        let guard = self.inner.try_read().ok_or(Error::ReadUnavailable)?; +          tracing::trace!("Acquired lock to value of type {}", guard.type_name());          Ok(ReadGuard { inner: guard }) @@ -42,10 +41,8 @@ where      /// Returns `Err` if unavailable (A mutable or immutable handle is hold).      pub fn write_nonblock(&self) -> Result<WriteGuard<Value>, Error>      { -        let guard = self.inner.try_write().or_else(|err| match err { -            TryLockError::WouldBlock => Err(Error::WriteUnavailable), -            TryLockError::Poisoned(poison_err) => Ok(poison_err.into_inner()), -        })?; +        let guard = self.inner.try_write().ok_or(Error::WriteUnavailable)?; +          tracing::trace!(              "Acquired mutable lock to value of type {}",              guard.type_name() @@ -56,9 +53,7 @@ where      pub fn into_inner(self) -> Value      { -        self.inner -            .into_inner() -            .unwrap_or_else(PoisonError::into_inner) +        self.inner.into_inner()      }  } diff --git a/ecs/src/system.rs b/ecs/src/system.rs index a810741..48c2723 100644 --- a/ecs/src/system.rs +++ b/ecs/src/system.rs @@ -3,7 +3,6 @@ use std::convert::Infallible;  use std::fmt::Debug;  use std::marker::PhantomData;  use std::ops::{Deref, DerefMut}; -use std::panic::{RefUnwindSafe, UnwindSafe};  use ecs_macros::Component;  use seq_macro::seq; @@ -49,7 +48,7 @@ macro_rules! impl_system {              impl<'world, Func, #(TParam~I,)*> System<'world, fn(#(TParam~I,)*)>                  for Func              where -                Func: Fn(#(TParam~I,)*) + Copy + RefUnwindSafe + UnwindSafe + 'static, +                Func: Fn(#(TParam~I,)*) + Copy + 'static,                  #(TParam~I: Param<'world, Input = ()>,)*              {                  type Input = Infallible; @@ -123,7 +122,7 @@ pub trait Into<Impl>  pub struct TypeErased  { -    data: Box<dyn Any + RefUnwindSafe + UnwindSafe>, +    data: Box<dyn Any>,      run: Box<TypeErasedRunFn>,  } @@ -151,7 +150,7 @@ impl Debug for TypeErased  }  /// Function in [`TypeErased`] used to run the system. -type TypeErasedRunFn = dyn Fn(&dyn Any, &World) + RefUnwindSafe + UnwindSafe; +type TypeErasedRunFn = dyn Fn(&dyn Any, &World);  /// A parameter to a [`System`].  pub trait Param<'world>  | 
