pub use self::Ordering::*;
+use kinds::Sync;
+
use intrinsics;
-use cell::{UnsafeCell, RacyCell};
+use cell::UnsafeCell;
/// A boolean type which can be safely shared between threads.
#[stable]
pub struct AtomicBool {
- v: RacyCell<uint>,
+ v: UnsafeCell<uint>,
}
+unsafe impl Sync for AtomicBool {}
+
/// A signed integer type which can be safely shared between threads.
#[stable]
pub struct AtomicInt {
- v: RacyCell<int>,
+ v: UnsafeCell<int>,
}
+unsafe impl Sync for AtomicInt {}
+
/// An unsigned integer type which can be safely shared between threads.
#[stable]
pub struct AtomicUint {
- v: RacyCell<uint>,
+ v: UnsafeCell<uint>,
}
+unsafe impl Sync for AtomicUint {}
+
/// A raw pointer type which can be safely shared between threads.
#[stable]
pub struct AtomicPtr<T> {
- p: RacyCell<uint>,
+ p: UnsafeCell<uint>,
}
+unsafe impl<T> Sync for AtomicPtr<T> {}
+
/// Atomic memory orderings
///
/// Memory orderings limit the ways that both the compiler and CPU may reorder
/// An `AtomicBool` initialized to `false`.
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub const INIT_ATOMIC_BOOL: AtomicBool =
- AtomicBool { v: RacyCell(UnsafeCell { value: 0 }) };
+ AtomicBool { v: UnsafeCell { value: 0 } };
/// An `AtomicInt` initialized to `0`.
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub const INIT_ATOMIC_INT: AtomicInt =
- AtomicInt { v: RacyCell(UnsafeCell { value: 0 }) };
+ AtomicInt { v: UnsafeCell { value: 0 } };
/// An `AtomicUint` initialized to `0`.
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub const INIT_ATOMIC_UINT: AtomicUint =
- AtomicUint { v: RacyCell(UnsafeCell { value: 0 }) };
+ AtomicUint { v: UnsafeCell { value: 0, } };
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
const UINT_TRUE: uint = -1;
#[stable]
pub fn new(v: bool) -> AtomicBool {
let val = if v { UINT_TRUE } else { 0 };
- AtomicBool { v: RacyCell::new(val) }
+ AtomicBool { v: UnsafeCell::new(val) }
}
/// Loads a value from the bool.
#[inline]
#[stable]
pub fn new(v: int) -> AtomicInt {
- AtomicInt {v: RacyCell::new(v)}
+ AtomicInt {v: UnsafeCell::new(v)}
}
/// Loads a value from the int.
#[inline]
#[stable]
pub fn new(v: uint) -> AtomicUint {
- AtomicUint { v: RacyCell::new(v) }
+ AtomicUint { v: UnsafeCell::new(v) }
}
/// Loads a value from the uint.
#[inline]
#[stable]
pub fn new(p: *mut T) -> AtomicPtr<T> {
- AtomicPtr { p: RacyCell::new(p as uint) }
+ AtomicPtr { p: UnsafeCell::new(p as uint) }
}
/// Loads a value from the pointer.
use clone::Clone;
use cmp::PartialEq;
use default::Default;
-use kinds::{marker, Copy, Send, Sync};
+use kinds::{marker, Copy};
use ops::{Deref, DerefMut, Drop};
use option::Option;
use option::Option::{None, Some};
#[deprecated = "renamed to into_inner()"]
pub unsafe fn unwrap(self) -> T { self.into_inner() }
}
-
-/// 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> Sync for RacyCell<T> { } // Oh dear
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;
}
}
+/// 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::*;