Skip to content

Commit

Permalink
Update some internal fields from Rc to Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Aug 9, 2019
1 parent 5fbae86 commit 801339a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
9 changes: 5 additions & 4 deletions lib/runtime-core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::{
types::{GlobalDescriptor, Type, Value},
vm,
};
use std::{cell::RefCell, fmt, rc::Rc};
use std::sync::Arc;
use std::{cell::RefCell, fmt};

pub struct Global {
desc: GlobalDescriptor,
storage: Rc<RefCell<vm::LocalGlobal>>,
storage: Arc<RefCell<vm::LocalGlobal>>,
}

impl Global {
Expand Down Expand Up @@ -56,7 +57,7 @@ impl Global {

Self {
desc,
storage: Rc::new(RefCell::new(local_global)),
storage: Arc::new(RefCell::new(local_global)),
}
}

Expand Down Expand Up @@ -120,7 +121,7 @@ impl Clone for Global {
fn clone(&self) -> Self {
Self {
desc: self.desc,
storage: Rc::clone(&self.storage),
storage: Arc::clone(&self.storage),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions lib/runtime-core/src/import.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::export::Export;
use std::collections::VecDeque;
use std::collections::{hash_map::Entry, HashMap};
use std::sync::Arc;
use std::{
cell::{Ref, RefCell},
ffi::c_void,
rc::Rc,
};

pub trait LikeNamespace {
Expand Down Expand Up @@ -45,16 +45,16 @@ impl IsExport for Export {
/// }
/// ```
pub struct ImportObject {
map: Rc<RefCell<HashMap<String, Box<dyn LikeNamespace>>>>,
pub(crate) state_creator: Option<Rc<dyn Fn() -> (*mut c_void, fn(*mut c_void))>>,
map: Arc<RefCell<HashMap<String, Box<dyn LikeNamespace>>>>,
pub(crate) state_creator: Option<Arc<dyn Fn() -> (*mut c_void, fn(*mut c_void))>>,
pub allow_missing_functions: bool,
}

impl ImportObject {
/// Create a new `ImportObject`.
pub fn new() -> Self {
Self {
map: Rc::new(RefCell::new(HashMap::new())),
map: Arc::new(RefCell::new(HashMap::new())),
state_creator: None,
allow_missing_functions: false,
}
Expand All @@ -65,8 +65,8 @@ impl ImportObject {
F: Fn() -> (*mut c_void, fn(*mut c_void)) + 'static,
{
Self {
map: Rc::new(RefCell::new(HashMap::new())),
state_creator: Some(Rc::new(state_creator)),
map: Arc::new(RefCell::new(HashMap::new())),
state_creator: Some(Arc::new(state_creator)),
allow_missing_functions: false,
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ImportObject {

pub fn clone_ref(&self) -> Self {
Self {
map: Rc::clone(&self.map),
map: Arc::clone(&self.map),
state_creator: self.state_creator.clone(),
allow_missing_functions: false,
}
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime-core/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{
units::Pages,
vm,
};
use std::sync::Arc;
use std::{
cell::{Cell, RefCell},
fmt, mem,
rc::Rc,
};

pub use self::atomic::Atomic;
Expand Down Expand Up @@ -211,7 +211,7 @@ enum UnsharedMemoryStorage {
}

pub struct UnsharedMemory {
internal: Rc<UnsharedMemoryInternal>,
internal: Arc<UnsharedMemoryInternal>,
}

struct UnsharedMemoryInternal {
Expand All @@ -238,7 +238,7 @@ impl UnsharedMemory {
};

Ok(UnsharedMemory {
internal: Rc::new(UnsharedMemoryInternal {
internal: Arc::new(UnsharedMemoryInternal {
storage: RefCell::new(storage),
local: Cell::new(local),
}),
Expand Down Expand Up @@ -279,7 +279,7 @@ impl UnsharedMemory {
impl Clone for UnsharedMemory {
fn clone(&self) -> Self {
UnsharedMemory {
internal: Rc::clone(&self.internal),
internal: Arc::clone(&self.internal),
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/runtime-core/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{
types::{ElementType, TableDescriptor},
vm,
};
use std::{cell::RefCell, fmt, ptr, rc::Rc};
use std::sync::Arc;
use std::{cell::RefCell, fmt, ptr};

mod anyfunc;

Expand All @@ -25,7 +26,7 @@ pub enum TableStorage {

pub struct Table {
desc: TableDescriptor,
storage: Rc<RefCell<(TableStorage, vm::LocalTable)>>,
storage: Arc<RefCell<(TableStorage, vm::LocalTable)>>,
}

impl Table {
Expand Down Expand Up @@ -71,7 +72,7 @@ impl Table {

Ok(Self {
desc,
storage: Rc::new(RefCell::new((storage, local))),
storage: Arc::new(RefCell::new((storage, local))),
})
}

Expand Down Expand Up @@ -136,7 +137,7 @@ impl Clone for Table {
fn clone(&self) -> Self {
Self {
desc: self.desc,
storage: Rc::clone(&self.storage),
storage: Arc::clone(&self.storage),
}
}
}
Expand Down

0 comments on commit 801339a

Please sign in to comment.