1use std::{collections::BTreeSet, sync::Arc};
6
7use crate::sync::*;
8use crate::trace_lock;
9
10pub struct Runtime {
13 running_components: Arc<Mutex<BTreeSet<String>>>,
16}
17
18impl Default for Runtime {
19 fn default() -> Self {
20 Self {
21 running_components: Arc::new(Mutex::new(BTreeSet::new())),
22 }
23 }
24}
25
26impl Runtime {
27 pub fn components(&self) -> Vec<String> {
28 let running_components = trace_lock!(self.running_components);
29 running_components.iter().cloned().collect()
30 }
31
32 pub fn register_component(&self, key: &str) {
33 debug!("registering component {}", key);
34 let mut running_components = trace_lock!(self.running_components);
35 if running_components.contains(key) {
36 trace!("Shouldn't be registering component {} more than once", key);
37 } else {
38 running_components.insert(key.to_string());
39 }
40 }
41
42 pub fn deregister_component(&self, key: &str) {
43 debug!("deregistering component {}", key);
44 let mut running_components = trace_lock!(self.running_components);
45 if !running_components.contains(key) {
46 trace!(
47 "Shouldn't be deregistering component {} which doesn't exist",
48 key
49 );
50 } else {
51 running_components.remove(key);
52 }
53 }
54}