diff options
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/mutex.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sys/windows/pipe.rs | 27 | ||||
| -rw-r--r-- | src/libstd/sys/windows/tcp.rs | 11 |
3 files changed, 28 insertions, 26 deletions
diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index f561e0121b3..1def99a3741 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -10,7 +10,7 @@ use prelude::v1::*; -use sync::atomic; +use sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering}; use alloc::{self, heap}; use libc::DWORD; @@ -18,9 +18,9 @@ use sys::sync as ffi; const SPIN_COUNT: DWORD = 4000; -pub struct Mutex { inner: atomic::AtomicUint } +pub struct Mutex { inner: AtomicUint } -pub const MUTEX_INIT: Mutex = Mutex { inner: atomic::ATOMIC_UINT_INIT }; +pub const MUTEX_INIT: Mutex = Mutex { inner: ATOMIC_UINT_INIT }; unsafe impl Sync for Mutex {} @@ -32,7 +32,7 @@ pub unsafe fn raw(m: &Mutex) -> ffi::LPCRITICAL_SECTION { impl Mutex { #[inline] pub unsafe fn new() -> Mutex { - Mutex { inner: atomic::AtomicUint::new(init_lock() as uint) } + Mutex { inner: AtomicUint::new(init_lock() as uint) } } #[inline] pub unsafe fn lock(&self) { @@ -47,22 +47,22 @@ impl Mutex { ffi::LeaveCriticalSection(self.get()) } pub unsafe fn destroy(&self) { - let lock = self.inner.swap(0, atomic::SeqCst); + let lock = self.inner.swap(0, Ordering::SeqCst); if lock != 0 { free_lock(lock as ffi::LPCRITICAL_SECTION) } } unsafe fn get(&self) -> ffi::LPCRITICAL_SECTION { - match self.inner.load(atomic::SeqCst) { + match self.inner.load(Ordering::SeqCst) { 0 => {} n => return n as ffi::LPCRITICAL_SECTION } let lock = init_lock(); - match self.inner.compare_and_swap(0, lock as uint, atomic::SeqCst) { + match self.inner.compare_and_swap(0, lock as uint, Ordering::SeqCst) { 0 => return lock as ffi::LPCRITICAL_SECTION, _ => {} } free_lock(lock); - return self.inner.load(atomic::SeqCst) as ffi::LPCRITICAL_SECTION; + return self.inner.load(Ordering::SeqCst) as ffi::LPCRITICAL_SECTION; } } diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 0edae75a9ce..9057515cad2 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -90,7 +90,8 @@ use libc; use c_str::CString; use mem; use ptr; -use sync::{atomic, Arc, Mutex}; +use sync::{Arc, Mutex}; +use sync::atomic::{AtomicBool, Ordering}; use io::{self, IoError, IoResult}; use sys_common::{self, eof}; @@ -126,8 +127,8 @@ impl Drop for Event { struct Inner { handle: libc::HANDLE, lock: Mutex<()>, - read_closed: atomic::AtomicBool, - write_closed: atomic::AtomicBool, + read_closed: AtomicBool, + write_closed: AtomicBool, } impl Inner { @@ -135,8 +136,8 @@ impl Inner { Inner { handle: handle, lock: Mutex::new(()), - read_closed: atomic::AtomicBool::new(false), - write_closed: atomic::AtomicBool::new(false), + read_closed: AtomicBool::new(false), + write_closed: AtomicBool::new(false), } } } @@ -334,11 +335,11 @@ impl UnixStream { pub fn handle(&self) -> libc::HANDLE { self.inner.handle } fn read_closed(&self) -> bool { - self.inner.read_closed.load(atomic::SeqCst) + self.inner.read_closed.load(Ordering::SeqCst) } fn write_closed(&self) -> bool { - self.inner.write_closed.load(atomic::SeqCst) + self.inner.write_closed.load(Ordering::SeqCst) } fn cancel_io(&self) -> IoResult<()> { @@ -517,14 +518,14 @@ impl UnixStream { // and 2 with a lock with respect to close_read(), we're guaranteed that // no thread will erroneously sit in a read forever. let _guard = unsafe { self.inner.lock.lock() }; - self.inner.read_closed.store(true, atomic::SeqCst); + self.inner.read_closed.store(true, Ordering::SeqCst); self.cancel_io() } pub fn close_write(&mut self) -> IoResult<()> { // see comments in close_read() for why this lock is necessary let _guard = unsafe { self.inner.lock.lock() }; - self.inner.write_closed.store(true, atomic::SeqCst); + self.inner.write_closed.store(true, Ordering::SeqCst); self.cancel_io() } @@ -586,7 +587,7 @@ impl UnixListener { deadline: 0, inner: Arc::new(AcceptorState { abort: try!(Event::new(true, false)), - closed: atomic::AtomicBool::new(false), + closed: AtomicBool::new(false), }), }) } @@ -614,7 +615,7 @@ unsafe impl Sync for UnixAcceptor {} struct AcceptorState { abort: Event, - closed: atomic::AtomicBool, + closed: AtomicBool, } unsafe impl Send for AcceptorState {} @@ -658,7 +659,7 @@ impl UnixAcceptor { // If we've had an artificial call to close_accept, be sure to never // proceed in accepting new clients in the future - if self.inner.closed.load(atomic::SeqCst) { return Err(eof()) } + if self.inner.closed.load(Ordering::SeqCst) { return Err(eof()) } let name = try!(to_utf16(self.listener.name.as_str())); @@ -734,7 +735,7 @@ impl UnixAcceptor { } pub fn close_accept(&mut self) -> IoResult<()> { - self.inner.closed.store(true, atomic::SeqCst); + self.inner.closed.store(true, Ordering::SeqCst); let ret = unsafe { c::SetEvent(self.inner.abort.handle()) }; diff --git a/src/libstd/sys/windows/tcp.rs b/src/libstd/sys/windows/tcp.rs index 1c8ec2a80a7..77139b52efa 100644 --- a/src/libstd/sys/windows/tcp.rs +++ b/src/libstd/sys/windows/tcp.rs @@ -15,7 +15,8 @@ use mem; use ptr; use prelude::v1::*; use super::{last_error, last_net_error, retry, sock_t}; -use sync::{Arc, atomic}; +use sync::Arc; +use sync::atomic::{AtomicBool, Ordering}; use sys::fs::FileDesc; use sys::{self, c, set_nonblocking, wouldblock, timer}; use sys_common::{self, timeout, eof, net}; @@ -91,7 +92,7 @@ impl TcpListener { listener: self, abort: try!(Event::new()), accept: accept, - closed: atomic::AtomicBool::new(false), + closed: AtomicBool::new(false), }), deadline: 0, }) @@ -122,7 +123,7 @@ struct AcceptorInner { listener: TcpListener, abort: Event, accept: Event, - closed: atomic::AtomicBool, + closed: AtomicBool, } unsafe impl Send for AcceptorInner {} @@ -154,7 +155,7 @@ impl TcpAcceptor { // stolen, so we do all of this in a loop as well. let events = [self.inner.abort.handle(), self.inner.accept.handle()]; - while !self.inner.closed.load(atomic::SeqCst) { + while !self.inner.closed.load(Ordering::SeqCst) { let ms = if self.deadline == 0 { c::WSA_INFINITE as u64 } else { @@ -214,7 +215,7 @@ impl TcpAcceptor { } pub fn close_accept(&mut self) -> IoResult<()> { - self.inner.closed.store(true, atomic::SeqCst); + self.inner.closed.store(true, Ordering::SeqCst); let ret = unsafe { c::WSASetEvent(self.inner.abort.handle()) }; if ret == libc::TRUE { Ok(()) |
