refactor(core): remove dashmap

This commit is contained in:
Nova
2023-09-28 01:30:26 -04:00
parent ee8f789f74
commit 7095e1df84
4 changed files with 14 additions and 32 deletions

14
Cargo.lock generated
View File

@@ -530,19 +530,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "dashmap"
version = "5.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
dependencies = [
"cfg-if",
"hashbrown 0.14.0",
"lock_api",
"once_cell",
"parking_lot_core 0.9.8",
]
[[package]] [[package]]
name = "directories" name = "directories"
version = "5.0.1" version = "5.0.1"
@@ -2086,7 +2073,6 @@ dependencies = [
"clap", "clap",
"color-eyre", "color-eyre",
"console-subscriber", "console-subscriber",
"dashmap",
"directories", "directories",
"glam 0.23.0", "glam 0.23.0",
"global_counter", "global_counter",

View File

@@ -39,7 +39,6 @@ lto = true
[dependencies] [dependencies]
color-eyre = { version = "0.6.2", default-features = false } color-eyre = { version = "0.6.2", default-features = false }
clap = { version = "4.2.4", features = ["derive"] } clap = { version = "4.2.4", features = ["derive"] }
dashmap = "5.4.0"
glam = { version = "0.23.0", features = ["mint"] } glam = { version = "0.23.0", features = ["mint"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
mint = "0.5.9" mint = "0.5.9"

View File

@@ -2,6 +2,8 @@ use crate::nodes::Node;
use crate::{core::client::Client, nodes::Message}; use crate::{core::client::Client, nodes::Message};
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use stardust_xr::scenegraph; use stardust_xr::scenegraph;
use stardust_xr::scenegraph::ScenegraphError; use stardust_xr::scenegraph::ScenegraphError;
use std::os::fd::OwnedFd; use std::os::fd::OwnedFd;
@@ -9,14 +11,10 @@ use std::sync::{Arc, Weak};
use tokio::sync::oneshot; use tokio::sync::oneshot;
use tracing::{debug, debug_span, instrument}; use tracing::{debug, debug_span, instrument};
use core::hash::BuildHasherDefault;
use dashmap::DashMap;
use rustc_hash::FxHasher;
#[derive(Default)] #[derive(Default)]
pub struct Scenegraph { pub struct Scenegraph {
pub(super) client: OnceCell<Weak<Client>>, pub(super) client: OnceCell<Weak<Client>>,
nodes: DashMap<String, Arc<Node>, BuildHasherDefault<FxHasher>>, nodes: Mutex<FxHashMap<String, Arc<Node>>>,
} }
impl Scenegraph { impl Scenegraph {
@@ -32,12 +30,12 @@ impl Scenegraph {
pub fn add_node_raw(&self, node: Arc<Node>) { pub fn add_node_raw(&self, node: Arc<Node>) {
debug!(node = ?&*node, "Add node"); debug!(node = ?&*node, "Add node");
let path = node.get_path().to_string(); let path = node.get_path().to_string();
self.nodes.insert(path, node); self.nodes.lock().insert(path, node);
} }
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> { pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
let mut node = self.nodes.get(path)?.clone(); let mut node = self.nodes.lock().get(path)?.clone();
while let Some(alias) = node.alias.get() { while let Some(alias) = node.alias.get() {
node = alias.original.upgrade()?; node = alias.original.upgrade()?;
} }
@@ -46,8 +44,7 @@ impl Scenegraph {
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> { pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
debug!(path, "Remove node"); debug!(path, "Remove node");
let (_, node) = self.nodes.remove(path)?; self.nodes.lock().remove(path)
Some(node)
} }
} }

View File

@@ -11,13 +11,11 @@ pub mod spatial;
pub mod startup; pub mod startup;
use color_eyre::eyre::{eyre, Result}; use color_eyre::eyre::{eyre, Result};
use core::hash::BuildHasherDefault;
use dashmap::DashMap;
use nanoid::nanoid; use nanoid::nanoid;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
use portable_atomic::{AtomicBool, Ordering}; use portable_atomic::{AtomicBool, Ordering};
use rustc_hash::FxHasher; use rustc_hash::FxHashMap;
use stardust_xr::messenger::MessageSenderHandle; use stardust_xr::messenger::MessageSenderHandle;
use stardust_xr::scenegraph::ScenegraphError; use stardust_xr::scenegraph::ScenegraphError;
use stardust_xr::schemas::flex::deserialize; use stardust_xr::schemas::flex::deserialize;
@@ -70,8 +68,8 @@ pub struct Node {
client: Weak<Client>, client: Weak<Client>,
message_sender_handle: Option<MessageSenderHandle>, message_sender_handle: Option<MessageSenderHandle>,
// trailing_slash_pos: usize, // trailing_slash_pos: usize,
local_signals: DashMap<String, Signal, BuildHasherDefault<FxHasher>>, local_signals: Mutex<FxHashMap<String, Signal>>,
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>, local_methods: Mutex<FxHashMap<String, Method>>,
destroyable: bool, destroyable: bool,
pub alias: OnceCell<Arc<Alias>>, pub alias: OnceCell<Arc<Alias>>,
@@ -198,10 +196,10 @@ impl Node {
} }
pub fn add_local_signal(&self, name: &str, signal: Signal) { pub fn add_local_signal(&self, name: &str, signal: Signal) {
self.local_signals.insert(name.to_string(), signal); self.local_signals.lock().insert(name.to_string(), signal);
} }
pub fn add_local_method(&self, name: &str, method: Method) { pub fn add_local_method(&self, name: &str, method: Method) {
self.local_methods.insert(name.to_string(), method); self.local_methods.lock().insert(name.to_string(), method);
} }
pub fn get_aspect<F, T>( pub fn get_aspect<F, T>(
@@ -236,7 +234,9 @@ impl Node {
} else { } else {
let signal = self let signal = self
.local_signals .local_signals
.lock()
.get(method) .get(method)
.cloned()
.ok_or(ScenegraphError::SignalNotFound)?; .ok_or(ScenegraphError::SignalNotFound)?;
signal(self, calling_client, message).map_err(|error| ScenegraphError::SignalError { signal(self, calling_client, message).map_err(|error| ScenegraphError::SignalError {
error: error.to_string(), error: error.to_string(),
@@ -269,7 +269,7 @@ impl Node {
response, response,
) )
} else { } else {
let Some(method) = self.local_methods.get(method) else { let Some(method) = self.local_methods.lock().get(method).cloned() else {
response.send(Err(ScenegraphError::MethodNotFound)); response.send(Err(ScenegraphError::MethodNotFound));
return; return;
}; };