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