auto merge of #17939 : alexcrichton/rust/snapshots, r=sfackler

Also convert a number of `static mut` to just a plain old `static` and remove
some unsafe blocks.
This commit is contained in:
bors 2014-10-11 09:02:01 +00:00
commit 9b98332992
36 changed files with 107 additions and 307 deletions

View File

@ -928,29 +928,6 @@ impl<S: Str> Add<S, String> for String {
}
}
#[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 {

View File

@ -389,15 +389,6 @@ macro_rules! bound {
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,
@ -440,15 +431,6 @@ impl<T> TrieMap<T> {
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,

View File

@ -461,28 +461,6 @@ impl<T> Index<uint,T> for Vec<T> {
}
}*/
#[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] {
@ -504,28 +482,6 @@ impl<T> ops::Slice<uint, [T]> for Vec<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] {

View File

@ -254,7 +254,6 @@ extern "rust-intrinsic" {
/// 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.

View File

@ -711,7 +711,6 @@ pub trait IndexMut<Index, Result> {
* }
* ```
*/
#[cfg(not(stage0))]
#[lang="slice"]
pub trait Slice<Idx, Sized? Result> for Sized? {
/// The method for the slicing operation foo[]
@ -723,21 +722,6 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
/// 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;
}
/**
*
@ -776,7 +760,6 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
* }
* ```
*/
#[cfg(not(stage0))]
#[lang="slice_mut"]
pub trait SliceMut<Idx, Sized? Result> for Sized? {
/// The method for the slicing operation foo[]
@ -788,21 +771,7 @@ pub trait SliceMut<Idx, Sized? Result> for Sized? {
/// 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

View File

@ -488,7 +488,6 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
#[cfg(not(stage0))]
impl<T> ops::Slice<uint, [T]> for [T] {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
@ -516,36 +515,7 @@ impl<T> ops::Slice<uint, [T]> for [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] {
@ -574,35 +544,6 @@ impl<T> ops::SliceMut<uint, [T]> for [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.

View File

@ -1164,29 +1164,6 @@ pub mod traits {
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 {

View File

@ -69,15 +69,13 @@ fn int_xor() {
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);
}

View File

@ -335,7 +335,7 @@ impl SchedPool {
/// 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,
@ -349,7 +349,7 @@ impl SchedPool {
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(),

View File

@ -1458,7 +1458,7 @@ mod test {
#[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

View File

@ -158,8 +158,8 @@ impl StackPool {
}
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,
}
@ -169,7 +169,7 @@ fn max_cached_stacks() -> uint {
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;
}

View File

@ -348,8 +348,8 @@ pub struct LogLocation {
/// 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

View File

@ -55,8 +55,8 @@ pub struct Helper<M> {
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 },

View File

@ -1063,7 +1063,7 @@ mod os {
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 {

View File

@ -28,7 +28,7 @@ use super::util;
#[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.
@ -988,7 +988,7 @@ fn waitpid(pid: pid_t, deadline: u64) -> IoResult<rtio::ProcessExit> {
// 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),
@ -996,7 +996,7 @@ fn waitpid(pid: pid_t, deadline: u64) -> IoResult<rtio::ProcessExit> {
}
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")),

View File

@ -59,7 +59,7 @@ use io::c;
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,
@ -204,10 +204,10 @@ impl Timer {
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 {
@ -237,7 +237,7 @@ impl Timer {
Some(i) => i,
None => {
let (tx, rx) = channel();
unsafe { HELPER.send(RemoveTimer(self.id, tx)); }
HELPER.send(RemoveTimer(self.id, tx));
rx.recv()
}
}
@ -262,7 +262,7 @@ impl rtio::RtioTimer for Timer {
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>) {
@ -274,7 +274,7 @@ impl rtio::RtioTimer for Timer {
inner.interval = msecs;
inner.target = now + msecs;
unsafe { HELPER.send(NewTimer(inner)); }
HELPER.send(NewTimer(inner));
}
}

View File

@ -28,7 +28,7 @@ use std::comm;
use io::helper_thread::Helper;
helper_init!(static mut HELPER: Helper<Req>)
helper_init!(static HELPER: Helper<Req>)
pub struct Timer {
obj: libc::HANDLE,
@ -104,7 +104,7 @@ pub fn now() -> u64 {
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())
@ -126,7 +126,7 @@ impl Timer {
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;
@ -158,7 +158,7 @@ impl rtio::RtioTimer for Timer {
ptr::null_mut(), 0)
}, 1);
unsafe { HELPER.send(NewTimer(self.obj, cb, true)) }
HELPER.send(NewTimer(self.obj, cb, true));
self.on_worker = true;
}
@ -172,7 +172,7 @@ impl rtio::RtioTimer for Timer {
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;
}
}

View File

@ -936,7 +936,7 @@ pub fn run_assembler(sess: &Session, outputs: &OutputFilenames) {
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

View File

@ -3035,7 +3035,7 @@ pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>)
// 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 {

View File

@ -54,8 +54,8 @@ mod imp {
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);
@ -64,7 +64,7 @@ mod imp {
pub unsafe fn cleanup() {
rtassert!(take().is_some());
lock.destroy();
LOCK.destroy();
}
pub fn take() -> Option<Vec<Vec<u8>>> {
@ -92,13 +92,13 @@ mod imp {
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>> {

View File

@ -24,8 +24,8 @@ use exclusive::Exclusive;
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());

View File

@ -23,8 +23,8 @@ use core::ops::Drop;
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: () }
@ -35,7 +35,7 @@ impl Drop for Token {
/// 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: () }
}

View File

@ -36,7 +36,7 @@
//! 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();
@ -109,7 +109,7 @@ impl StaticNativeMutex {
///
/// ```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...
@ -655,7 +655,7 @@ mod test {
#[test]
fn smoke_lock() {
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
let _guard = lock.lock();
}
@ -663,7 +663,7 @@ mod test {
#[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() {
@ -679,7 +679,7 @@ mod test {
#[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();
@ -688,7 +688,7 @@ mod test {
#[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() {

View File

@ -92,7 +92,7 @@ pub type Callback = fn(msg: &Any + Send, file: &'static str, line: uint);
//
// 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,
@ -101,7 +101,7 @@ static mut 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];
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 {
@ -560,7 +560,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) ->
// 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)]
};

View File

@ -230,11 +230,11 @@ pub mod dl {
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();

View File

@ -38,14 +38,14 @@ impl TempDir {
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) {

View File

@ -20,22 +20,20 @@ use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
/// 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 {

View File

@ -192,10 +192,10 @@ Serialize access through a global lock.
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()
}
}
@ -1073,7 +1073,7 @@ pub fn last_os_error() -> String {
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
@ -1086,13 +1086,13 @@ static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
* 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")]

View File

@ -28,20 +28,18 @@ pub use self::imp::write;
// 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
}
@ -268,7 +266,7 @@ mod imp {
// 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:"));
@ -301,7 +299,7 @@ mod imp {
// 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:"));
@ -931,7 +929,7 @@ mod imp {
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

View File

@ -41,8 +41,8 @@ pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
}
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,
}
@ -50,7 +50,7 @@ pub fn min_stack() -> uint {
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;
}

View File

@ -93,12 +93,10 @@
//! ```
//! 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)]

View File

@ -545,8 +545,8 @@ mod tests {
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();
@ -604,7 +604,7 @@ mod tests {
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();

View File

@ -127,9 +127,9 @@ enum Flavor {
/// ```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
/// }
@ -536,7 +536,7 @@ mod test {
#[test]
fn smoke_static() {
static mut m: StaticMutex = MUTEX_INIT;
static m: StaticMutex = MUTEX_INIT;
unsafe {
drop(m.lock());
drop(m.lock());
@ -546,7 +546,7 @@ mod test {
#[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;

View File

@ -30,13 +30,11 @@ use mutex::{StaticMutex, MUTEX_INIT};
/// ```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,
@ -128,17 +126,17 @@ mod test {
#[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();

View File

@ -192,7 +192,7 @@ pub fn precise_time_ns() -> u64 {
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);

View File

@ -1,3 +1,12 @@
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