extern crate atomic; use alloc::sync::{Arc, Mutex}; pub use alloc::sync::{ Arc as MyRc, Weak as MyWeak, MutexGuard as MyRef, }; pub use self::atomic::{ Atomic, Ordering::Relaxed as Ordering, }; /// Thread-safe wrapper which can be used in place of a `RefCell`. #[derive(Debug)] pub struct MyRefCell(Arc>); impl MyRefCell { /// Create new wrapper object. pub fn new(obj: T) -> MyRefCell { MyRefCell(Arc::new(Mutex::new(obj))) } /// Borrow a `MyRef` to the inner value. pub fn borrow(&self) -> ::MyRef { self.0.lock().expect("bar") } /// Borrow a mutable `MyRef` to the inner value. pub fn borrow_mut(&self) -> ::MyRef { self.0.lock().expect("bar") } } /// Thread-safe wrapper which can be used in place of a `Cell`. #[derive(Debug)] pub struct MyCell(Atomic) where T: Copy; impl MyCell where T: Copy { /// Create new wrapper object. pub fn new(obj: T) -> MyCell { MyCell(Atomic::new(obj)) } /// Returns the inner value. pub fn get(&self) -> T { self.0.load(::Ordering) } /// Sets the inner value. pub fn set(&self, val: T) { self.0.store(val, ::Ordering); } }