}
}
-#[cfg(stage0)]
-impl ops::Slice<uint, str> for String {
- #[inline]
- fn as_slice_<'a>(&'a self) -> &'a str {
- self.as_slice()
- }
-
- #[inline]
- fn slice_from_<'a>(&'a self, from: &uint) -> &'a str {
- self[][*from..]
- }
-
- #[inline]
- fn slice_to_<'a>(&'a self, to: &uint) -> &'a str {
- self[][..*to]
- }
-
- #[inline]
- fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
- self[][*from..*to]
- }
-}
-#[cfg(not(stage0))]
impl ops::Slice<uint, str> for String {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a str {
impl<T> TrieMap<T> {
// If `upper` is true then returns upper_bound else returns lower_bound.
- #[cfg(stage0)]
- #[inline]
- fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
- bound!(Entries, self = self,
- key = key, is_upper = upper,
- slice_from = slice_from_, iter = iter,
- mutability = )
- }
- #[cfg(not(stage0))]
#[inline]
fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
bound!(Entries, self = self,
self.bound(key, true)
}
// If `upper` is true then returns upper_bound else returns lower_bound.
- #[cfg(stage0)]
- #[inline]
- fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
- bound!(MutEntries, self = self,
- key = key, is_upper = upper,
- slice_from = slice_from_mut_, iter = iter_mut,
- mutability = mut)
- }
- #[cfg(not(stage0))]
#[inline]
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
bound!(MutEntries, self = self,
}
}*/
-#[cfg(stage0)]
-impl<T> ops::Slice<uint, [T]> for Vec<T> {
- #[inline]
- fn as_slice_<'a>(&'a self) -> &'a [T] {
- self.as_slice()
- }
-
- #[inline]
- fn slice_from_<'a>(&'a self, start: &uint) -> &'a [T] {
- self.as_slice().slice_from_(start)
- }
-
- #[inline]
- fn slice_to_<'a>(&'a self, end: &uint) -> &'a [T] {
- self.as_slice().slice_to_(end)
- }
- #[inline]
- fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
- self.as_slice().slice_(start, end)
- }
-}
-#[cfg(not(stage0))]
impl<T> ops::Slice<uint, [T]> for Vec<T> {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
}
}
-#[cfg(stage0)]
-impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
- #[inline]
- fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
- self.as_mut_slice()
- }
-
- #[inline]
- fn slice_from_mut_<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
- self.as_mut_slice().slice_from_mut_(start)
- }
-
- #[inline]
- fn slice_to_mut_<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
- self.as_mut_slice().slice_to_mut_(end)
- }
- #[inline]
- fn slice_mut_<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
- self.as_mut_slice().slice_mut_(start, end)
- }
-}
-#[cfg(not(stage0))]
impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
#[inline]
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
/// enabling further optimizations.
///
/// NB: This is very different from the `unreachable!()` macro!
- #[cfg(not(stage0))]
pub fn unreachable() -> !;
/// Execute a breakpoint trap, for inspection by a debugger.
* }
* ```
*/
-#[cfg(not(stage0))]
#[lang="slice"]
pub trait Slice<Idx, Sized? Result> for Sized? {
/// The method for the slicing operation foo[]
/// The method for the slicing operation foo[from..to]
fn slice_or_fail<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result;
}
-#[cfg(stage0)]
-/**
- *
- */
-#[lang="slice"]
-pub trait Slice<Idx, Sized? Result> for Sized? {
- /// The method for the slicing operation foo[]
- fn as_slice_<'a>(&'a self) -> &'a Result;
- /// The method for the slicing operation foo[from..]
- fn slice_from_<'a>(&'a self, from: &Idx) -> &'a Result;
- /// The method for the slicing operation foo[..to]
- fn slice_to_<'a>(&'a self, to: &Idx) -> &'a Result;
- /// The method for the slicing operation foo[from..to]
- fn slice_<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result;
-}
/**
*
* }
* ```
*/
-#[cfg(not(stage0))]
#[lang="slice_mut"]
pub trait SliceMut<Idx, Sized? Result> for Sized? {
/// The method for the slicing operation foo[]
/// The method for the slicing operation foo[from..to]
fn slice_or_fail_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
}
-#[cfg(stage0)]
-/**
- *
- */
-#[lang="slice_mut"]
-pub trait SliceMut<Idx, Sized? Result> for Sized? {
- /// The method for the slicing operation foo[mut]
- fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Result;
- /// The method for the slicing operation foo[mut from..]
- fn slice_from_mut_<'a>(&'a mut self, from: &Idx) -> &'a mut Result;
- /// The method for the slicing operation foo[mut ..to]
- fn slice_to_mut_<'a>(&'a mut self, to: &Idx) -> &'a mut Result;
- /// The method for the slicing operation foo[mut from..to]
- fn slice_mut_<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
-}
+
/**
*
* The `Deref` trait is used to specify the functionality of dereferencing
-#[cfg(not(stage0))]
impl<T> ops::Slice<uint, [T]> for [T] {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
}
}
}
-#[cfg(stage0)]
-impl<T> ops::Slice<uint, [T]> for [T] {
- #[inline]
- fn as_slice_<'a>(&'a self) -> &'a [T] {
- self
- }
-
- #[inline]
- fn slice_from_<'a>(&'a self, start: &uint) -> &'a [T] {
- self.slice_(start, &self.len())
- }
- #[inline]
- fn slice_to_<'a>(&'a self, end: &uint) -> &'a [T] {
- self.slice_(&0, end)
- }
- #[inline]
- fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
- assert!(*start <= *end);
- assert!(*end <= self.len());
- unsafe {
- transmute(RawSlice {
- data: self.as_ptr().offset(*start as int),
- len: (*end - *start)
- })
- }
- }
-}
-
-#[cfg(not(stage0))]
impl<T> ops::SliceMut<uint, [T]> for [T] {
#[inline]
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
}
}
}
-#[cfg(stage0)]
-impl<T> ops::SliceMut<uint, [T]> for [T] {
- #[inline]
- fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
- self
- }
-
- #[inline]
- fn slice_from_mut_<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
- let len = &self.len();
- self.slice_mut_(start, len)
- }
-
- #[inline]
- fn slice_to_mut_<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
- self.slice_mut_(&0, end)
- }
- #[inline]
- fn slice_mut_<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
- assert!(*start <= *end);
- assert!(*end <= self.len());
- unsafe {
- transmute(RawSlice {
- data: self.as_ptr().offset(*start as int),
- len: (*end - *start)
- })
- }
- }
-}
/// Extension methods for slices such that their elements are
/// mutable.
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
}
- #[cfg(stage0)]
- impl ops::Slice<uint, str> for str {
- #[inline]
- fn as_slice_<'a>(&'a self) -> &'a str {
- self
- }
-
- #[inline]
- fn slice_from_<'a>(&'a self, from: &uint) -> &'a str {
- self.slice_from(*from)
- }
-
- #[inline]
- fn slice_to_<'a>(&'a self, to: &uint) -> &'a str {
- self.slice_to(*to)
- }
-
- #[inline]
- fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
- self.slice(*from, *to)
- }
- }
- #[cfg(not(stage0))]
impl ops::Slice<uint, str> for str {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a str {
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
}
-static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL;
-static mut S_INT : AtomicInt = INIT_ATOMIC_INT;
-static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT;
+static S_BOOL : AtomicBool = INIT_ATOMIC_BOOL;
+static S_INT : AtomicInt = INIT_ATOMIC_INT;
+static S_UINT : AtomicUint = INIT_ATOMIC_UINT;
#[test]
fn static_init() {
- unsafe {
- assert!(!S_BOOL.load(SeqCst));
- assert!(S_INT.load(SeqCst) == 0);
- assert!(S_UINT.load(SeqCst) == 0);
- }
+ assert!(!S_BOOL.load(SeqCst));
+ assert!(S_INT.load(SeqCst) == 0);
+ assert!(S_UINT.load(SeqCst) == 0);
}
/// This will configure the pool according to the `config` parameter, and
/// initially run `main` inside the pool of schedulers.
pub fn new(config: PoolConfig) -> SchedPool {
- static mut POOL_ID: AtomicUint = INIT_ATOMIC_UINT;
+ static POOL_ID: AtomicUint = INIT_ATOMIC_UINT;
let PoolConfig {
threads: nscheds,
threads: vec![],
handles: vec![],
stealers: vec![],
- id: unsafe { POOL_ID.fetch_add(1, SeqCst) },
+ id: POOL_ID.fetch_add(1, SeqCst),
sleepers: SleeperList::new(),
stack_pool: StackPool::new(),
deque_pool: deque::BufferPool::new(),
#[test]
fn test_spawn_sched_blocking() {
use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
- static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
// Testing that a task in one scheduler can block in foreign code
// without affecting other schedulers
}
fn max_cached_stacks() -> uint {
- static mut AMT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
- match unsafe { AMT.load(atomic::SeqCst) } {
+ static AMT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+ match AMT.load(atomic::SeqCst) {
0 => {}
n => return n - 1,
}
let amt = amt.unwrap_or(10);
// 0 is our sentinel value, so ensure that we'll never see 0 after
// initialization has run
- unsafe { AMT.store(amt + 1, atomic::SeqCst); }
+ AMT.store(amt + 1, atomic::SeqCst);
return amt;
}
/// module's log statement should be emitted or not.
#[doc(hidden)]
pub fn mod_enabled(level: u32, module: &str) -> bool {
- static mut INIT: Once = ONCE_INIT;
- unsafe { INIT.doit(init); }
+ static INIT: Once = ONCE_INIT;
+ INIT.doit(init);
// It's possible for many threads are in this function, only one of them
// will perform the global initialization, but all of them will need to check
pub initialized: UnsafeCell<bool>,
}
-macro_rules! helper_init( (static mut $name:ident: Helper<$m:ty>) => (
- static mut $name: Helper<$m> = Helper {
+macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
+ static $name: Helper<$m> = Helper {
lock: ::std::rt::mutex::NATIVE_MUTEX_INIT,
chan: ::std::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
signal: ::std::cell::UnsafeCell { value: 0 },
unsafe {
use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
static mut INITIALIZED: bool = false;
- static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
let _guard = LOCK.lock();
if !INITIALIZED {
#[cfg(unix)] use io::helper_thread::Helper;
#[cfg(unix)]
-helper_init!(static mut HELPER: Helper<Req>)
+helper_init!(static HELPER: Helper<Req>)
/**
* A value representing a child process.
// The actual communication between the helper thread and this thread is
// quite simple, just a channel moving data around.
- unsafe { HELPER.boot(register_sigchld, waitpid_helper) }
+ HELPER.boot(register_sigchld, waitpid_helper);
match waitpid_nowait(pid) {
Some(ret) => return Ok(ret),
}
let (tx, rx) = channel();
- unsafe { HELPER.send(NewChild(pid, tx, deadline)); }
+ HELPER.send(NewChild(pid, tx, deadline));
return match rx.recv_opt() {
Ok(e) => Ok(e),
Err(()) => Err(util::timeout("wait timed out")),
use io::file::FileDesc;
use io::helper_thread::Helper;
-helper_init!(static mut HELPER: Helper<Req>)
+helper_init!(static HELPER: Helper<Req>)
pub struct Timer {
id: uint,
pub fn new() -> IoResult<Timer> {
// See notes above regarding using int return value
// instead of ()
- unsafe { HELPER.boot(|| {}, helper); }
+ HELPER.boot(|| {}, helper);
- static mut ID: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
- let id = unsafe { ID.fetch_add(1, atomic::Relaxed) };
+ static ID: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+ let id = ID.fetch_add(1, atomic::Relaxed);
Ok(Timer {
id: id,
inner: Some(box Inner {
Some(i) => i,
None => {
let (tx, rx) = channel();
- unsafe { HELPER.send(RemoveTimer(self.id, tx)); }
+ HELPER.send(RemoveTimer(self.id, tx));
rx.recv()
}
}
inner.interval = msecs;
inner.target = now + msecs;
- unsafe { HELPER.send(NewTimer(inner)); }
+ HELPER.send(NewTimer(inner));
}
fn period(&mut self, msecs: u64, cb: Box<rtio::Callback + Send>) {
inner.interval = msecs;
inner.target = now + msecs;
- unsafe { HELPER.send(NewTimer(inner)); }
+ HELPER.send(NewTimer(inner));
}
}
use io::helper_thread::Helper;
-helper_init!(static mut HELPER: Helper<Req>)
+helper_init!(static HELPER: Helper<Req>)
pub struct Timer {
obj: libc::HANDLE,
impl Timer {
pub fn new() -> IoResult<Timer> {
- unsafe { HELPER.boot(|| {}, helper) }
+ HELPER.boot(|| {}, helper);
let obj = unsafe {
imp::CreateWaitableTimerA(ptr::null_mut(), 0, ptr::null())
if !self.on_worker { return }
let (tx, rx) = channel();
- unsafe { HELPER.send(RemoveTimer(self.obj, tx)) }
+ HELPER.send(RemoveTimer(self.obj, tx));
rx.recv();
self.on_worker = false;
ptr::null_mut(), 0)
}, 1);
- unsafe { HELPER.send(NewTimer(self.obj, cb, true)) }
+ HELPER.send(NewTimer(self.obj, cb, true));
self.on_worker = true;
}
ptr::null_mut(), ptr::null_mut(), 0)
}, 1);
- unsafe { HELPER.send(NewTimer(self.obj, cb, false)) }
+ HELPER.send(NewTimer(self.obj, cb, false));
self.on_worker = true;
}
}
unsafe fn configure_llvm(sess: &Session) {
use std::sync::{Once, ONCE_INIT};
- static mut INIT: Once = ONCE_INIT;
+ static INIT: Once = ONCE_INIT;
// Copy what clang does by turning on loop vectorization at O2 and
// slp vectorization at O3
// Before we touch LLVM, make sure that multithreading is enabled.
unsafe {
use std::sync::{Once, ONCE_INIT};
- static mut INIT: Once = ONCE_INIT;
+ static INIT: Once = ONCE_INIT;
static mut POISONED: bool = false;
INIT.doit(|| {
if llvm::LLVMStartMultithreaded() != 1 {
use mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
- static mut global_args_ptr: uint = 0;
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static mut GLOBAL_ARGS_PTR: uint = 0;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
pub unsafe fn init(argc: int, argv: *const *const u8) {
let args = load_argc_and_argv(argc, argv);
pub unsafe fn cleanup() {
rtassert!(take().is_some());
- lock.destroy();
+ LOCK.destroy();
}
pub fn take() -> Option<Vec<Vec<u8>>> {
fn with_lock<T>(f: || -> T) -> T {
unsafe {
- let _guard = lock.lock();
+ let _guard = LOCK.lock();
f()
}
}
fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> {
- unsafe { mem::transmute(&global_args_ptr) }
+ unsafe { mem::transmute(&GLOBAL_ARGS_PTR) }
}
unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec<Vec<u8>> {
type Queue = Exclusive<Vec<proc():Send>>;
-static mut QUEUE: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
-static mut RUNNING: atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL;
+static QUEUE: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+static RUNNING: atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL;
pub fn init() {
let state: Box<Queue> = box Exclusive::new(Vec::new());
use mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
-static mut TASK_COUNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
-static mut TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+static TASK_COUNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+static TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
pub struct Token { _private: () }
/// Increment the number of live tasks, returning a token which will decrement
/// the count when dropped.
pub fn increment() -> Token {
- let _ = unsafe { TASK_COUNT.fetch_add(1, atomic::SeqCst) };
+ let _ = TASK_COUNT.fetch_add(1, atomic::SeqCst);
Token { _private: () }
}
//! use std::rt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
//!
//! // Use a statically initialized mutex
-//! static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+//! static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
//!
//! unsafe {
//! let _guard = LOCK.lock();
///
/// ```rust
/// use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
- /// static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ /// static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
/// unsafe {
/// let _guard = LOCK.lock();
/// // critical section...
#[test]
fn smoke_lock() {
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
let _guard = lock.lock();
}
#[test]
fn smoke_cond() {
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
let guard = lock.lock();
let t = Thread::start(proc() {
#[test]
fn smoke_lock_noguard() {
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
lock.lock_noguard();
lock.unlock_noguard();
#[test]
fn smoke_cond_noguard() {
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
lock.lock_noguard();
let t = Thread::start(proc() {
//
// For more information, see below.
const MAX_CALLBACKS: uint = 16;
-static mut CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] =
+static CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] =
[atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT,
atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT,
atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT,
atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT,
atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT,
atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT];
-static mut CALLBACK_CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+static CALLBACK_CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
impl Unwinder {
pub fn new() -> Unwinder {
// so we just chalk it up to a race condition and move on to the next
// callback. Additionally, CALLBACK_CNT may briefly be higher than
// MAX_CALLBACKS, so we're sure to clamp it as necessary.
- let callbacks = unsafe {
+ let callbacks = {
let amt = CALLBACK_CNT.load(atomic::SeqCst);
CALLBACKS[..cmp::min(amt, MAX_CALLBACKS)]
};
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> {
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
// dlerror isn't thread safe, so we need to lock around this entire
// sequence
- let _guard = lock.lock();
+ let _guard = LOCK.lock();
let _old_error = dlerror();
let result = f();
return TempDir::new_in(&os::make_absolute(tmpdir), suffix);
}
- static mut CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+ static CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
let mut attempts = 0u;
loop {
let filename =
format!("rs-{}-{}-{}",
unsafe { libc::getpid() },
- unsafe { CNT.fetch_add(1, atomic::SeqCst) },
+ CNT.fetch_add(1, atomic::SeqCst),
suffix);
let p = tmpdir.join(filename);
match fs::mkdir(&p, io::USER_RWX) {
/// Get a port number, starting at 9600, for use in tests
pub fn next_test_port() -> u16 {
- static mut next_offset: AtomicUint = INIT_ATOMIC_UINT;
- unsafe {
- base_port() + next_offset.fetch_add(1, Relaxed) as u16
- }
+ static NEXT_OFFSET: AtomicUint = INIT_ATOMIC_UINT;
+ base_port() + NEXT_OFFSET.fetch_add(1, Relaxed) as u16
}
/// Get a temporary path which could be the location of a unix socket
pub fn next_test_unix() -> Path {
- static mut COUNT: AtomicUint = INIT_ATOMIC_UINT;
+ static COUNT: AtomicUint = INIT_ATOMIC_UINT;
// base port and pid are an attempt to be unique between multiple
// test-runners of different configurations running on one
// buildbot, the count is to be unique within this executable.
let string = format!("rust-test-unix-path-{}-{}-{}",
base_port(),
unsafe {libc::getpid()},
- unsafe {COUNT.fetch_add(1, Relaxed)});
+ COUNT.fetch_add(1, Relaxed));
if cfg!(unix) {
os::tmpdir().join(string)
} else {
fn with_env_lock<T>(f: || -> T) -> T {
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
- static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
- let _guard = lock.lock();
+ let _guard = LOCK.lock();
f()
}
}
error_string(errno() as uint)
}
-static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
+static EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
/**
* Sets the process exit code
* Note that this is not synchronized against modifications of other threads.
*/
pub fn set_exit_status(code: int) {
- unsafe { EXIT_STATUS.store(code, SeqCst) }
+ EXIT_STATUS.store(code, SeqCst)
}
/// Fetches the process's current exit code. This defaults to 0 and can change
/// by calling `set_exit_status`.
pub fn get_exit_status() -> int {
- unsafe { EXIT_STATUS.load(SeqCst) }
+ EXIT_STATUS.load(SeqCst)
}
#[cfg(target_os = "macos")]
// For now logging is turned off by default, and this function checks to see
// whether the magical environment variable is present to see if it's turned on.
pub fn log_enabled() -> bool {
- static mut ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT;
- unsafe {
- match ENABLED.load(atomic::SeqCst) {
- 1 => return false,
- 2 => return true,
- _ => {}
- }
+ static ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT;
+ match ENABLED.load(atomic::SeqCst) {
+ 1 => return false,
+ 2 => return true,
+ _ => {}
}
let val = match os::getenv("RUST_BACKTRACE") {
Some(..) => 2,
None => 1,
};
- unsafe { ENABLED.store(val, atomic::SeqCst); }
+ ENABLED.store(val, atomic::SeqCst);
val == 2
}
// while it doesn't requires lock for work as everything is
// local, it still displays much nicer backtraces when a
// couple of tasks fail simultaneously
- static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
let _g = unsafe { LOCK.lock() };
try!(writeln!(w, "stack backtrace:"));
// is semi-reasonable in terms of printing anyway, and we know that all
// I/O done here is blocking I/O, not green I/O, so we don't have to
// worry about this being a native vs green mutex.
- static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
let _g = unsafe { LOCK.lock() };
try!(writeln!(w, "stack backtrace:"));
pub fn write(w: &mut Writer) -> IoResult<()> {
// According to windows documentation, all dbghelp functions are
// single-threaded.
- static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
let _g = unsafe { LOCK.lock() };
// Open up dbghelp.dll, we don't link to it explicitly because it can't
}
pub fn min_stack() -> uint {
- static mut MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
- match unsafe { MIN.load(atomic::SeqCst) } {
+ static MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+ match MIN.load(atomic::SeqCst) {
0 => {}
n => return n - 1,
}
let amt = amt.unwrap_or(2 * 1024 * 1024);
// 0 is our sentinel value, so ensure that we'll never see 0 after
// initialization has run
- unsafe { MIN.store(amt + 1, atomic::SeqCst); }
+ MIN.store(amt + 1, atomic::SeqCst);
return amt;
}
//! ```
//! use std::sync::atomic::{AtomicUint, SeqCst, INIT_ATOMIC_UINT};
//!
-//! static mut GLOBAL_TASK_COUNT: AtomicUint = INIT_ATOMIC_UINT;
+//! static GLOBAL_TASK_COUNT: AtomicUint = INIT_ATOMIC_UINT;
//!
-//! unsafe {
-//! let old_task_count = GLOBAL_TASK_COUNT.fetch_add(1, SeqCst);
-//! println!("live tasks: {}", old_task_count + 1);
-//! }
+//! let old_task_count = GLOBAL_TASK_COUNT.fetch_add(1, SeqCst);
+//! println!("live tasks: {}", old_task_count + 1);
//! ```
#![allow(deprecated)]
fn stress() {
static AMT: int = 100000;
static NTHREADS: int = 8;
- static mut DONE: AtomicBool = INIT_ATOMIC_BOOL;
- static mut HITS: AtomicUint = INIT_ATOMIC_UINT;
+ static DONE: AtomicBool = INIT_ATOMIC_BOOL;
+ static HITS: AtomicUint = INIT_ATOMIC_UINT;
let pool = BufferPool::<int>::new();
let (w, s) = pool.deque();
fn no_starvation() {
static AMT: int = 10000;
static NTHREADS: int = 4;
- static mut DONE: AtomicBool = INIT_ATOMIC_BOOL;
+ static DONE: AtomicBool = INIT_ATOMIC_BOOL;
let pool = BufferPool::<(int, uint)>::new();
let (w, s) = pool.deque();
/// ```rust
/// use sync::mutex::{StaticMutex, MUTEX_INIT};
///
-/// static mut LOCK: StaticMutex = MUTEX_INIT;
+/// static LOCK: StaticMutex = MUTEX_INIT;
///
-/// unsafe {
+/// {
/// let _g = LOCK.lock();
/// // do some productive work
/// }
#[test]
fn smoke_static() {
- static mut m: StaticMutex = MUTEX_INIT;
+ static m: StaticMutex = MUTEX_INIT;
unsafe {
drop(m.lock());
drop(m.lock());
#[test]
fn lots_and_lots() {
- static mut m: StaticMutex = MUTEX_INIT;
+ static m: StaticMutex = MUTEX_INIT;
static mut CNT: uint = 0;
static M: uint = 1000;
static N: uint = 3;
/// ```rust
/// use sync::one::{Once, ONCE_INIT};
///
-/// static mut START: Once = ONCE_INIT;
+/// static START: Once = ONCE_INIT;
///
-/// unsafe {
-/// START.doit(|| {
-/// // run initialization here
-/// });
-/// }
+/// START.doit(|| {
+/// // run initialization here
+/// });
/// ```
pub struct Once {
mutex: StaticMutex,
#[test]
fn smoke_once() {
- static mut o: Once = ONCE_INIT;
+ static o: Once = ONCE_INIT;
let mut a = 0i;
- unsafe { o.doit(|| a += 1); }
+ o.doit(|| a += 1);
assert_eq!(a, 1);
- unsafe { o.doit(|| a += 1); }
+ o.doit(|| a += 1);
assert_eq!(a, 1);
}
#[test]
fn stampede_once() {
- static mut o: Once = ONCE_INIT;
+ static o: Once = ONCE_INIT;
static mut run: bool = false;
let (tx, rx) = channel();
fn os_precise_time_ns() -> u64 {
static mut TIMEBASE: libc::mach_timebase_info = libc::mach_timebase_info { numer: 0,
denom: 0 };
- static mut ONCE: std::sync::Once = std::sync::ONCE_INIT;
+ static ONCE: std::sync::Once = std::sync::ONCE_INIT;
unsafe {
ONCE.doit(|| {
imp::mach_timebase_info(&mut TIMEBASE);
+S 2014-10-10 78a7676
+ freebsd-x86_64 511061af382e2e837a6d615823e1a952e8281483
+ linux-i386 0644637db852db8a6c603ded0531ccaa60291bd3
+ linux-x86_64 656b8c23fbb97794e85973aca725a4b9cd07b29e
+ macos-i386 e4d9709fcfe485fcca00f0aa1fe456e2f164ed96
+ macos-x86_64 6b1aa5a441965da87961be81950e8663eadba377
+ winnt-i386 b87f8f040adb464e9f8455a37de8582e9e2c8cf3
+ winnt-x86_64 b883264902ac0585a80175ba27dc141f5c4f8618
+
S 2014-10-04 749ff5e
freebsd-x86_64 f39d94487d29b3d48217b1295ad2cda8c941e694
linux-i386 555aca74f9a268f80cab2df1147dc6406403e9e4