From: Ian Jackson Date: Sat, 10 Apr 2021 17:15:14 +0000 (+0100) Subject: Revert "locks: Make config an Option" X-Git-Tag: otter-0.5.0~106 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1df6493f1ef2e673170d25714317386a2086ded7;p=otter.git Revert "locks: Make config an Option" There's no point to this unless it helps us get rid of the lazy_static! But it doesn't. This reverts commit 79bf71d23437a33eaf4ce27f2d325d21508bb45e. --- diff --git a/src/config.rs b/src/config.rs index 38b7dab9..cc6d1292 100644 --- a/src/config.rs +++ b/src/config.rs @@ -191,29 +191,15 @@ impl TryFrom for WholeServerConfig { } } -fn config_read() -> MappedRwLockReadGuard<'static, WholeServerConfig> { - { - let g = GLOBAL.config.read(); - let g = RwLockReadGuard::try_map(g, |g| g.as_ref()); - if let Ok(g) = g { return g } - } - { - let mut g = GLOBAL.config.write(); - g.get_or_insert_with(default); - let g = RwLockWriteGuard::downgrade(g); - RwLockReadGuard::try_map(g, |g| g.as_ref()).unwrap() - } -} - pub fn config() -> Arc { - config_read().server.clone() + GLOBAL.config.read().server.clone() } pub fn log_config() -> LogSpecification { - config_read().log.clone() + GLOBAL.config.read().log.clone() } fn set_config(whole: WholeServerConfig) { - *GLOBAL.config.write() = Some(whole); + *GLOBAL.config.write() = whole; } impl ServerConfig { diff --git a/src/global.rs b/src/global.rs index 7093cedd..0bf8a535 100644 --- a/src/global.rs +++ b/src/global.rs @@ -206,7 +206,7 @@ pub struct Global { // <- InstanceContainer -> // inner locks which the game needs: dirty: Mutex>, - pub config: RwLock>, + pub config: RwLock, // fast global lookups players: RwLock>, diff --git a/src/prelude.rs b/src/prelude.rs index 1a1747c6..829aad36 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -77,7 +77,6 @@ pub use num_traits::{Bounded, FromPrimitive, ToPrimitive}; pub use ordered_float::OrderedFloat; pub use parking_lot::{Condvar, Mutex, MutexGuard}; pub use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; -pub use parking_lot::{MappedRwLockReadGuard}; pub use percent_encoding::percent_decode_str; pub use percent_encoding::utf8_percent_encode; pub use percent_encoding::NON_ALPHANUMERIC;