xmtp_mls_core/
mutex_registry.rs1use std::{collections::HashMap, sync::Arc};
2
3use tokio::sync::Mutex;
4use xmtp_proto::types::GroupId;
5
6#[derive(Debug, Clone, Default)]
8pub struct MutexRegistry {
9 mutexes: HashMap<GroupId, Arc<Mutex<()>>>,
10}
11
12impl MutexRegistry {
13 pub fn new() -> Self {
14 Self {
15 mutexes: HashMap::new(),
16 }
17 }
18
19 pub fn get_mutex(&mut self, key: GroupId) -> Arc<Mutex<()>> {
20 self.mutexes
21 .entry(key)
22 .or_insert_with(|| Arc::new(Mutex::new(())))
23 .clone()
24 }
25}