Commit 2e063426 authored by Roman Alifanov's avatar Roman Alifanov

Add mutex to serialize concurrent Update calls

parent df572398
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio::sync::{Mutex, RwLock};
use zbus::{interface, Connection};
use crate::config::Config;
......@@ -14,11 +14,12 @@ fn to_json<T: serde::Serialize>(data: &T) -> zbus::fdo::Result<String> {
pub struct QueryInterface {
config: Arc<RwLock<Config>>,
connection: Connection,
update_lock: Mutex<()>,
}
impl QueryInterface {
pub fn new(config: Arc<RwLock<Config>>, connection: Connection) -> Self {
Self { config, connection }
Self { config, connection, update_lock: Mutex::new(()) }
}
}
......@@ -105,6 +106,8 @@ impl QueryInterface {
}
async fn update(&self, transaction: String) -> zbus::fdo::Result<String> {
let _guard = self.update_lock.lock().await;
let config = self.config.read().await;
let signal_emitter = SignalEmitter::new(self.connection.clone());
let tx = if transaction.is_empty() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment