From 6fe4be0b3c21c9e79069953cb6675dcdbf862eef Mon Sep 17 00:00:00 2001 From: Dhanuka Warusadura Date: Wed, 21 Feb 2024 16:13:43 +0530 Subject: [PATCH] Updates ServiceManager Removed RwLock wrapper from sessions Removed async from all the methods See: https://github.com/bilelmoussaoui/oo7/pull/73#discussion_r1497239325 Signed-off-by: Dhanuka Warusadura --- server/src/daemon/service_manager.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/server/src/daemon/service_manager.rs b/server/src/daemon/service_manager.rs index f127d4f13..c6870e88a 100644 --- a/server/src/daemon/service_manager.rs +++ b/server/src/daemon/service_manager.rs @@ -1,36 +1,30 @@ use std::collections::HashMap; -use tokio::sync::RwLock; use zbus::zvariant::{ObjectPath, OwnedObjectPath}; use super::session::Session; #[derive(Debug)] pub struct ServiceManager { - sessions: RwLock>, + sessions: HashMap, } impl ServiceManager { pub fn new() -> Self { Self { - sessions: RwLock::new(HashMap::new()), + sessions: HashMap::new(), } } - pub async fn session(&self, path: ObjectPath<'_>) -> Option { - self.sessions - .read() - .await - .get(&path.into()) - .to_owned() - .cloned() + pub fn session(&self, path: ObjectPath<'_>) -> Option { + self.sessions.get(&path.into()).to_owned().cloned() } - pub async fn insert_session(&mut self, path: ObjectPath<'_>, session: Session) { - self.sessions.write().await.insert(path.into(), session); + pub fn insert_session(&mut self, path: ObjectPath<'_>, session: Session) { + self.sessions.insert(path.into(), session); } - pub async fn remove_session(&mut self, path: ObjectPath<'_>) { - self.sessions.write().await.remove(&path.into()); + pub fn remove_session(&mut self, path: ObjectPath<'_>) { + self.sessions.remove(&path.into()); } }