Make all nodes thread safe

This commit is contained in:
Nova
2022-06-14 19:34:27 -04:00
parent 651fa5f012
commit 3aa691475c
6 changed files with 182 additions and 207 deletions

View File

@@ -2,7 +2,7 @@ use super::core::Node;
use crate::core::registry::Registry;
use anyhow::{ensure, Result};
use lazy_static::lazy_static;
use rccell::RcCell;
use std::sync::Arc;
lazy_static! {
static ref PULSE_SENDER_REGISTRY: Registry<PulseSender> = Default::default();
@@ -11,15 +11,15 @@ lazy_static! {
pub struct PulseSender {}
impl PulseSender {
pub fn add_to(node: &RcCell<Node>) -> Result<()> {
pub fn add_to(node: &Arc<Node>) -> Result<()> {
ensure!(
node.borrow().spatial.is_some(),
node.spatial.read().is_some(),
"Internal: Node does not have a spatial attached!"
);
let sender = PulseSender {};
let sender = PULSE_SENDER_REGISTRY.add(sender)?;
node.borrow_mut().pulse_sender = Some(sender);
*node.pulse_sender.write() = Some(sender);
Ok(())
}
}