Skip to content

Commit

Permalink
Make Rc, Cell and RefCell NoShare
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Mar 20, 2014
1 parent 37154fb commit 21d23ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -32,6 +33,7 @@ impl<T:Pod> Cell<T> {
value: value,
marker1: marker::InvariantType::<T>,
marker2: marker::NoFreeze,
marker3: marker::NoShare,
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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,
}
Expand Down
21 changes: 14 additions & 7 deletions src/libstd/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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
}
}
}
Expand All @@ -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
}
}
}
}
Expand Down Expand Up @@ -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 }
}
}
}
Expand Down Expand Up @@ -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> {
Expand All @@ -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 })
}
}
}
Expand All @@ -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 }
}
}
}
Expand Down

0 comments on commit 21d23ff

Please sign in to comment.