diff --git a/src/admin/mod.rs b/src/admin/mod.rs index 2de42420..f2e35d80 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -36,13 +36,18 @@ pub async fn init() { .write() .expect("locked for writing") .insert(handler::complete); - _ = services().admin.handle.lock().await.insert(handler::handle); + _ = services() + .admin + .handle + .write() + .await + .insert(handler::handle); } /// Uninstall the admin command handler #[allow(clippy::let_underscore_must_use)] pub async fn fini() { - _ = services().admin.handle.lock().await.take(); + _ = services().admin.handle.write().await.take(); _ = services() .admin .complete diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index d01a6f55..ca0e551b 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -21,7 +21,10 @@ use ruma::{ OwnedEventId, OwnedRoomId, RoomId, UserId, }; use serde_json::value::to_raw_value; -use tokio::{sync::Mutex, task::JoinHandle}; +use tokio::{ + sync::{Mutex, RwLock}, + task::JoinHandle, +}; use crate::{pdu::PduBuilder, services, user_is_local, PduEvent}; @@ -37,7 +40,7 @@ pub struct Service { sender: Sender, receiver: Mutex>, handler_join: Mutex>>, - pub handle: Mutex>, + pub handle: RwLock>, pub complete: StdRwLock>, #[cfg(feature = "console")] pub console: Arc, @@ -57,7 +60,7 @@ impl crate::Service for Service { sender, receiver: Mutex::new(receiver), handler_join: Mutex::new(None), - handle: Mutex::new(None), + handle: RwLock::new(None), complete: StdRwLock::new(None), #[cfg(feature = "console")] console: console::Console::new(), @@ -175,7 +178,7 @@ impl Service { } async fn process_command(&self, command: Command) -> CommandResult { - if let Some(handle) = self.handle.lock().await.as_ref() { + if let Some(handle) = self.handle.read().await.as_ref() { handle(command).await } else { Err(Error::Err("Admin module is not loaded.".into()))