diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-10 21:59:10 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-10 22:09:49 -0700 |
| commit | dae48a07f34dcf714b3b57029f4e03a0b95a269e (patch) | |
| tree | 4ced3fe4c6c167508f0f7d1308473dfec676846d /src/libnative | |
| parent | 1add4dedc131d5f98d82feafe80d92ed1f3f6d49 (diff) | |
| download | rust-dae48a07f34dcf714b3b57029f4e03a0b95a269e.tar.gz rust-dae48a07f34dcf714b3b57029f4e03a0b95a269e.zip | |
Register new snapshots
Also convert a number of `static mut` to just a plain old `static` and remove some unsafe blocks.
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/helper_thread.rs | 4 | ||||
| -rw-r--r-- | src/libnative/io/net.rs | 2 | ||||
| -rw-r--r-- | src/libnative/io/process.rs | 6 | ||||
| -rw-r--r-- | src/libnative/io/timer_unix.rs | 14 | ||||
| -rw-r--r-- | src/libnative/io/timer_windows.rs | 10 |
5 files changed, 18 insertions, 18 deletions
diff --git a/src/libnative/io/helper_thread.rs b/src/libnative/io/helper_thread.rs index 1f51f8eacd6..8aff1732a41 100644 --- a/src/libnative/io/helper_thread.rs +++ b/src/libnative/io/helper_thread.rs @@ -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 }, diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index aa2b1a6f14e..a4b97a3eb84 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -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 { diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index 7a0c1c35d65..2ca25f1eeb9 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -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")), diff --git a/src/libnative/io/timer_unix.rs b/src/libnative/io/timer_unix.rs index 8c6fd83a76b..4d4ba33aec4 100644 --- a/src/libnative/io/timer_unix.rs +++ b/src/libnative/io/timer_unix.rs @@ -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)); } } diff --git a/src/libnative/io/timer_windows.rs b/src/libnative/io/timer_windows.rs index 82d31811172..421cc28e157 100644 --- a/src/libnative/io/timer_windows.rs +++ b/src/libnative/io/timer_windows.rs @@ -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; } } |
