Make Rc, Cell and RefCell NoShare

This commit is contained in:
Flavio Percoco 2014-03-05 22:09:38 +01:00
parent 37154fb8b9
commit 21d23ff25b
2 changed files with 18 additions and 7 deletions

View File

@ -23,6 +23,7 @@ pub struct Cell<T> {
priv value: T,
priv marker1: marker::InvariantType<T>,
priv marker2: marker::NoFreeze,
priv marker3: marker::NoShare,
}
impl<T:Pod> Cell<T> {
@ -32,6 +33,7 @@ impl<T:Pod> Cell<T> {
value: value,
marker1: marker::InvariantType::<T>,
marker2: marker::NoFreeze,
marker3: marker::NoShare,
}
}
@ -75,6 +77,7 @@ pub struct RefCell<T> {
priv marker1: marker::InvariantType<T>,
priv marker2: marker::NoFreeze,
priv marker3: marker::NoPod,
priv marker4: marker::NoShare,
}
// Values [1, MAX-1] represent the number of `Ref` active
@ -90,6 +93,7 @@ impl<T> RefCell<T> {
marker1: marker::InvariantType::<T>,
marker2: marker::NoFreeze,
marker3: marker::NoPod,
marker4: marker::NoShare,
value: value,
borrow: UNUSED,
}

View File

@ -42,7 +42,8 @@ struct RcBox<T> {
#[unsafe_no_drop_flag]
pub struct Rc<T> {
priv ptr: *mut RcBox<T>,
priv marker: marker::NoSend
priv nosend: marker::NoSend,
priv noshare: marker::NoShare
}
impl<T> Rc<T> {
@ -56,7 +57,8 @@ impl<T> Rc<T> {
// strong destructor is running, even if the weak
// pointer is stored inside the strong one.
ptr: transmute(~RcBox { value: value, strong: 1, weak: 1 }),
marker: marker::NoSend,
nosend: marker::NoSend,
noshare: marker::NoShare
}
}
}
@ -67,7 +69,11 @@ impl<T> Rc<T> {
pub fn downgrade(&self) -> Weak<T> {
unsafe {
(*self.ptr).weak += 1;
Weak { ptr: self.ptr, marker: marker::NoSend }
Weak {
ptr: self.ptr,
nosend: marker::NoSend,
noshare: marker::NoShare
}
}
}
}
@ -107,7 +113,7 @@ impl<T> Clone for Rc<T> {
fn clone(&self) -> Rc<T> {
unsafe {
(*self.ptr).strong += 1;
Rc { ptr: self.ptr, marker: marker::NoSend }
Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }
}
}
}
@ -138,7 +144,8 @@ impl<T: Ord> Ord for Rc<T> {
#[unsafe_no_drop_flag]
pub struct Weak<T> {
priv ptr: *mut RcBox<T>,
priv marker: marker::NoSend
priv nosend: marker::NoSend,
priv noshare: marker::NoShare
}
impl<T> Weak<T> {
@ -149,7 +156,7 @@ impl<T> Weak<T> {
None
} else {
(*self.ptr).strong += 1;
Some(Rc { ptr: self.ptr, marker: marker::NoSend })
Some(Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare })
}
}
}
@ -176,7 +183,7 @@ impl<T> Clone for Weak<T> {
fn clone(&self) -> Weak<T> {
unsafe {
(*self.ptr).weak += 1;
Weak { ptr: self.ptr, marker: marker::NoSend }
Weak { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }
}
}
}