mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
use OnceLock instead of RwLock for SERVICES
It actually has the semantics we need. Until we get rid of SERVICES.
This commit is contained in:
parent
032e1ca3c6
commit
ad37eae869
1 changed files with 7 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
sync::{Arc, Mutex as StdMutex, RwLock as StdRwLock},
|
||||
sync::{Arc, Mutex as StdMutex, OnceLock},
|
||||
};
|
||||
|
||||
use lru_cache::LruCache;
|
||||
|
|
@ -22,14 +22,11 @@ pub(crate) mod transaction_ids;
|
|||
pub(crate) mod uiaa;
|
||||
pub(crate) mod users;
|
||||
|
||||
static SERVICES: StdRwLock<Option<&'static Services>> = StdRwLock::new(None);
|
||||
static SERVICES: OnceLock<&'static Services> = OnceLock::new();
|
||||
|
||||
/// Convenient access to the global [`Services`] instance
|
||||
pub(crate) fn services() -> &'static Services {
|
||||
SERVICES
|
||||
.read()
|
||||
.unwrap()
|
||||
.expect("SERVICES should be initialized when this is called")
|
||||
SERVICES.get().expect("`Services::install` should have been called first")
|
||||
}
|
||||
|
||||
pub(crate) struct Services {
|
||||
|
|
@ -166,7 +163,10 @@ impl Services {
|
|||
|
||||
/// Installs `self` to be globally accessed via [`services`]
|
||||
pub(crate) fn install(self) {
|
||||
*SERVICES.write().unwrap() = Some(Box::leak(Box::new(self)));
|
||||
assert!(
|
||||
SERVICES.set(Box::leak(Box::new(self))).is_ok(),
|
||||
"Services::install was called more than once"
|
||||
);
|
||||
}
|
||||
|
||||
async fn memory_usage(&self) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue