agentmux_srv/backend/blockcontroller/
pidregistry.rs1use std::collections::HashMap;
9use std::sync::{LazyLock, RwLock};
10
11static BLOCK_PIDS: LazyLock<RwLock<HashMap<String, u32>>> =
12 LazyLock::new(|| RwLock::new(HashMap::new()));
13
14pub fn register(block_id: &str, pid: u32) {
15 BLOCK_PIDS.write().unwrap().insert(block_id.to_string(), pid);
16 tracing::debug!(block_id = %block_id, pid = pid, "pidregistry: registered");
17}
18
19pub fn unregister(block_id: &str) {
20 BLOCK_PIDS.write().unwrap().remove(block_id);
21 tracing::debug!(block_id = %block_id, "pidregistry: unregistered");
22}
23
24pub fn get_all() -> Vec<(String, u32)> {
25 BLOCK_PIDS
26 .read()
27 .unwrap()
28 .iter()
29 .map(|(k, v)| (k.clone(), *v))
30 .collect()
31}