chiark / gitweb /
Revert "locks: Make config an Option"
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 10 Apr 2021 17:15:14 +0000 (18:15 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 10 Apr 2021 17:15:14 +0000 (18:15 +0100)
There's no point to this unless it helps us get rid of the
lazy_static!  But it doesn't.

This reverts commit 79bf71d23437a33eaf4ce27f2d325d21508bb45e.

src/config.rs
src/global.rs
src/prelude.rs

index 38b7dab9e2469fe1b1909bb37d482e7ddc7245a1..cc6d129210fecd5a2895f4e7ad1da7efa0a31f89 100644 (file)
@@ -191,29 +191,15 @@ impl TryFrom<ServerConfigSpec> 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<ServerConfig> {
-  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 {
index 7093ceddb805b98620c89853aa198e68728eb483..0bf8a5355de2226ac96b869413acf4b8b7520ce3 100644 (file)
@@ -206,7 +206,7 @@ pub struct Global {
   // <- InstanceContainer ->
   // inner locks which the game needs:
   dirty: Mutex<VecDeque<InstanceRef>>,
-  pub config: RwLock<Option<WholeServerConfig>>,
+  pub config: RwLock<WholeServerConfig>,
 
   // fast global lookups
   players: RwLock<TokenTable<PlayerId>>,
index 1a1747c660fbf7ab2df8dbf56d244dabd1f9e270..829aad36dccfaaefbe8a8b0235f8026d5c82abd7 100644 (file)
@@ -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;