fix(client): turn Rc into Arc

This commit is contained in:
Nova
2022-06-14 21:02:05 -04:00
parent 3421fa84af
commit 46a1581e1b
6 changed files with 33 additions and 37 deletions

View File

@@ -3,7 +3,7 @@ use crate::nodes::field;
use crate::nodes::spatial;
use libstardustxr::messenger::Messenger;
use mio::net::UnixStream;
use std::rc::Rc;
use std::sync::Arc;
pub struct Client {
pub messenger: Messenger,
@@ -11,8 +11,8 @@ pub struct Client {
}
impl Client {
pub fn from_connection(connection: UnixStream) -> Rc<Self> {
let client = Rc::new(Client {
pub fn from_connection(connection: UnixStream) -> Arc<Self> {
let client = Arc::new(Client {
messenger: Messenger::new(connection),
scenegraph: Default::default(),
});

View File

@@ -6,7 +6,7 @@ use mio::unix::pipe;
use mio::{Events, Interest, Poll, Token};
use slab::Slab;
use std::io::Write;
use std::rc::Rc;
use std::sync::Arc;
use std::thread::{self, JoinHandle};
pub struct EventLoop {
@@ -24,7 +24,7 @@ impl EventLoop {
let join_handle = thread::Builder::new()
.name("event_loop".to_owned())
.spawn(move || -> Result<()> {
let mut clients: Slab<Option<Rc<Client>>> = Slab::new();
let mut clients: Slab<Option<Arc<Client>>> = Slab::new();
let mut poll = Poll::new()?;
let mut events = Events::with_capacity(1024);
const LISTENER: Token = Token(usize::MAX - 1);

View File

@@ -4,8 +4,7 @@ use anyhow::Result;
use libstardustxr::scenegraph;
use libstardustxr::scenegraph::ScenegraphError;
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use std::sync::Arc;
use std::sync::{Arc, Weak};
use core::hash::BuildHasherDefault;
use dashmap::DashMap;
@@ -18,17 +17,17 @@ pub struct Scenegraph {
}
impl Scenegraph {
pub fn get_client(&self) -> Rc<Client> {
pub fn get_client(&self) -> Arc<Client> {
self.client.borrow().upgrade().unwrap()
}
pub fn set_client(&self, client: &Rc<Client>) {
*self.client.borrow_mut() = Rc::downgrade(client);
pub fn set_client(&self, client: &Arc<Client>) {
*self.client.borrow_mut() = Arc::downgrade(client);
}
pub fn add_node(&self, node: Node) -> Arc<Node> {
let mut node = node;
node.client = Rc::downgrade(&self.get_client());
node.client = Arc::downgrade(&self.get_client());
let path = node.get_path().to_string();
let node_arc = Arc::new(node);
self.nodes.insert(path, node_arc.clone());