Move RacyCell to std::comm

RacyCell is not exactly what we'd like as a final implementation for
this. Therefore, we're moving it under `std::comm` and also making it
private.
This commit is contained in:
Flavio Percoco 2014-12-22 12:29:46 +01:00
parent f436f9ca29
commit e2116c8fba
8 changed files with 61 additions and 47 deletions

View file

@ -319,9 +319,10 @@ pub use self::TrySendError::*;
use self::Flavor::*;
use alloc::arc::Arc;
use core::kinds;
use core::kinds::marker;
use core::mem;
use core::cell::{UnsafeCell, RacyCell};
use core::cell::UnsafeCell;
pub use self::select::{Select, Handle};
use self::select::StartResult;
@ -1024,6 +1025,32 @@ impl<T: Send> Drop for Receiver<T> {
}
}
/// A version of `UnsafeCell` intended for use in concurrent data
/// structures (for example, you might put it in an `Arc`).
pub struct RacyCell<T>(pub UnsafeCell<T>);
impl<T> RacyCell<T> {
/// DOX
pub fn new(value: T) -> RacyCell<T> {
RacyCell(UnsafeCell { value: value })
}
/// DOX
pub unsafe fn get(&self) -> *mut T {
self.0.get()
}
/// DOX
pub unsafe fn into_inner(self) -> T {
self.0.into_inner()
}
}
unsafe impl<T:Send> Send for RacyCell<T> { }
unsafe impl<T> kinds::Sync for RacyCell<T> { } // Oh dear
#[cfg(test)]
mod test {
use prelude::*;