diff options
Diffstat (limited to 'src/libstd')
51 files changed, 242 insertions, 1027 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 857a7072009..bcd87f6786d 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -13,7 +13,6 @@ //! Operations on ASCII strings and characters #![unstable = "unsure about placement and naming"] -#![allow(deprecated)] use core::kinds::Sized; use iter::IteratorExt; diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 4fb4f220c59..9c96a9cac78 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -266,10 +266,6 @@ impl CString { self.buf } - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub unsafe fn unwrap(self) -> *const libc::c_char { self.into_inner() } - /// Return the number of bytes in the CString (not including the NUL /// terminator). #[inline] diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 40942f1b987..4a20208f31a 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -150,10 +150,6 @@ impl<T> CVec<T> { self.base } - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub unsafe fn unwrap(self) -> *mut T { self.into_inner() } - /// Returns the number of items in this vector. pub fn len(&self) -> uint { self.len } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index c63484396d2..651f31b205d 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -16,7 +16,7 @@ use self::VacantEntryState::*; use borrow::BorrowFrom; use clone::Clone; -use cmp::{max, Eq, Equiv, PartialEq}; +use cmp::{max, Eq, PartialEq}; use default::Default; use fmt::{self, Show}; use hash::{Hash, Hasher, RandomSipHasher}; @@ -444,20 +444,6 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { table::make_hash(&self.hasher, x) } - #[allow(deprecated)] - fn search_equiv<'a, Sized? Q: Hash<S> + Equiv<K>>(&'a self, q: &Q) - -> Option<FullBucketImm<'a, K, V>> { - let hash = self.make_hash(q); - search_hashed(&self.table, hash, |k| q.equiv(k)).into_option() - } - - #[allow(deprecated)] - fn search_equiv_mut<'a, Sized? Q: Hash<S> + Equiv<K>>(&'a mut self, q: &Q) - -> Option<FullBucketMut<'a, K, V>> { - let hash = self.make_hash(q); - search_hashed(&mut self.table, hash, |k| q.equiv(k)).into_option() - } - /// Search for a key, yielding the index if it's found in the hashtable. /// If you already have the hash for the key lying around, use /// search_hashed. @@ -807,30 +793,6 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { } } - /// Deprecated: use `contains_key` and `BorrowFrom` instead. - #[deprecated = "use contains_key and BorrowFrom instead"] - pub fn contains_key_equiv<Sized? Q: Hash<S> + Equiv<K>>(&self, key: &Q) -> bool { - self.search_equiv(key).is_some() - } - - /// Deprecated: use `get` and `BorrowFrom` instead. - #[deprecated = "use get and BorrowFrom instead"] - pub fn find_equiv<'a, Sized? Q: Hash<S> + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> { - self.search_equiv(k).map(|bucket| bucket.into_refs().1) - } - - /// Deprecated: use `remove` and `BorrowFrom` instead. - #[deprecated = "use remove and BorrowFrom instead"] - pub fn pop_equiv<Sized? Q:Hash<S> + Equiv<K>>(&mut self, k: &Q) -> Option<V> { - if self.table.size() == 0 { - return None - } - - self.reserve(1); - - self.search_equiv_mut(k).map(|bucket| pop_internal(bucket).1) - } - /// An iterator visiting all keys in arbitrary order. /// Iterator element type is `&'a K`. /// @@ -1047,12 +1009,6 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { self.drain(); } - /// Deprecated: Renamed to `get`. - #[deprecated = "Renamed to `get`"] - pub fn find(&self, k: &K) -> Option<&V> { - self.get(k) - } - /// Returns a reference to the value corresponding to the key. /// /// The key may be any borrowed form of the map's key type, but @@ -1099,12 +1055,6 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { self.search(k).is_some() } - /// Deprecated: Renamed to `get_mut`. - #[deprecated = "Renamed to `get_mut`"] - pub fn find_mut(&mut self, k: &K) -> Option<&mut V> { - self.get_mut(k) - } - /// Returns a mutable reference to the value corresponding to the key. /// /// The key may be any borrowed form of the map's key type, but @@ -1131,12 +1081,6 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { self.search_mut(k).map(|bucket| bucket.into_mut_refs().1) } - /// Deprecated: Renamed to `insert`. - #[deprecated = "Renamed to `insert`"] - pub fn swap(&mut self, k: K, v: V) -> Option<V> { - self.insert(k, v) - } - /// Inserts a key-value pair from the map. If the key already had a value /// present in the map, that value is returned. Otherwise, `None` is returned. /// @@ -1165,12 +1109,6 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { retval } - /// Deprecated: Renamed to `remove`. - #[deprecated = "Renamed to `remove`"] - pub fn pop(&mut self, k: &K) -> Option<V> { - self.remove(k) - } - /// Removes a key from the map, returning the value at the key if the key /// was previously in the map. /// @@ -1246,24 +1184,6 @@ fn search_entry_hashed<'a, K: Eq, V>(table: &'a mut RawTable<K,V>, hash: SafeHas } } -impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> { - /// Deprecated: Use `map.get(k).cloned()`. - /// - /// Return a copy of the value corresponding to the key. - #[deprecated = "Use `map.get(k).cloned()`"] - pub fn find_copy(&self, k: &K) -> Option<V> { - self.get(k).cloned() - } - - /// Deprecated: Use `map[k].clone()`. - /// - /// Return a copy of the value corresponding to the key. - #[deprecated = "Use `map[k].clone()`"] - pub fn get_copy(&self, k: &K) -> V { - self[*k].clone() - } -} - #[stable] impl<K: Eq + Hash<S>, V: PartialEq, S, H: Hasher<S>> PartialEq for HashMap<K, V, H> { fn eq(&self, other: &HashMap<K, V, H>) -> bool { @@ -1574,30 +1494,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Extend<(K, V)> for HashMap<K mod test_map { use prelude::v1::*; - use cmp::Equiv; use super::HashMap; use super::Entry::{Occupied, Vacant}; - use hash; - use iter::{range_inclusive, range_step_inclusive}; + use iter::{range_inclusive, range_step_inclusive, repeat}; use cell::RefCell; use rand::{weak_rng, Rng}; - struct KindaIntLike(int); - - #[allow(deprecated)] - impl Equiv<int> for KindaIntLike { - fn equiv(&self, other: &int) -> bool { - let KindaIntLike(this) = *self; - this == *other - } - } - impl<S: hash::Writer> hash::Hash<S> for KindaIntLike { - fn hash(&self, state: &mut S) { - let KindaIntLike(this) = *self; - this.hash(state) - } - } - #[test] fn test_create_capacity_zero() { let mut m = HashMap::with_capacity(0); @@ -1654,7 +1556,7 @@ mod test_map { #[test] fn test_drops() { DROP_VECTOR.with(|slot| { - *slot.borrow_mut() = Vec::from_elem(200, 0i); + *slot.borrow_mut() = repeat(0i).take(200).collect(); }); { @@ -1713,7 +1615,7 @@ mod test_map { #[test] fn test_move_iter_drops() { DROP_VECTOR.with(|v| { - *v.borrow_mut() = Vec::from_elem(200, 0i); + *v.borrow_mut() = repeat(0).take(200).collect(); }); let hm = { @@ -1912,15 +1814,6 @@ mod test_map { } #[test] - #[allow(deprecated)] - fn test_pop_equiv() { - let mut m = HashMap::new(); - m.insert(1i, 2i); - assert_eq!(m.pop_equiv(&KindaIntLike(1)), Some(2)); - assert_eq!(m.pop_equiv(&KindaIntLike(1)), None); - } - - #[test] fn test_iterate() { let mut m = HashMap::with_capacity(4); for i in range(0u, 32) { @@ -1971,27 +1864,6 @@ mod test_map { } #[test] - #[allow(deprecated)] - fn test_find_copy() { - let mut m = HashMap::new(); - assert!(m.get(&1i).is_none()); - - for i in range(1i, 10000) { - m.insert(i, i + 7); - match m.find_copy(&i) { - None => panic!(), - Some(v) => assert_eq!(v, i + 7) - } - for j in range(1i, i/100) { - match m.find_copy(&j) { - None => panic!(), - Some(v) => assert_eq!(v, j + 7) - } - } - } - } - - #[test] fn test_eq() { let mut m1 = HashMap::new(); m1.insert(1i, 2i); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 28c78ca3a91..b1824db93aa 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -12,7 +12,7 @@ use borrow::BorrowFrom; use clone::Clone; -use cmp::{Eq, Equiv, PartialEq}; +use cmp::{Eq, PartialEq}; use core::kinds::Sized; use default::Default; use fmt::Show; @@ -228,13 +228,6 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> { self.map.shrink_to_fit() } - /// Deprecated: use `contains` and `BorrowFrom`. - #[deprecated = "use contains and BorrowFrom"] - #[allow(deprecated)] - pub fn contains_equiv<Sized? Q: Hash<S> + Equiv<T>>(&self, value: &Q) -> bool { - self.map.contains_key_equiv(value) - } - /// An iterator visiting all elements in arbitrary order. /// Iterator element type is &'a T. /// diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 0d44e6d869a..4be83bfc664 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -314,17 +314,9 @@ pub use core_collections::{BinaryHeap, Bitv, BitvSet, BTreeMap, BTreeSet}; pub use core_collections::{DList, RingBuf, VecMap}; -/// Deprecated: Moved to collect-rs: https://github.com/Gankro/collect-rs/ -#[deprecated = "Moved to collect-rs: https://github.com/Gankro/collect-rs/"] -pub use core_collections::EnumSet; - pub use core_collections::{binary_heap, bitv, bitv_set, btree_map, btree_set}; pub use core_collections::{dlist, ring_buf, vec_map}; -/// Deprecated: Moved to collect-rs: https://github.com/Gankro/collect-rs/ -#[deprecated = "Moved to collect-rs: https://github.com/Gankro/collect-rs/"] -pub use core_collections::enum_set; - pub use self::hash_map::HashMap; pub use self::hash_set::HashSet; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index d97f4a7bc34..c56acd38e81 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -89,10 +89,6 @@ impl<R: Reader> BufferedReader<R> { /// /// Note that any leftover data in the internal buffer is lost. pub fn into_inner(self) -> R { self.inner } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> R { self.into_inner() } } impl<R: Reader> Buffer for BufferedReader<R> { @@ -198,10 +194,6 @@ impl<W: Writer> BufferedWriter<W> { self.flush_buf().unwrap(); self.inner.take().unwrap() } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> W { self.into_inner() } } impl<W: Writer> Writer for BufferedWriter<W> { @@ -262,10 +254,6 @@ impl<W: Writer> LineBufferedWriter<W> { /// /// The internal buffer is flushed before returning the writer. pub fn into_inner(self) -> W { self.inner.into_inner() } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> W { self.into_inner() } } impl<W: Writer> Writer for LineBufferedWriter<W> { @@ -374,10 +362,6 @@ impl<S: Stream> BufferedStream<S> { let InternalBufferedWriter(w) = self.inner.inner; w.into_inner() } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> S { self.into_inner() } } impl<S: Stream> Buffer for BufferedStream<S> { diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 8c097a65db7..af08eea210e 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -518,7 +518,7 @@ mod bench { ({ use super::u64_from_be_bytes; - let data = Vec::from_fn($stride*100+$start_index, |i| i as u8); + let data = range(0u8, $stride*100+$start_index).collect::<Vec<_>>(); let mut sum = 0u64; $b.iter(|| { let mut i = $start_index; diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 1615541e37d..5c17644a1ac 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -12,8 +12,6 @@ //! Readers and Writers for in-memory buffers -#![allow(deprecated)] - use cmp::min; use option::Option::None; use result::Result::{Err, Ok}; @@ -70,6 +68,7 @@ pub struct MemWriter { buf: Vec<u8>, } +#[allow(deprecated)] impl MemWriter { /// Create a new `MemWriter`. #[inline] @@ -96,10 +95,6 @@ impl MemWriter { /// Unwraps this `MemWriter`, returning the underlying buffer #[inline] pub fn into_inner(self) -> Vec<u8> { self.buf } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> Vec<u8> { self.into_inner() } } impl Writer for MemWriter { @@ -155,10 +150,6 @@ impl MemReader { /// Unwraps this `MemReader`, returning the underlying buffer #[inline] pub fn into_inner(self) -> Vec<u8> { self.buf } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> Vec<u8> { self.into_inner() } } impl Reader for MemReader { @@ -401,10 +392,11 @@ mod test { extern crate "test" as test_crate; use prelude::v1::*; - use super::*; use io::{SeekSet, SeekCur, SeekEnd}; use io; + use iter::repeat; use self::test_crate::Bencher; + use super::*; #[test] fn test_vec_writer() { @@ -664,7 +656,7 @@ mod test { } fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) { - let src: Vec<u8> = Vec::from_elem(len, 5); + let src: Vec<u8> = repeat(5).take(len).collect(); b.bytes = (times * len) as u64; b.iter(|| { @@ -673,7 +665,7 @@ mod test { wr.write(src.as_slice()).unwrap(); } - let v = wr.unwrap(); + let v = wr.into_inner(); assert_eq!(v.len(), times * len); assert!(v.iter().all(|x| *x == 5)); }); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 590231dcd82..ae401a04a96 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -263,7 +263,6 @@ pub use self::timer::Timer; pub use self::net::ip::IpAddr; pub use self::net::tcp::TcpListener; pub use self::net::tcp::TcpStream; -pub use self::net::udp::UdpStream; pub use self::pipe::PipeStream; pub use self::process::{Process, Command}; pub use self::tempfile::TempDir; @@ -863,23 +862,6 @@ pub trait Reader { } /// A reader which can be converted to a RefReader. -#[deprecated = "use ByRefReader instead"] -pub trait AsRefReader { - /// Creates a wrapper around a mutable reference to the reader. - /// - /// This is useful to allow applying adaptors while still - /// retaining ownership of the original value. - fn by_ref<'a>(&'a mut self) -> RefReader<'a, Self>; -} - -#[allow(deprecated)] -impl<T: Reader> AsRefReader for T { - fn by_ref<'a>(&'a mut self) -> RefReader<'a, T> { - RefReader { inner: self } - } -} - -/// A reader which can be converted to a RefReader. pub trait ByRefReader { /// Creates a wrapper around a mutable reference to the reader. /// @@ -1243,24 +1225,6 @@ pub trait Writer { } /// A writer which can be converted to a RefWriter. -#[deprecated = "use ByRefWriter instead"] -pub trait AsRefWriter { - /// Creates a wrapper around a mutable reference to the writer. - /// - /// This is useful to allow applying wrappers while still - /// retaining ownership of the original value. - #[inline] - fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self>; -} - -#[allow(deprecated)] -impl<T: Writer> AsRefWriter for T { - fn by_ref<'a>(&'a mut self) -> RefWriter<'a, T> { - RefWriter { inner: self } - } -} - -/// A writer which can be converted to a RefWriter. pub trait ByRefWriter { /// Creates a wrapper around a mutable reference to the writer. /// @@ -1847,64 +1811,6 @@ bitflags! { #[doc = "All possible permissions enabled."] const ALL_PERMISSIONS = USER_RWX.bits | GROUP_RWX.bits | OTHER_RWX.bits, - - // Deprecated names - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_READ instead"] - const UserRead = USER_READ.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_WRITE instead"] - const UserWrite = USER_WRITE.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_EXECUTE instead"] - const UserExecute = USER_EXECUTE.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use GROUP_READ instead"] - const GroupRead = GROUP_READ.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use GROUP_WRITE instead"] - const GroupWrite = GROUP_WRITE.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use GROUP_EXECUTE instead"] - const GroupExecute = GROUP_EXECUTE.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use OTHER_READ instead"] - const OtherRead = OTHER_READ.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use OTHER_WRITE instead"] - const OtherWrite = OTHER_WRITE.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use OTHER_EXECUTE instead"] - const OtherExecute = OTHER_EXECUTE.bits, - - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_RWX instead"] - const UserRWX = USER_RWX.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use GROUP_RWX instead"] - const GroupRWX = GROUP_RWX.bits, - #[allow(non_upper_case_globals)] - #[deprecated = "use OTHER_RWX instead"] - const OtherRWX = OTHER_RWX.bits, - - #[doc = "Deprecated: use `USER_FILE` instead."] - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_FILE instead"] - const UserFile = USER_FILE.bits, - - #[doc = "Deprecated: use `USER_DIR` instead."] - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_DIR instead"] - const UserDir = USER_DIR.bits, - #[doc = "Deprecated: use `USER_EXEC` instead."] - #[allow(non_upper_case_globals)] - #[deprecated = "use USER_EXEC instead"] - const UserExec = USER_EXEC.bits, - - #[doc = "Deprecated: use `ALL_PERMISSIONS` instead"] - #[allow(non_upper_case_globals)] - #[deprecated = "use ALL_PERMISSIONS instead"] - const AllPermissions = ALL_PERMISSIONS.bits, } } diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 6c167359966..a4db0d4f5de 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -17,10 +17,8 @@ use clone::Clone; use io::net::ip::{SocketAddr, IpAddr, ToSocketAddr}; -use io::{Reader, Writer, IoResult}; -use ops::FnOnce; +use io::IoResult; use option::Option; -use result::Result::{Ok, Err}; use sys::udp::UdpSocket as UdpSocketImp; use sys_common; @@ -88,21 +86,6 @@ impl UdpSocket { super::with_addresses(addr, |addr| self.inner.send_to(buf, addr)) } - /// Creates a `UdpStream`, which allows use of the `Reader` and `Writer` - /// traits to receive and send data from the same address. This transfers - /// ownership of the socket to the stream. - /// - /// Note that this call does not perform any actual network communication, - /// because UDP is a datagram protocol. - #[deprecated = "`UdpStream` has been deprecated"] - #[allow(deprecated)] - pub fn connect(self, other: SocketAddr) -> UdpStream { - UdpStream { - socket: self, - connected_to: other, - } - } - /// Returns the socket address that this socket was created from. pub fn socket_name(&mut self) -> IoResult<SocketAddr> { self.inner.socket_name() @@ -192,59 +175,6 @@ impl sys_common::AsInner<UdpSocketImp> for UdpSocket { } } -/// A type that allows convenient usage of a UDP stream connected to one -/// address via the `Reader` and `Writer` traits. -/// -/// # Note -/// -/// This structure has been deprecated because `Reader` is a stream-oriented API but UDP -/// is a packet-oriented protocol. Every `Reader` method will read a whole packet and -/// throw all superfluous bytes away so that they are no longer available for further -/// method calls. -#[deprecated] -pub struct UdpStream { - socket: UdpSocket, - connected_to: SocketAddr -} - -impl UdpStream { - /// Allows access to the underlying UDP socket owned by this stream. This - /// is useful to, for example, use the socket to send data to hosts other - /// than the one that this stream is connected to. - pub fn as_socket<T, F>(&mut self, f: F) -> T where - F: FnOnce(&mut UdpSocket) -> T, - { - f(&mut self.socket) - } - - /// Consumes this UDP stream and returns out the underlying socket. - pub fn disconnect(self) -> UdpSocket { - self.socket - } -} - -impl Reader for UdpStream { - /// Returns the next non-empty message from the specified address. - fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { - let peer = self.connected_to; - self.as_socket(|sock| { - loop { - let (nread, src) = try!(sock.recv_from(buf)); - if nread > 0 && src == peer { - return Ok(nread); - } - } - }) - } -} - -impl Writer for UdpStream { - fn write(&mut self, buf: &[u8]) -> IoResult<()> { - let connected_to = self.connected_to; - self.as_socket(|sock| sock.send_to(buf, connected_to)) - } -} - #[cfg(test)] #[allow(experimental)] mod test { @@ -337,91 +267,6 @@ mod test { } } - #[test] - #[allow(deprecated)] - fn stream_smoke_test_ip4() { - let server_ip = next_test_ip4(); - let client_ip = next_test_ip4(); - let dummy_ip = next_test_ip4(); - let (tx1, rx1) = channel(); - let (tx2, rx2) = channel(); - - let _t = Thread::spawn(move|| { - let send_as = |&:ip, val: &[u8]| { - match UdpSocket::bind(ip) { - Ok(client) => { - let client = box client; - let mut stream = client.connect(server_ip); - stream.write(val).unwrap(); - } - Err(..) => panic!() - } - }; - rx1.recv().unwrap(); - send_as(dummy_ip, &[98]); - send_as(client_ip, &[99]); - tx2.send(()).unwrap(); - }); - - match UdpSocket::bind(server_ip) { - Ok(server) => { - let server = box server; - let mut stream = server.connect(client_ip); - tx1.send(()).unwrap(); - let mut buf = [0]; - match stream.read(&mut buf) { - Ok(nread) => { - assert_eq!(nread, 1); - assert_eq!(buf[0], 99); - } - Err(..) => panic!(), - } - } - Err(..) => panic!() - } - rx2.recv().unwrap(); - } - - #[test] - #[allow(deprecated)] - fn stream_smoke_test_ip6() { - let server_ip = next_test_ip6(); - let client_ip = next_test_ip6(); - let (tx1, rx1) = channel(); - let (tx2, rx2) = channel(); - - let _t = Thread::spawn(move|| { - match UdpSocket::bind(client_ip) { - Ok(client) => { - let client = box client; - let mut stream = client.connect(server_ip); - rx1.recv().unwrap(); - stream.write(&[99]).unwrap(); - } - Err(..) => panic!() - } - tx2.send(()).unwrap(); - }); - - match UdpSocket::bind(server_ip) { - Ok(server) => { - let server = box server; - let mut stream = server.connect(client_ip); - tx1.send(()).unwrap(); - let mut buf = [0]; - match stream.read(&mut buf) { - Ok(nread) => { - assert_eq!(nread, 1); - assert_eq!(buf[0], 99); - } - Err(..) => panic!() - } - } - Err(..) => panic!() - } - rx2.recv().unwrap(); - } - pub fn socket_name(addr: SocketAddr) { let server = UdpSocket::bind(addr); diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs index 5cf86676651..45e0dd4e8e5 100644 --- a/src/libstd/io/tempfile.rs +++ b/src/libstd/io/tempfile.rs @@ -19,7 +19,7 @@ use option::Option::{None, Some}; use os; use path::{Path, GenericPath}; use result::Result::{Ok, Err}; -use sync::atomic; +use sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering}; /// A wrapper for a path to temporary directory implementing automatic /// scope-based deletion. @@ -90,14 +90,14 @@ impl TempDir { return TempDir::new_in(&abs_tmpdir, suffix); } - static CNT: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT; + static CNT: AtomicUint = ATOMIC_UINT_INIT; let mut attempts = 0u; loop { let filename = format!("rs-{}-{}-{}", unsafe { libc::getpid() }, - CNT.fetch_add(1, atomic::SeqCst), + CNT.fetch_add(1, Ordering::SeqCst), suffix); let p = tmpdir.join(filename); match fs::mkdir(&p, io::USER_RWX) { @@ -129,10 +129,6 @@ impl TempDir { tmpdir.path.take().unwrap() } - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> Path { self.into_inner() } - /// Access the wrapped `std::path::Path` to the temporary directory. pub fn path<'a>(&'a self) -> &'a Path { self.path.as_ref().unwrap() diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index 2f87abd0ee2..3ce56c907b3 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -17,12 +17,12 @@ use prelude::v1::*; use libc; use os; use std::io::net::ip::*; -use sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Relaxed}; +use sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering}; /// Get a port number, starting at 9600, for use in tests pub fn next_test_port() -> u16 { static NEXT_OFFSET: AtomicUint = ATOMIC_UINT_INIT; - base_port() + NEXT_OFFSET.fetch_add(1, Relaxed) as u16 + base_port() + NEXT_OFFSET.fetch_add(1, Ordering::Relaxed) as u16 } /// Get a temporary path which could be the location of a unix socket @@ -34,7 +34,7 @@ pub fn next_test_unix() -> Path { let string = format!("rust-test-unix-path-{}-{}-{}", base_port(), unsafe {libc::getpid()}, - COUNT.fetch_add(1, Relaxed)); + COUNT.fetch_add(1, Ordering::Relaxed)); if cfg!(unix) { os::tmpdir().join(string) } else { diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 1381ad17ea2..86fa68d63ac 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -30,10 +30,6 @@ impl<R: Reader> LimitReader<R> { /// Consumes the `LimitReader`, returning the underlying `Reader`. pub fn into_inner(self) -> R { self.inner } - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner"] - pub fn unwrap(self) -> R { self.into_inner() } - /// Returns the number of bytes that can be read before the `LimitReader` /// will return EOF. /// @@ -219,10 +215,6 @@ impl<R: Reader, W: Writer> TeeReader<R, W> { let TeeReader { reader, writer } = self; (reader, writer) } - - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner"] - pub fn unwrap(self) -> (R, W) { self.into_inner() } } impl<R: Reader, W: Writer> Reader for TeeReader<R, W> { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7c8aab2b31d..608ad9882b9 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -226,7 +226,6 @@ pub mod hash; /* Threads and communication */ -pub mod task; pub mod thread; pub mod sync; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 8f21fb0b8b9..c126eb1d6cf 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -21,12 +21,8 @@ #[cfg(test)] use ops::{Add, Sub, Mul, Div, Rem}; #[cfg(test)] use kinds::Copy; -pub use core::num::{Num, div_rem, Zero, zero, One, one}; -pub use core::num::{Unsigned, pow, Bounded}; -pub use core::num::{Primitive, Int, SignedInt, UnsignedInt}; +pub use core::num::{Int, SignedInt, UnsignedInt}; pub use core::num::{cast, FromPrimitive, NumCast, ToPrimitive}; -pub use core::num::{next_power_of_two, is_power_of_two}; -pub use core::num::{checked_next_power_of_two}; pub use core::num::{from_int, from_i8, from_i16, from_i32, from_i64}; pub use core::num::{from_uint, from_u8, from_u16, from_u32, from_u64}; pub use core::num::{from_f32, from_f64}; @@ -118,11 +114,6 @@ pub trait FloatMath: Float { // DEPRECATED -#[deprecated = "Use `FloatMath::abs_sub`"] -pub fn abs_sub<T: FloatMath>(x: T, y: T) -> T { - x.abs_sub(y) -} - /// Helper function for testing numeric operations #[cfg(test)] pub fn test_num<T>(ten: T, two: T) where @@ -804,7 +795,7 @@ mod bench { #[bench] fn bench_pow_function(b: &mut Bencher) { - let v = Vec::from_fn(1024u, |n| n); + let v = range(0, 1024u).collect::<Vec<_>>(); b.iter(|| {v.iter().fold(0u, |old, new| old.pow(*new));}); } } diff --git a/src/libstd/num/u16.rs b/src/libstd/num/u16.rs index 46699b78599..7cb6a8ffe07 100644 --- a/src/libstd/num/u16.rs +++ b/src/libstd/num/u16.rs @@ -15,6 +15,4 @@ pub use core::u16::{BITS, BYTES, MIN, MAX}; -use ops::FnOnce; - uint_module! { u16 } diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs index 45ee9251d2f..43b01ddb16b 100644 --- a/src/libstd/num/u32.rs +++ b/src/libstd/num/u32.rs @@ -15,6 +15,4 @@ pub use core::u32::{BITS, BYTES, MIN, MAX}; -use ops::FnOnce; - uint_module! { u32 } diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs index 1d8ff77dac8..79e7f237051 100644 --- a/src/libstd/num/u64.rs +++ b/src/libstd/num/u64.rs @@ -15,6 +15,4 @@ pub use core::u64::{BITS, BYTES, MIN, MAX}; -use ops::FnOnce; - uint_module! { u64 } diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs index 0663ace2e5b..3da2fabe3f2 100644 --- a/src/libstd/num/u8.rs +++ b/src/libstd/num/u8.rs @@ -15,6 +15,4 @@ pub use core::u8::{BITS, BYTES, MIN, MAX}; -use ops::FnOnce; - uint_module! { u8 } diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index cd000b3098b..0fbc0953b20 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -15,6 +15,4 @@ pub use core::uint::{BITS, BYTES, MIN, MAX}; -use ops::FnOnce; - uint_module! { uint } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index b52e4fda7af..7818f4a0534 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -17,41 +17,14 @@ macro_rules! uint_module { ($T:ty) => ( // String conversion functions and impl num -> str -/// Convert to a string as a byte slice in a given base. -/// -/// Use in place of x.to_string() when you do not need to store the string permanently -/// -/// # Examples -/// -/// ``` -/// #![allow(deprecated)] -/// -/// std::uint::to_str_bytes(123, 10, |v| { -/// assert!(v == "123".as_bytes()); -/// }); -/// ``` -#[inline] -#[deprecated = "just use .to_string(), or a BufWriter with write! if you mustn't allocate"] -pub fn to_str_bytes<U, F>(n: $T, radix: uint, f: F) -> U where - F: FnOnce(&[u8]) -> U, -{ - use io::{Writer, Seek}; - // The radix can be as low as 2, so we need at least 64 characters for a - // base 2 number, and then we need another for a possible '-' character. - let mut buf = [0u8; 65]; - let amt = { - let mut wr = ::io::BufWriter::new(&mut buf); - (write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap(); - wr.tell().unwrap() as uint - }; - f(buf[..amt]) -} - #[cfg(test)] mod tests { use prelude::v1::*; use num::FromStrRadix; - use str::from_str; + + fn from_str<T: ::str::FromStr>(t: &str) -> Option<T> { + ::str::FromStr::from_str(t) + } #[test] pub fn test_from_str() { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 771c808ab8a..be8f82349c2 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -54,7 +54,7 @@ use result::Result::{Err, Ok}; use slice::{AsSlice, SliceExt}; use str::{Str, StrExt}; use string::{String, ToString}; -use sync::atomic::{AtomicInt, ATOMIC_INT_INIT, SeqCst}; +use sync::atomic::{AtomicInt, ATOMIC_INT_INIT, Ordering}; use vec::Vec; #[cfg(unix)] use c_str::ToCStr; @@ -606,13 +606,13 @@ static EXIT_STATUS: AtomicInt = ATOMIC_INT_INIT; /// /// Note that this is not synchronized against modifications of other threads. pub fn set_exit_status(code: int) { - EXIT_STATUS.store(code, SeqCst) + EXIT_STATUS.store(code, Ordering::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 { - EXIT_STATUS.load(SeqCst) + EXIT_STATUS.load(Ordering::SeqCst) } #[cfg(target_os = "macos")] diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 731c3bbe427..bf9ffbffe7d 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -69,9 +69,9 @@ use iter::IteratorExt; use option::Option; use option::Option::{None, Some}; use str; -use str::{CowString, MaybeOwned, Str, StrExt}; -use string::String; -use slice::{AsSlice, SliceExt}; +use str::StrExt; +use string::{String, CowString}; +use slice::SliceExt; use vec::Vec; /// Typedef for POSIX file paths. @@ -896,20 +896,6 @@ impl BytesContainer for CString { } } -#[allow(deprecated)] -impl<'a> BytesContainer for str::MaybeOwned<'a> { - #[inline] - fn container_as_bytes<'b>(&'b self) -> &'b [u8] { - self.as_slice().as_bytes() - } - #[inline] - fn container_as_str<'b>(&'b self) -> Option<&'b str> { - Some(self.as_slice()) - } - #[inline] - fn is_str(_: Option<&str::MaybeOwned>) -> bool { true } -} - impl<'a, Sized? T: BytesContainer> BytesContainer for &'a T { #[inline] fn container_as_bytes(&self) -> &[u8] { diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 55063f1393f..aa28c8266d1 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -421,7 +421,7 @@ pub fn sample<T, I: Iterator<Item=T>, R: Rng>(rng: &mut R, mod test { use prelude::v1::*; use super::{Rng, thread_rng, random, SeedableRng, StdRng, sample}; - use iter::order; + use iter::{order, repeat}; struct ConstRng { i: u64 } impl Rng for ConstRng { @@ -439,7 +439,7 @@ mod test { let lengths = [0, 1, 2, 3, 4, 5, 6, 7, 80, 81, 82, 83, 84, 85, 86, 87]; for &n in lengths.iter() { - let mut v = Vec::from_elem(n, 0u8); + let mut v = repeat(0u8).take(n).collect::<Vec<_>>(); r.fill_bytes(v.as_mut_slice()); // use this to get nicer error messages. diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 5caa71b4347..6ae6a238c95 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -93,12 +93,12 @@ mod imp { target_arch = "arm", target_arch = "aarch64")))] fn is_getrandom_available() -> bool { - use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Relaxed}; + use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering}; static GETRANDOM_CHECKED: AtomicBool = ATOMIC_BOOL_INIT; static GETRANDOM_AVAILABLE: AtomicBool = ATOMIC_BOOL_INIT; - if !GETRANDOM_CHECKED.load(Relaxed) { + if !GETRANDOM_CHECKED.load(Ordering::Relaxed) { let mut buf: [u8; 0] = []; let result = getrandom(&mut buf); let available = if result == -1 { @@ -107,11 +107,11 @@ mod imp { } else { true }; - GETRANDOM_AVAILABLE.store(available, Relaxed); - GETRANDOM_CHECKED.store(true, Relaxed); + GETRANDOM_AVAILABLE.store(available, Ordering::Relaxed); + GETRANDOM_CHECKED.store(true, Ordering::Relaxed); available } else { - GETRANDOM_AVAILABLE.load(Relaxed) + GETRANDOM_AVAILABLE.load(Ordering::Relaxed) } } diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index ae405e9400b..578239c9cc4 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -15,7 +15,7 @@ use prelude::v1::*; use os; -use sync::atomic; +use sync::atomic::{mod, Ordering}; pub use sys::backtrace::write; @@ -23,7 +23,7 @@ pub use sys::backtrace::write; // whether the magical environment variable is present to see if it's turned on. pub fn log_enabled() -> bool { static ENABLED: atomic::AtomicInt = atomic::ATOMIC_INT_INIT; - match ENABLED.load(atomic::SeqCst) { + match ENABLED.load(Ordering::SeqCst) { 1 => return false, 2 => return true, _ => {} @@ -33,7 +33,7 @@ pub fn log_enabled() -> bool { Some(..) => 2, None => 1, }; - ENABLED.store(val, atomic::SeqCst); + ENABLED.store(val, Ordering::SeqCst); val == 2 } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 99f791df474..a48a8edd82f 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -67,7 +67,7 @@ use fmt; use intrinsics; use libc::c_void; use mem; -use sync::atomic; +use sync::atomic::{mod, Ordering}; use sync::{Once, ONCE_INIT}; use rt::libunwind as uw; @@ -543,11 +543,11 @@ fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) -> // callback. Additionally, CALLBACK_CNT may briefly be higher than // MAX_CALLBACKS, so we're sure to clamp it as necessary. let callbacks = { - let amt = CALLBACK_CNT.load(atomic::SeqCst); + let amt = CALLBACK_CNT.load(Ordering::SeqCst); CALLBACKS[..cmp::min(amt, MAX_CALLBACKS)] }; for cb in callbacks.iter() { - match cb.load(atomic::SeqCst) { + match cb.load(Ordering::SeqCst) { 0 => {} n => { let f: Callback = unsafe { mem::transmute(n) }; @@ -584,18 +584,18 @@ fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) -> /// currently possible to unregister a callback once it has been registered. #[experimental] pub unsafe fn register(f: Callback) -> bool { - match CALLBACK_CNT.fetch_add(1, atomic::SeqCst) { + match CALLBACK_CNT.fetch_add(1, Ordering::SeqCst) { // The invocation code has knowledge of this window where the count has // been incremented, but the callback has not been stored. We're // guaranteed that the slot we're storing into is 0. n if n < MAX_CALLBACKS => { - let prev = CALLBACKS[n].swap(mem::transmute(f), atomic::SeqCst); + let prev = CALLBACKS[n].swap(mem::transmute(f), Ordering::SeqCst); rtassert!(prev == 0); true } // If we accidentally bumped the count too high, pull it back. _ => { - CALLBACK_CNT.store(MAX_CALLBACKS, atomic::SeqCst); + CALLBACK_CNT.store(MAX_CALLBACKS, Ordering::SeqCst); false } } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index d6cf35ee3cd..883a01fa318 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -19,7 +19,7 @@ use libc::{self, uintptr_t}; use os; use slice; use str; -use sync::atomic; +use sync::atomic::{mod, Ordering}; /// Dynamically inquire about whether we're running under V. /// You should usually not use this unless your test definitely @@ -47,7 +47,7 @@ pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool { pub fn min_stack() -> uint { static MIN: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT; - match MIN.load(atomic::SeqCst) { + match MIN.load(Ordering::SeqCst) { 0 => {} n => return n - 1, } @@ -55,7 +55,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 - MIN.store(amt + 1, atomic::SeqCst); + MIN.store(amt + 1, Ordering::SeqCst); return amt; } diff --git a/src/libstd/sync/atomic.rs b/src/libstd/sync/atomic.rs deleted file mode 100644 index 3652b45ce97..00000000000 --- a/src/libstd/sync/atomic.rs +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Atomic types -//! -//! Atomic types provide primitive shared-memory communication between -//! threads, and are the building blocks of other concurrent -//! types. -//! -//! This module defines atomic versions of a select number of primitive -//! types, including `AtomicBool`, `AtomicInt`, `AtomicUint`, and `AtomicOption`. -//! Atomic types present operations that, when used correctly, synchronize -//! updates between threads. -//! -//! Each method takes an `Ordering` which represents the strength of -//! the memory barrier for that operation. These orderings are the -//! same as [C++11 atomic orderings][1]. -//! -//! [1]: http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync -//! -//! Atomic variables are safe to share between threads (they implement `Sync`) -//! but they do not themselves provide the mechanism for sharing. The most -//! common way to share an atomic variable is to put it into an `Arc` (an -//! atomically-reference-counted shared pointer). -//! -//! Most atomic types may be stored in static variables, initialized using -//! the provided static initializers like `INIT_ATOMIC_BOOL`. Atomic statics -//! are often used for lazy global initialization. -//! -//! -//! # Examples -//! -//! A simple spinlock: -//! -//! ``` -//! use std::sync::Arc; -//! use std::sync::atomic::{AtomicUint, SeqCst}; -//! use std::thread::Thread; -//! -//! fn main() { -//! let spinlock = Arc::new(AtomicUint::new(1)); -//! -//! let spinlock_clone = spinlock.clone(); -//! Thread::spawn(move|| { -//! spinlock_clone.store(0, SeqCst); -//! }).detach(); -//! -//! // Wait for the other task to release the lock -//! while spinlock.load(SeqCst) != 0 {} -//! } -//! ``` -//! -//! Transferring a heap object with `AtomicOption`: -//! -//! ``` -//! use std::sync::Arc; -//! use std::sync::atomic::{AtomicOption, SeqCst}; -//! use std::thread::Thread; -//! -//! fn main() { -//! struct BigObject; -//! -//! let shared_big_object = Arc::new(AtomicOption::empty()); -//! -//! let shared_big_object_clone = shared_big_object.clone(); -//! Thread::spawn(move|| { -//! let unwrapped_big_object = shared_big_object_clone.take(SeqCst); -//! if unwrapped_big_object.is_some() { -//! println!("got a big object from another task"); -//! } else { -//! println!("other task hasn't sent big object yet"); -//! } -//! }).detach(); -//! -//! shared_big_object.swap(box BigObject, SeqCst); -//! } -//! ``` -//! -//! Keep a global count of live tasks: -//! -//! ``` -//! use std::sync::atomic::{AtomicUint, SeqCst, ATOMIC_UINT_INIT}; -//! -//! static GLOBAL_TASK_COUNT: AtomicUint = ATOMIC_UINT_INIT; -//! -//! let old_task_count = GLOBAL_TASK_COUNT.fetch_add(1, SeqCst); -//! println!("live tasks: {}", old_task_count + 1); -//! ``` - -#![stable] - -use alloc::boxed::Box; -use core::mem; -use core::prelude::{Send, Drop, None, Option, Some}; - -pub use core::atomic::{AtomicBool, AtomicInt, AtomicUint, AtomicPtr}; -pub use core::atomic::{INIT_ATOMIC_BOOL, INIT_ATOMIC_INT, INIT_ATOMIC_UINT}; -pub use core::atomic::{ATOMIC_BOOL_INIT, ATOMIC_INT_INIT, ATOMIC_UINT_INIT}; -pub use core::atomic::fence; -pub use core::atomic::Ordering::{self, Relaxed, Release, Acquire, AcqRel, SeqCst}; - -/// An atomic, nullable unique pointer -/// -/// This can be used as the concurrency primitive for operations that transfer -/// owned heap objects across tasks. -#[unsafe_no_drop_flag] -#[deprecated = "no longer used; will eventually be replaced by a higher-level\ - concept like MVar"] -pub struct AtomicOption<T> { - p: AtomicUint, -} - -#[allow(deprecated)] -impl<T: Send> AtomicOption<T> { - /// Create a new `AtomicOption` - pub fn new(p: Box<T>) -> AtomicOption<T> { - unsafe { AtomicOption { p: AtomicUint::new(mem::transmute(p)) } } - } - - /// Create a new `AtomicOption` that doesn't contain a value - pub fn empty() -> AtomicOption<T> { AtomicOption { p: AtomicUint::new(0) } } - - /// Store a value, returning the old value - #[inline] - pub fn swap(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> { - let val = unsafe { mem::transmute(val) }; - - match self.p.swap(val, order) { - 0 => None, - n => Some(unsafe { mem::transmute(n) }), - } - } - - /// Remove the value, leaving the `AtomicOption` empty. - #[inline] - pub fn take(&self, order: Ordering) -> Option<Box<T>> { - unsafe { self.swap(mem::transmute(0u), order) } - } - - /// Replace an empty value with a non-empty value. - /// - /// Succeeds if the option is `None` and returns `None` if so. If - /// the option was already `Some`, returns `Some` of the rejected - /// value. - #[inline] - pub fn fill(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> { - unsafe { - let val = mem::transmute(val); - let expected = mem::transmute(0u); - let oldval = self.p.compare_and_swap(expected, val, order); - if oldval == expected { - None - } else { - Some(mem::transmute(val)) - } - } - } - - /// Returns `true` if the `AtomicOption` is empty. - /// - /// Be careful: The caller must have some external method of ensuring the - /// result does not get invalidated by another task after this returns. - #[inline] - pub fn is_empty(&self, order: Ordering) -> bool { - self.p.load(order) as uint == 0 - } -} - -#[unsafe_destructor] -impl<T: Send> Drop for AtomicOption<T> { - fn drop(&mut self) { - let _ = self.take(SeqCst); - } -} - -#[cfg(test)] -mod test { - use prelude::v1::*; - use super::*; - - #[test] - fn option_empty() { - let option: AtomicOption<()> = AtomicOption::empty(); - assert!(option.is_empty(SeqCst)); - } - - #[test] - fn option_swap() { - let p = AtomicOption::new(box 1i); - let a = box 2i; - - let b = p.swap(a, SeqCst); - - assert!(b == Some(box 1)); - assert!(p.take(SeqCst) == Some(box 2)); - } - - #[test] - fn option_take() { - let p = AtomicOption::new(box 1i); - - assert!(p.take(SeqCst) == Some(box 1)); - assert!(p.take(SeqCst) == None); - - let p2 = box 2i; - p.swap(p2, SeqCst); - - assert!(p.take(SeqCst) == Some(box 2)); - } - - #[test] - fn option_fill() { - let p = AtomicOption::new(box 1i); - assert!(p.fill(box 2i, SeqCst).is_some()); // should fail; shouldn't leak! - assert!(p.take(SeqCst) == Some(box 1)); - - assert!(p.fill(box 2i, SeqCst).is_none()); // shouldn't fail - assert!(p.take(SeqCst) == Some(box 2)); - } -} diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 28c36922ca6..7734f655ed2 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -10,7 +10,7 @@ use prelude::v1::*; -use sync::atomic::{self, AtomicUint}; +use sync::atomic::{AtomicUint, Ordering, ATOMIC_UINT_INIT}; use sync::poison::{self, LockResult}; use sys_common::condvar as sys; use sys_common::mutex as sys_mutex; @@ -88,7 +88,7 @@ unsafe impl Sync for StaticCondvar {} #[unstable = "may be merged with Condvar in the future"] pub const CONDVAR_INIT: StaticCondvar = StaticCondvar { inner: sys::CONDVAR_INIT, - mutex: atomic::ATOMIC_UINT_INIT, + mutex: ATOMIC_UINT_INIT, }; impl Condvar { @@ -260,7 +260,7 @@ impl StaticCondvar { fn verify(&self, mutex: &sys_mutex::Mutex) { let addr = mutex as *const _ as uint; - match self.mutex.compare_and_swap(0, addr, atomic::SeqCst) { + match self.mutex.compare_and_swap(0, addr, Ordering::SeqCst) { // If we got out 0, then we have successfully bound the mutex to // this cvar. 0 => {} diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index e5245251ea8..4c6adcc04f6 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -65,10 +65,6 @@ impl<A> Future<A> { } } - /// Deprecated, use into_inner() instead - #[deprecated = "renamed to into_inner()"] - pub fn unwrap(self) -> A { self.into_inner() } - pub fn get_ref<'a>(&'a mut self) -> &'a A { /*! * Executes the future's closure and then returns a reference diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index c09c3b45d3e..6ce278726e9 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -18,6 +18,7 @@ #![experimental] pub use alloc::arc::{Arc, Weak}; +pub use core::atomic; pub use self::mutex::{Mutex, MutexGuard, StaticMutex}; pub use self::mutex::MUTEX_INIT; @@ -32,7 +33,6 @@ pub use self::poison::{PoisonError, TryLockError, TryLockResult, LockResult}; pub use self::future::Future; pub use self::task_pool::TaskPool; -pub mod atomic; pub mod mpsc; mod barrier; diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 8945233dac9..8f85dc6e043 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -48,7 +48,7 @@ use alloc::boxed::Box; use core::mem; use core::cell::UnsafeCell; -use sync::atomic::{AtomicPtr, Release, Acquire, AcqRel, Relaxed}; +use sync::atomic::{AtomicPtr, Ordering}; /// A result of the `pop` function. pub enum PopResult<T> { @@ -103,8 +103,8 @@ impl<T: Send> Queue<T> { pub fn push(&self, t: T) { unsafe { let n = Node::new(Some(t)); - let prev = self.head.swap(n, AcqRel); - (*prev).next.store(n, Release); + let prev = self.head.swap(n, Ordering::AcqRel); + (*prev).next.store(n, Ordering::Release); } } @@ -121,7 +121,7 @@ impl<T: Send> Queue<T> { pub fn pop(&self) -> PopResult<T> { unsafe { let tail = *self.tail.get(); - let next = (*tail).next.load(Acquire); + let next = (*tail).next.load(Ordering::Acquire); if !next.is_null() { *self.tail.get() = next; @@ -132,7 +132,7 @@ impl<T: Send> Queue<T> { return Data(ret); } - if self.head.load(Acquire) == tail {Empty} else {Inconsistent} + if self.head.load(Ordering::Acquire) == tail {Empty} else {Inconsistent} } } } @@ -143,7 +143,7 @@ impl<T: Send> Drop for Queue<T> { unsafe { let mut cur = *self.tail.get(); while !cur.is_null() { - let next = (*cur).next.load(Relaxed); + let next = (*cur).next.load(Ordering::Relaxed); let _: Box<Node<T>> = mem::transmute(cur); cur = next; } diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index 2811f403c6c..5c2331d0f2e 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -42,7 +42,7 @@ use core::prelude::*; use sync::mpsc::Receiver; use sync::mpsc::blocking::{self, SignalToken}; use core::mem; -use sync::atomic; +use sync::atomic::{AtomicUint, Ordering}; // Various states you can find a port in. const EMPTY: uint = 0; // initial state: no data, no blocked reciever @@ -56,7 +56,7 @@ const DISCONNECTED: uint = 2; // channel is disconnected OR upgraded pub struct Packet<T> { // Internal state of the chan/port pair (stores the blocked task as well) - state: atomic::AtomicUint, + state: AtomicUint, // One-shot data slot location data: Option<T>, // when used for the second time, a oneshot channel must be upgraded, and @@ -93,7 +93,7 @@ impl<T: Send> Packet<T> { Packet { data: None, upgrade: NothingSent, - state: atomic::AtomicUint::new(EMPTY), + state: AtomicUint::new(EMPTY), } } @@ -107,7 +107,7 @@ impl<T: Send> Packet<T> { self.data = Some(t); self.upgrade = SendUsed; - match self.state.swap(DATA, atomic::SeqCst) { + match self.state.swap(DATA, Ordering::SeqCst) { // Sent the data, no one was waiting EMPTY => Ok(()), @@ -141,14 +141,14 @@ impl<T: Send> Packet<T> { pub fn recv(&mut self) -> Result<T, Failure<T>> { // Attempt to not block the task (it's a little expensive). If it looks // like we're not empty, then immediately go through to `try_recv`. - if self.state.load(atomic::SeqCst) == EMPTY { + if self.state.load(Ordering::SeqCst) == EMPTY { let (wait_token, signal_token) = blocking::tokens(); let ptr = unsafe { signal_token.cast_to_uint() }; // race with senders to enter the blocking state - if self.state.compare_and_swap(EMPTY, ptr, atomic::SeqCst) == EMPTY { + if self.state.compare_and_swap(EMPTY, ptr, Ordering::SeqCst) == EMPTY { wait_token.wait(); - debug_assert!(self.state.load(atomic::SeqCst) != EMPTY); + debug_assert!(self.state.load(Ordering::SeqCst) != EMPTY); } else { // drop the signal token, since we never blocked drop(unsafe { SignalToken::cast_from_uint(ptr) }); @@ -159,7 +159,7 @@ impl<T: Send> Packet<T> { } pub fn try_recv(&mut self) -> Result<T, Failure<T>> { - match self.state.load(atomic::SeqCst) { + match self.state.load(Ordering::SeqCst) { EMPTY => Err(Empty), // We saw some data on the channel, but the channel can be used @@ -169,7 +169,7 @@ impl<T: Send> Packet<T> { // the state changes under our feet we'd rather just see that state // change. DATA => { - self.state.compare_and_swap(DATA, EMPTY, atomic::SeqCst); + self.state.compare_and_swap(DATA, EMPTY, Ordering::SeqCst); match self.data.take() { Some(data) => Ok(data), None => unreachable!(), @@ -209,7 +209,7 @@ impl<T: Send> Packet<T> { }; self.upgrade = GoUp(up); - match self.state.swap(DISCONNECTED, atomic::SeqCst) { + match self.state.swap(DISCONNECTED, Ordering::SeqCst) { // If the channel is empty or has data on it, then we're good to go. // Senders will check the data before the upgrade (in case we // plastered over the DATA state). @@ -225,7 +225,7 @@ impl<T: Send> Packet<T> { } pub fn drop_chan(&mut self) { - match self.state.swap(DISCONNECTED, atomic::SeqCst) { + match self.state.swap(DISCONNECTED, Ordering::SeqCst) { DATA | DISCONNECTED | EMPTY => {} // If someone's waiting, we gotta wake them up @@ -236,7 +236,7 @@ impl<T: Send> Packet<T> { } pub fn drop_port(&mut self) { - match self.state.swap(DISCONNECTED, atomic::SeqCst) { + match self.state.swap(DISCONNECTED, Ordering::SeqCst) { // An empty channel has nothing to do, and a remotely disconnected // channel also has nothing to do b/c we're about to run the drop // glue @@ -259,7 +259,7 @@ impl<T: Send> Packet<T> { // If Ok, the value is whether this port has data, if Err, then the upgraded // port needs to be checked instead of this one. pub fn can_recv(&mut self) -> Result<bool, Receiver<T>> { - match self.state.load(atomic::SeqCst) { + match self.state.load(Ordering::SeqCst) { EMPTY => Ok(false), // Welp, we tried DATA => Ok(true), // we have some un-acquired data DISCONNECTED if self.data.is_some() => Ok(true), // we have data @@ -284,7 +284,7 @@ impl<T: Send> Packet<T> { // because there is data, or fail because there is an upgrade pending. pub fn start_selection(&mut self, token: SignalToken) -> SelectionResult<T> { let ptr = unsafe { token.cast_to_uint() }; - match self.state.compare_and_swap(EMPTY, ptr, atomic::SeqCst) { + match self.state.compare_and_swap(EMPTY, ptr, Ordering::SeqCst) { EMPTY => SelSuccess, DATA => { drop(unsafe { SignalToken::cast_from_uint(ptr) }); @@ -322,7 +322,7 @@ impl<T: Send> Packet<T> { // // The return value indicates whether there's data on this port. pub fn abort_selection(&mut self) -> Result<bool, Receiver<T>> { - let state = match self.state.load(atomic::SeqCst) { + let state = match self.state.load(Ordering::SeqCst) { // Each of these states means that no further activity will happen // with regard to abortion selection s @ EMPTY | @@ -331,7 +331,7 @@ impl<T: Send> Packet<T> { // If we've got a blocked task, then use an atomic to gain ownership // of it (may fail) - ptr => self.state.compare_and_swap(ptr, EMPTY, atomic::SeqCst) + ptr => self.state.compare_and_swap(ptr, EMPTY, Ordering::SeqCst) }; // Now that we've got ownership of our state, figure out what to do @@ -370,6 +370,6 @@ impl<T: Send> Packet<T> { #[unsafe_destructor] impl<T: Send> Drop for Packet<T> { fn drop(&mut self) { - assert_eq!(self.state.load(atomic::SeqCst), DISCONNECTED); + assert_eq!(self.state.load(Ordering::SeqCst), DISCONNECTED); } } diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index cadac8e6272..4295d116aed 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -25,11 +25,12 @@ use core::prelude::*; use core::cmp; use core::int; -use sync::{atomic, Mutex, MutexGuard}; -use sync::mpsc::mpsc_queue as mpsc; +use sync::atomic::{AtomicUint, AtomicInt, AtomicBool, Ordering}; use sync::mpsc::blocking::{self, SignalToken}; -use sync::mpsc::select::StartResult; +use sync::mpsc::mpsc_queue as mpsc; use sync::mpsc::select::StartResult::*; +use sync::mpsc::select::StartResult; +use sync::{Mutex, MutexGuard}; use thread::Thread; const DISCONNECTED: int = int::MIN; @@ -41,17 +42,17 @@ const MAX_STEALS: int = 1 << 20; pub struct Packet<T> { queue: mpsc::Queue<T>, - cnt: atomic::AtomicInt, // How many items are on this channel + cnt: AtomicInt, // How many items are on this channel steals: int, // How many times has a port received without blocking? - to_wake: atomic::AtomicUint, // SignalToken for wake up + to_wake: AtomicUint, // SignalToken for wake up // The number of channels which are currently using this packet. - channels: atomic::AtomicInt, + channels: AtomicInt, // See the discussion in Port::drop and the channel send methods for what // these are used for - port_dropped: atomic::AtomicBool, - sender_drain: atomic::AtomicInt, + port_dropped: AtomicBool, + sender_drain: AtomicInt, // this lock protects various portions of this implementation during // select() @@ -69,12 +70,12 @@ impl<T: Send> Packet<T> { pub fn new() -> Packet<T> { let p = Packet { queue: mpsc::Queue::new(), - cnt: atomic::AtomicInt::new(0), + cnt: AtomicInt::new(0), steals: 0, - to_wake: atomic::AtomicUint::new(0), - channels: atomic::AtomicInt::new(2), - port_dropped: atomic::AtomicBool::new(false), - sender_drain: atomic::AtomicInt::new(0), + to_wake: AtomicUint::new(0), + channels: AtomicInt::new(2), + port_dropped: AtomicBool::new(false), + sender_drain: AtomicInt::new(0), select_lock: Mutex::new(()), }; return p; @@ -98,10 +99,10 @@ impl<T: Send> Packet<T> { token: Option<SignalToken>, guard: MutexGuard<()>) { token.map(|token| { - assert_eq!(self.cnt.load(atomic::SeqCst), 0); - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); - self.to_wake.store(unsafe { token.cast_to_uint() }, atomic::SeqCst); - self.cnt.store(-1, atomic::SeqCst); + assert_eq!(self.cnt.load(Ordering::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); + self.to_wake.store(unsafe { token.cast_to_uint() }, Ordering::SeqCst); + self.cnt.store(-1, Ordering::SeqCst); // This store is a little sketchy. What's happening here is that // we're transferring a blocker from a oneshot or stream channel to @@ -134,7 +135,7 @@ impl<T: Send> Packet<T> { pub fn send(&mut self, t: T) -> Result<(), T> { // See Port::drop for what's going on - if self.port_dropped.load(atomic::SeqCst) { return Err(t) } + if self.port_dropped.load(Ordering::SeqCst) { return Err(t) } // Note that the multiple sender case is a little trickier // semantically than the single sender case. The logic for @@ -161,12 +162,12 @@ impl<T: Send> Packet<T> { // preflight check serves as the definitive "this will never be // received". Once we get beyond this check, we have permanently // entered the realm of "this may be received" - if self.cnt.load(atomic::SeqCst) < DISCONNECTED + FUDGE { + if self.cnt.load(Ordering::SeqCst) < DISCONNECTED + FUDGE { return Err(t) } self.queue.push(t); - match self.cnt.fetch_add(1, atomic::SeqCst) { + match self.cnt.fetch_add(1, Ordering::SeqCst) { -1 => { self.take_to_wake().signal(); } @@ -183,9 +184,9 @@ impl<T: Send> Packet<T> { n if n < DISCONNECTED + FUDGE => { // see the comment in 'try' for a shared channel for why this // window of "not disconnected" is ok. - self.cnt.store(DISCONNECTED, atomic::SeqCst); + self.cnt.store(DISCONNECTED, Ordering::SeqCst); - if self.sender_drain.fetch_add(1, atomic::SeqCst) == 0 { + if self.sender_drain.fetch_add(1, Ordering::SeqCst) == 0 { loop { // drain the queue, for info on the thread yield see the // discussion in try_recv @@ -198,7 +199,7 @@ impl<T: Send> Packet<T> { } // maybe we're done, if we're not the last ones // here, then we need to go try again. - if self.sender_drain.fetch_sub(1, atomic::SeqCst) == 1 { + if self.sender_drain.fetch_sub(1, Ordering::SeqCst) == 1 { break } } @@ -239,15 +240,15 @@ impl<T: Send> Packet<T> { // Essentially the exact same thing as the stream decrement function. // Returns true if blocking should proceed. fn decrement(&mut self, token: SignalToken) -> StartResult { - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); let ptr = unsafe { token.cast_to_uint() }; - self.to_wake.store(ptr, atomic::SeqCst); + self.to_wake.store(ptr, Ordering::SeqCst); let steals = self.steals; self.steals = 0; - match self.cnt.fetch_sub(1 + steals, atomic::SeqCst) { - DISCONNECTED => { self.cnt.store(DISCONNECTED, atomic::SeqCst); } + match self.cnt.fetch_sub(1 + steals, Ordering::SeqCst) { + DISCONNECTED => { self.cnt.store(DISCONNECTED, Ordering::SeqCst); } // If we factor in our steals and notice that the channel has no // data, we successfully sleep n => { @@ -256,7 +257,7 @@ impl<T: Send> Packet<T> { } } - self.to_wake.store(0, atomic::SeqCst); + self.to_wake.store(0, Ordering::SeqCst); drop(unsafe { SignalToken::cast_from_uint(ptr) }); Abort } @@ -297,9 +298,9 @@ impl<T: Send> Packet<T> { // might decrement steals. Some(data) => { if self.steals > MAX_STEALS { - match self.cnt.swap(0, atomic::SeqCst) { + match self.cnt.swap(0, Ordering::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomic::SeqCst); + self.cnt.store(DISCONNECTED, Ordering::SeqCst); } n => { let m = cmp::min(n, self.steals); @@ -316,7 +317,7 @@ impl<T: Send> Packet<T> { // See the discussion in the stream implementation for why we try // again. None => { - match self.cnt.load(atomic::SeqCst) { + match self.cnt.load(Ordering::SeqCst) { n if n != DISCONNECTED => Err(Empty), _ => { match self.queue.pop() { @@ -334,20 +335,20 @@ impl<T: Send> Packet<T> { // Prepares this shared packet for a channel clone, essentially just bumping // a refcount. pub fn clone_chan(&mut self) { - self.channels.fetch_add(1, atomic::SeqCst); + self.channels.fetch_add(1, Ordering::SeqCst); } // Decrement the reference count on a channel. This is called whenever a // Chan is dropped and may end up waking up a receiver. It's the receiver's // responsibility on the other end to figure out that we've disconnected. pub fn drop_chan(&mut self) { - match self.channels.fetch_sub(1, atomic::SeqCst) { + match self.channels.fetch_sub(1, Ordering::SeqCst) { 1 => {} n if n > 1 => return, n => panic!("bad number of channels left {}", n), } - match self.cnt.swap(DISCONNECTED, atomic::SeqCst) { + match self.cnt.swap(DISCONNECTED, Ordering::SeqCst) { -1 => { self.take_to_wake().signal(); } DISCONNECTED => {} n => { assert!(n >= 0); } @@ -357,10 +358,10 @@ impl<T: Send> Packet<T> { // See the long discussion inside of stream.rs for why the queue is drained, // and why it is done in this fashion. pub fn drop_port(&mut self) { - self.port_dropped.store(true, atomic::SeqCst); + self.port_dropped.store(true, Ordering::SeqCst); let mut steals = self.steals; while { - let cnt = self.cnt.compare_and_swap(steals, DISCONNECTED, atomic::SeqCst); + let cnt = self.cnt.compare_and_swap(steals, DISCONNECTED, Ordering::SeqCst); cnt != DISCONNECTED && cnt != steals } { // See the discussion in 'try_recv' for why we yield @@ -376,8 +377,8 @@ impl<T: Send> Packet<T> { // Consumes ownership of the 'to_wake' field. fn take_to_wake(&mut self) -> SignalToken { - let ptr = self.to_wake.load(atomic::SeqCst); - self.to_wake.store(0, atomic::SeqCst); + let ptr = self.to_wake.load(Ordering::SeqCst); + self.to_wake.store(0, Ordering::SeqCst); assert!(ptr != 0); unsafe { SignalToken::cast_from_uint(ptr) } } @@ -392,15 +393,15 @@ impl<T: Send> Packet<T> { // This is different than the stream version because there's no need to peek // at the queue, we can just look at the local count. pub fn can_recv(&mut self) -> bool { - let cnt = self.cnt.load(atomic::SeqCst); + let cnt = self.cnt.load(Ordering::SeqCst); cnt == DISCONNECTED || cnt - self.steals > 0 } // increment the count on the channel (used for selection) fn bump(&mut self, amt: int) -> int { - match self.cnt.fetch_add(amt, atomic::SeqCst) { + match self.cnt.fetch_add(amt, Ordering::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomic::SeqCst); + self.cnt.store(DISCONNECTED, Ordering::SeqCst); DISCONNECTED } n => n @@ -444,13 +445,13 @@ impl<T: Send> Packet<T> { // the channel count and figure out what we should do to make it // positive. let steals = { - let cnt = self.cnt.load(atomic::SeqCst); + let cnt = self.cnt.load(Ordering::SeqCst); if cnt < 0 && cnt != DISCONNECTED {-cnt} else {0} }; let prev = self.bump(steals + 1); if prev == DISCONNECTED { - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); true } else { let cur = prev + steals + 1; @@ -458,7 +459,7 @@ impl<T: Send> Packet<T> { if prev < 0 { drop(self.take_to_wake()); } else { - while self.to_wake.load(atomic::SeqCst) != 0 { + while self.to_wake.load(Ordering::SeqCst) != 0 { Thread::yield_now(); } } @@ -479,8 +480,8 @@ impl<T: Send> Drop for Packet<T> { // disconnection, but also a proper fence before the read of // `to_wake`, so this assert cannot be removed with also removing // the `to_wake` assert. - assert_eq!(self.cnt.load(atomic::SeqCst), DISCONNECTED); - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); - assert_eq!(self.channels.load(atomic::SeqCst), 0); + assert_eq!(self.cnt.load(Ordering::SeqCst), DISCONNECTED); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); + assert_eq!(self.channels.load(Ordering::SeqCst), 0); } } diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 15624601157..e8d6e380be5 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -41,7 +41,7 @@ use alloc::boxed::Box; use core::mem; use core::cell::UnsafeCell; -use sync::atomic::{AtomicPtr, Relaxed, AtomicUint, Acquire, Release}; +use sync::atomic::{AtomicPtr, AtomicUint, Ordering}; // Node within the linked list queue of messages to send struct Node<T> { @@ -109,7 +109,7 @@ impl<T: Send> Queue<T> { pub unsafe fn new(bound: uint) -> Queue<T> { let n1 = Node::new(); let n2 = Node::new(); - (*n1).next.store(n2, Relaxed); + (*n1).next.store(n2, Ordering::Relaxed); Queue { tail: UnsafeCell::new(n2), tail_prev: AtomicPtr::new(n1), @@ -131,8 +131,8 @@ impl<T: Send> Queue<T> { let n = self.alloc(); assert!((*n).value.is_none()); (*n).value = Some(t); - (*n).next.store(0 as *mut Node<T>, Relaxed); - (**self.head.get()).next.store(n, Release); + (*n).next.store(0 as *mut Node<T>, Ordering::Relaxed); + (**self.head.get()).next.store(n, Ordering::Release); *self.head.get() = n; } } @@ -144,23 +144,23 @@ impl<T: Send> Queue<T> { // only one subtracting from the cache). if *self.first.get() != *self.tail_copy.get() { if self.cache_bound > 0 { - let b = self.cache_subtractions.load(Relaxed); - self.cache_subtractions.store(b + 1, Relaxed); + let b = self.cache_subtractions.load(Ordering::Relaxed); + self.cache_subtractions.store(b + 1, Ordering::Relaxed); } let ret = *self.first.get(); - *self.first.get() = (*ret).next.load(Relaxed); + *self.first.get() = (*ret).next.load(Ordering::Relaxed); return ret; } // If the above fails, then update our copy of the tail and try // again. - *self.tail_copy.get() = self.tail_prev.load(Acquire); + *self.tail_copy.get() = self.tail_prev.load(Ordering::Acquire); if *self.first.get() != *self.tail_copy.get() { if self.cache_bound > 0 { - let b = self.cache_subtractions.load(Relaxed); - self.cache_subtractions.store(b + 1, Relaxed); + let b = self.cache_subtractions.load(Ordering::Relaxed); + self.cache_subtractions.store(b + 1, Ordering::Relaxed); } let ret = *self.first.get(); - *self.first.get() = (*ret).next.load(Relaxed); + *self.first.get() = (*ret).next.load(Ordering::Relaxed); return ret; } // If all of that fails, then we have to allocate a new node @@ -177,25 +177,26 @@ impl<T: Send> Queue<T> { // tail's next field and see if we can use it. If we do a pop, then // the current tail node is a candidate for going into the cache. let tail = *self.tail.get(); - let next = (*tail).next.load(Acquire); + let next = (*tail).next.load(Ordering::Acquire); if next.is_null() { return None } assert!((*next).value.is_some()); let ret = (*next).value.take(); *self.tail.get() = next; if self.cache_bound == 0 { - self.tail_prev.store(tail, Release); + self.tail_prev.store(tail, Ordering::Release); } else { // FIXME: this is dubious with overflow. - let additions = self.cache_additions.load(Relaxed); - let subtractions = self.cache_subtractions.load(Relaxed); + let additions = self.cache_additions.load(Ordering::Relaxed); + let subtractions = self.cache_subtractions.load(Ordering::Relaxed); let size = additions - subtractions; if size < self.cache_bound { - self.tail_prev.store(tail, Release); - self.cache_additions.store(additions + 1, Relaxed); + self.tail_prev.store(tail, Ordering::Release); + self.cache_additions.store(additions + 1, Ordering::Relaxed); } else { - (*self.tail_prev.load(Relaxed)).next.store(next, Relaxed); + (*self.tail_prev.load(Ordering::Relaxed)) + .next.store(next, Ordering::Relaxed); // We have successfully erased all references to 'tail', so // now we can safely drop it. let _: Box<Node<T>> = mem::transmute(tail); @@ -217,7 +218,7 @@ impl<T: Send> Queue<T> { // stripped out. unsafe { let tail = *self.tail.get(); - let next = (*tail).next.load(Acquire); + let next = (*tail).next.load(Ordering::Acquire); if next.is_null() { return None } return (*next).value.as_mut(); } @@ -230,7 +231,7 @@ impl<T: Send> Drop for Queue<T> { unsafe { let mut cur = *self.first.get(); while !cur.is_null() { - let next = (*cur).next.load(Relaxed); + let next = (*cur).next.load(Ordering::Relaxed); let _n: Box<Node<T>> = mem::transmute(cur); cur = next; } diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index c526e6acb8f..bd1e74a3390 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -28,10 +28,10 @@ use core::cmp; use core::int; use thread::Thread; +use sync::atomic::{AtomicInt, AtomicUint, Ordering, AtomicBool}; +use sync::mpsc::Receiver; use sync::mpsc::blocking::{self, SignalToken}; use sync::mpsc::spsc_queue as spsc; -use sync::mpsc::Receiver; -use sync::atomic; const DISCONNECTED: int = int::MIN; #[cfg(test)] @@ -42,11 +42,11 @@ const MAX_STEALS: int = 1 << 20; pub struct Packet<T> { queue: spsc::Queue<Message<T>>, // internal queue for all message - cnt: atomic::AtomicInt, // How many items are on this channel + cnt: AtomicInt, // How many items are on this channel steals: int, // How many times has a port received without blocking? - to_wake: atomic::AtomicUint, // SignalToken for the blocked thread to wake up + to_wake: AtomicUint, // SignalToken for the blocked thread to wake up - port_dropped: atomic::AtomicBool, // flag if the channel has been destroyed. + port_dropped: AtomicBool, // flag if the channel has been destroyed. } pub enum Failure<T> { @@ -79,11 +79,11 @@ impl<T: Send> Packet<T> { Packet { queue: unsafe { spsc::Queue::new(128) }, - cnt: atomic::AtomicInt::new(0), + cnt: AtomicInt::new(0), steals: 0, - to_wake: atomic::AtomicUint::new(0), + to_wake: AtomicUint::new(0), - port_dropped: atomic::AtomicBool::new(false), + port_dropped: AtomicBool::new(false), } } @@ -91,7 +91,7 @@ impl<T: Send> Packet<T> { // If the other port has deterministically gone away, then definitely // must return the data back up the stack. Otherwise, the data is // considered as being sent. - if self.port_dropped.load(atomic::SeqCst) { return Err(t) } + if self.port_dropped.load(Ordering::SeqCst) { return Err(t) } match self.do_send(Data(t)) { UpSuccess | UpDisconnected => {}, @@ -103,14 +103,14 @@ impl<T: Send> Packet<T> { pub fn upgrade(&mut self, up: Receiver<T>) -> UpgradeResult { // If the port has gone away, then there's no need to proceed any // further. - if self.port_dropped.load(atomic::SeqCst) { return UpDisconnected } + if self.port_dropped.load(Ordering::SeqCst) { return UpDisconnected } self.do_send(GoUp(up)) } fn do_send(&mut self, t: Message<T>) -> UpgradeResult { self.queue.push(t); - match self.cnt.fetch_add(1, atomic::SeqCst) { + match self.cnt.fetch_add(1, Ordering::SeqCst) { // As described in the mod's doc comment, -1 == wakeup -1 => UpWoke(self.take_to_wake()), // As as described before, SPSC queues must be >= -2 @@ -124,7 +124,7 @@ impl<T: Send> Packet<T> { // will never remove this data. We can only have at most one item to // drain (the port drains the rest). DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomic::SeqCst); + self.cnt.store(DISCONNECTED, Ordering::SeqCst); let first = self.queue.pop(); let second = self.queue.pop(); assert!(second.is_none()); @@ -143,8 +143,8 @@ impl<T: Send> Packet<T> { // Consumes ownership of the 'to_wake' field. fn take_to_wake(&mut self) -> SignalToken { - let ptr = self.to_wake.load(atomic::SeqCst); - self.to_wake.store(0, atomic::SeqCst); + let ptr = self.to_wake.load(Ordering::SeqCst); + self.to_wake.store(0, Ordering::SeqCst); assert!(ptr != 0); unsafe { SignalToken::cast_from_uint(ptr) } } @@ -153,15 +153,15 @@ impl<T: Send> Packet<T> { // back if it shouldn't sleep. Note that this is the location where we take // steals into account. fn decrement(&mut self, token: SignalToken) -> Result<(), SignalToken> { - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); let ptr = unsafe { token.cast_to_uint() }; - self.to_wake.store(ptr, atomic::SeqCst); + self.to_wake.store(ptr, Ordering::SeqCst); let steals = self.steals; self.steals = 0; - match self.cnt.fetch_sub(1 + steals, atomic::SeqCst) { - DISCONNECTED => { self.cnt.store(DISCONNECTED, atomic::SeqCst); } + match self.cnt.fetch_sub(1 + steals, Ordering::SeqCst) { + DISCONNECTED => { self.cnt.store(DISCONNECTED, Ordering::SeqCst); } // If we factor in our steals and notice that the channel has no // data, we successfully sleep n => { @@ -170,7 +170,7 @@ impl<T: Send> Packet<T> { } } - self.to_wake.store(0, atomic::SeqCst); + self.to_wake.store(0, Ordering::SeqCst); Err(unsafe { SignalToken::cast_from_uint(ptr) }) } @@ -217,9 +217,9 @@ impl<T: Send> Packet<T> { // adding back in whatever we couldn't factor into steals. Some(data) => { if self.steals > MAX_STEALS { - match self.cnt.swap(0, atomic::SeqCst) { + match self.cnt.swap(0, Ordering::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomic::SeqCst); + self.cnt.store(DISCONNECTED, Ordering::SeqCst); } n => { let m = cmp::min(n, self.steals); @@ -237,7 +237,7 @@ impl<T: Send> Packet<T> { } None => { - match self.cnt.load(atomic::SeqCst) { + match self.cnt.load(Ordering::SeqCst) { n if n != DISCONNECTED => Err(Empty), // This is a little bit of a tricky case. We failed to pop @@ -266,7 +266,7 @@ impl<T: Send> Packet<T> { pub fn drop_chan(&mut self) { // Dropping a channel is pretty simple, we just flag it as disconnected // and then wakeup a blocker if there is one. - match self.cnt.swap(DISCONNECTED, atomic::SeqCst) { + match self.cnt.swap(DISCONNECTED, Ordering::SeqCst) { -1 => { self.take_to_wake().signal(); } DISCONNECTED => {} n => { assert!(n >= 0); } @@ -293,7 +293,7 @@ impl<T: Send> Packet<T> { // sends are gated on this flag, so we're immediately guaranteed that // there are a bounded number of active sends that we'll have to deal // with. - self.port_dropped.store(true, atomic::SeqCst); + self.port_dropped.store(true, Ordering::SeqCst); // Now that we're guaranteed to deal with a bounded number of senders, // we need to drain the queue. This draining process happens atomically @@ -306,7 +306,7 @@ impl<T: Send> Packet<T> { let mut steals = self.steals; while { let cnt = self.cnt.compare_and_swap( - steals, DISCONNECTED, atomic::SeqCst); + steals, DISCONNECTED, Ordering::SeqCst); cnt != DISCONNECTED && cnt != steals } { loop { @@ -351,9 +351,9 @@ impl<T: Send> Packet<T> { // increment the count on the channel (used for selection) fn bump(&mut self, amt: int) -> int { - match self.cnt.fetch_add(amt, atomic::SeqCst) { + match self.cnt.fetch_add(amt, Ordering::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomic::SeqCst); + self.cnt.store(DISCONNECTED, Ordering::SeqCst); DISCONNECTED } n => n @@ -403,7 +403,7 @@ impl<T: Send> Packet<T> { // of time until the data is actually sent. if was_upgrade { assert_eq!(self.steals, 0); - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); return Ok(true) } @@ -416,7 +416,7 @@ impl<T: Send> Packet<T> { // If we were previously disconnected, then we know for sure that there // is no task in to_wake, so just keep going let has_data = if prev == DISCONNECTED { - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); true // there is data, that data is that we're disconnected } else { let cur = prev + steals + 1; @@ -439,7 +439,7 @@ impl<T: Send> Packet<T> { if prev < 0 { drop(self.take_to_wake()); } else { - while self.to_wake.load(atomic::SeqCst) != 0 { + while self.to_wake.load(Ordering::SeqCst) != 0 { Thread::yield_now(); } } @@ -478,7 +478,7 @@ impl<T: Send> Drop for Packet<T> { // disconnection, but also a proper fence before the read of // `to_wake`, so this assert cannot be removed with also removing // the `to_wake` assert. - assert_eq!(self.cnt.load(atomic::SeqCst), DISCONNECTED); - assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.cnt.load(Ordering::SeqCst), DISCONNECTED); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); } } diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 0eee10898bc..6836888e67e 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -41,14 +41,15 @@ use self::Blocker::*; use vec::Vec; use core::mem; -use sync::{atomic, Mutex, MutexGuard}; +use sync::atomic::{Ordering, AtomicUint}; use sync::mpsc::blocking::{self, WaitToken, SignalToken}; use sync::mpsc::select::StartResult::{self, Installed, Abort}; +use sync::{Mutex, MutexGuard}; pub struct Packet<T> { /// Only field outside of the mutex. Just done for kicks, but mainly because /// the other shared channel already had the code implemented - channels: atomic::AtomicUint, + channels: AtomicUint, lock: Mutex<State<T>>, } @@ -137,7 +138,7 @@ fn wakeup<T>(token: SignalToken, guard: MutexGuard<State<T>>) { impl<T: Send> Packet<T> { pub fn new(cap: uint) -> Packet<T> { Packet { - channels: atomic::AtomicUint::new(1), + channels: AtomicUint::new(1), lock: Mutex::new(State { disconnected: false, blocker: NoneBlocked, @@ -304,12 +305,12 @@ impl<T: Send> Packet<T> { // Prepares this shared packet for a channel clone, essentially just bumping // a refcount. pub fn clone_chan(&self) { - self.channels.fetch_add(1, atomic::SeqCst); + self.channels.fetch_add(1, Ordering::SeqCst); } pub fn drop_chan(&self) { // Only flag the channel as disconnected if we're the last channel - match self.channels.fetch_sub(1, atomic::SeqCst) { + match self.channels.fetch_sub(1, Ordering::SeqCst) { 1 => {} _ => return } @@ -412,7 +413,7 @@ impl<T: Send> Packet<T> { #[unsafe_destructor] impl<T: Send> Drop for Packet<T> { fn drop(&mut self) { - assert_eq!(self.channels.load(atomic::SeqCst), 0); + assert_eq!(self.channels.load(Ordering::SeqCst), 0); let mut guard = self.lock.lock().unwrap(); assert!(guard.queue.dequeue().is_none()); assert!(guard.canceled.is_none()); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 9e9a17e482f..08e323c9cb4 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -17,7 +17,7 @@ use int; use kinds::Sync; use mem::drop; use ops::FnOnce; -use sync::atomic; +use sync::atomic::{AtomicInt, Ordering, ATOMIC_INT_INIT}; use sync::{StaticMutex, MUTEX_INIT}; /// A synchronization primitive which can be used to run a one-time global @@ -39,8 +39,8 @@ use sync::{StaticMutex, MUTEX_INIT}; #[stable] pub struct Once { mutex: StaticMutex, - cnt: atomic::AtomicInt, - lock_cnt: atomic::AtomicInt, + cnt: AtomicInt, + lock_cnt: AtomicInt, } unsafe impl Sync for Once {} @@ -49,8 +49,8 @@ unsafe impl Sync for Once {} #[stable] pub const ONCE_INIT: Once = Once { mutex: MUTEX_INIT, - cnt: atomic::ATOMIC_INT_INIT, - lock_cnt: atomic::ATOMIC_INT_INIT, + cnt: ATOMIC_INT_INIT, + lock_cnt: ATOMIC_INT_INIT, }; impl Once { @@ -66,7 +66,7 @@ impl Once { #[stable] pub fn call_once<F>(&'static self, f: F) where F: FnOnce() { // Optimize common path: load is much cheaper than fetch_add. - if self.cnt.load(atomic::SeqCst) < 0 { + if self.cnt.load(Ordering::SeqCst) < 0 { return } @@ -97,11 +97,11 @@ impl Once { // calling `call_once` will return immediately before the initialization // has completed. - let prev = self.cnt.fetch_add(1, atomic::SeqCst); + let prev = self.cnt.fetch_add(1, Ordering::SeqCst); if prev < 0 { // Make sure we never overflow, we'll never have int::MIN // simultaneous calls to `call_once` to make this value go back to 0 - self.cnt.store(int::MIN, atomic::SeqCst); + self.cnt.store(int::MIN, Ordering::SeqCst); return } @@ -109,15 +109,15 @@ impl Once { // otherwise we run the job and record how many people will try to grab // this lock let guard = self.mutex.lock(); - if self.cnt.load(atomic::SeqCst) > 0 { + if self.cnt.load(Ordering::SeqCst) > 0 { f(); - let prev = self.cnt.swap(int::MIN, atomic::SeqCst); - self.lock_cnt.store(prev, atomic::SeqCst); + let prev = self.cnt.swap(int::MIN, Ordering::SeqCst); + self.lock_cnt.store(prev, Ordering::SeqCst); } drop(guard); // Last one out cleans up after everyone else, no leaks! - if self.lock_cnt.fetch_add(-1, atomic::SeqCst) == 1 { + if self.lock_cnt.fetch_add(-1, Ordering::SeqCst) == 1 { unsafe { self.mutex.destroy() } } } diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index 158fd3a8382..e9af796c674 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -58,7 +58,7 @@ use prelude::v1::*; -use sync::atomic::{self, AtomicUint}; +use sync::atomic::{self, AtomicUint, Ordering}; use sync::{Mutex, Once, ONCE_INIT}; use sys::thread_local as imp; @@ -166,7 +166,7 @@ impl StaticKey { /// Note that this does *not* run the user-provided destructor if one was /// specified at definition time. Doing so must be done manually. pub unsafe fn destroy(&self) { - match self.inner.key.swap(0, atomic::SeqCst) { + match self.inner.key.swap(0, Ordering::SeqCst) { 0 => {} n => { imp::destroy(n as imp::Key) } } @@ -174,7 +174,7 @@ impl StaticKey { #[inline] unsafe fn key(&self) -> imp::Key { - match self.inner.key.load(atomic::Relaxed) { + match self.inner.key.load(Ordering::Relaxed) { 0 => self.lazy_init() as imp::Key, n => n as imp::Key } @@ -199,7 +199,7 @@ impl StaticKey { key2 }; assert!(key != 0); - match self.inner.key.compare_and_swap(0, key as uint, atomic::SeqCst) { + match self.inner.key.compare_and_swap(0, key as uint, Ordering::SeqCst) { // The CAS succeeded, so we've created the actual key 0 => key as uint, // If someone beat us to the punch, use their key instead diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 690574301d7..181b8fdd0f8 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -20,7 +20,6 @@ use libc::{self, c_int, c_char, c_void}; use os; use path::{BytesContainer}; use ptr; -use sync::atomic::{AtomicInt, SeqCst}; use sys::fs::FileDesc; use os::TMPBUF_SZ; diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index fcbfb383d3c..9063fbc2ba9 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -13,7 +13,8 @@ use prelude::v1::*; use libc; use c_str::CString; use mem; -use sync::{atomic, Arc, Mutex}; +use sync::{Arc, Mutex}; +use sync::atomic::{AtomicBool, Ordering}; use io::{self, IoResult, IoError}; use sys::{self, timer, retry, c, set_nonblocking, wouldblock}; @@ -242,7 +243,7 @@ impl UnixListener { listener: self, reader: reader, writer: writer, - closed: atomic::AtomicBool::new(false), + closed: AtomicBool::new(false), }), deadline: 0, }) @@ -260,7 +261,7 @@ struct AcceptorInner { listener: UnixListener, reader: FileDesc, writer: FileDesc, - closed: atomic::AtomicBool, + closed: AtomicBool, } impl UnixAcceptor { @@ -269,7 +270,7 @@ impl UnixAcceptor { pub fn accept(&mut self) -> IoResult<UnixStream> { let deadline = if self.deadline == 0 {None} else {Some(self.deadline)}; - while !self.inner.closed.load(atomic::SeqCst) { + while !self.inner.closed.load(Ordering::SeqCst) { unsafe { let mut storage: libc::sockaddr_storage = mem::zeroed(); let storagep = &mut storage as *mut libc::sockaddr_storage; @@ -297,7 +298,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 fd = FileDesc::new(self.inner.writer.fd(), false); match fd.write(&[0]) { Ok(..) => Ok(()), diff --git a/src/libstd/sys/unix/tcp.rs b/src/libstd/sys/unix/tcp.rs index 13ccf685fd7..59eebd3f28e 100644 --- a/src/libstd/sys/unix/tcp.rs +++ b/src/libstd/sys/unix/tcp.rs @@ -16,7 +16,8 @@ use libc; use mem; use ptr; 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::{set_nonblocking, wouldblock}; use sys; @@ -74,7 +75,7 @@ impl TcpListener { listener: self, reader: reader, writer: writer, - closed: atomic::AtomicBool::new(false), + closed: AtomicBool::new(false), }), deadline: 0, }) @@ -96,7 +97,7 @@ struct AcceptorInner { listener: TcpListener, reader: FileDesc, writer: FileDesc, - closed: atomic::AtomicBool, + closed: AtomicBool, } unsafe impl Sync for AcceptorInner {} @@ -121,7 +122,7 @@ impl TcpAcceptor { // self-pipe is never written to unless close_accept() is called. let deadline = if self.deadline == 0 {None} else {Some(self.deadline)}; - while !self.inner.closed.load(atomic::SeqCst) { + while !self.inner.closed.load(Ordering::SeqCst) { match retry(|| unsafe { libc::accept(self.fd(), ptr::null_mut(), ptr::null_mut()) }) { @@ -145,7 +146,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 fd = FileDesc::new(self.inner.writer.fd(), false); match fd.write(&[0]) { Ok(..) => Ok(()), diff --git a/src/libstd/sys/unix/timer.rs b/src/libstd/sys/unix/timer.rs index 80f93dd2f61..11f29232a92 100644 --- a/src/libstd/sys/unix/timer.rs +++ b/src/libstd/sys/unix/timer.rs @@ -54,7 +54,7 @@ use libc; use mem; use os; use ptr; -use sync::atomic; +use sync::atomic::{mod, Ordering}; use sync::mpsc::{channel, Sender, Receiver, TryRecvError}; use sys::c; use sys::fs::FileDesc; @@ -212,7 +212,7 @@ impl Timer { HELPER.boot(|| {}, helper); static ID: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT; - let id = ID.fetch_add(1, atomic::Relaxed); + let id = ID.fetch_add(1, Ordering::Relaxed); Ok(Timer { id: id, inner: Some(box Inner { 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(()) diff --git a/src/libstd/task.rs b/src/libstd/task.rs deleted file mode 100644 index 0f08108fee5..00000000000 --- a/src/libstd/task.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Deprecated in favor of `thread`. - -#![deprecated = "use std::thread instead"] - -use any::Any; -use boxed::Box; -use thread; -use kinds::Send; -use result::Result; -use ops::FnOnce; - -/// Deprecate: use `std::thread::Builder` instead. -#[deprecated = "use std::thread::Builder instead"] -pub type TaskBuilder = thread::Builder; - -/// Deprecated: use `std::thread::Thread::spawn` and `detach` instead. -#[deprecated = "use std::thread::Thread::spawn and detach instead"] -pub fn spawn<F>(f: F) where F: FnOnce(), F: Send { - thread::Thread::spawn(f).detach(); -} - -/// Deprecated: use `std::thread::Thread::spawn` and `join` instead. -#[deprecated = "use std::thread::Thread::spawn and join instead"] -pub fn try<T, F>(f: F) -> Result<T, Box<Any + Send>> where - T: Send, F: FnOnce() -> T, F: Send -{ - thread::Thread::spawn(f).join() -} - -/// Deprecated: use `std::thread::Thread::yield_now instead`. -#[deprecated = "use std::thread::Thread::yield_now instead"] -pub fn deschedule() { - thread::Thread::yield_now() -} diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 9c8a5fc239c..1d6f49b04a3 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -125,7 +125,6 @@ //! * It can be implemented highly efficiently on many platforms. use any::Any; -use borrow::IntoCow; use boxed::Box; use cell::UnsafeCell; use clone::Clone; @@ -175,12 +174,6 @@ impl Builder { self } - /// Deprecated: use `name` instead - #[deprecated = "use name instead"] - pub fn named<T: IntoCow<'static, String, str>>(self, name: T) -> Builder { - self.name(name.into_cow().into_owned()) - } - /// Set the size of the stack for the new thread. pub fn stack_size(mut self, size: uint) -> Builder { self.stack_size = Some(size); diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index fc90bffa03c..f40b62182d4 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -35,17 +35,6 @@ //! //! # Examples //! -//! Using fields: -//! -//! ``` -//! #[allow(deprecated)] -//! # fn main() { -//! let pair = ("pi", 3.14f64); -//! assert_eq!(pair.0, "pi"); -//! assert_eq!(pair.1, 3.14f64); -//! # } -//! ``` -//! //! Using traits implemented for tuples: //! //! ``` |
