diff options
| author | bors <bors@rust-lang.org> | 2015-02-24 09:33:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-24 09:33:17 +0000 |
| commit | dccdde4007c191aa8b8d9cfffb0c7d3509fa675e (patch) | |
| tree | f4493e88a229c9622daf5389616001fd48d337c2 /src/libstd | |
| parent | 0ef56da541a90c62801440702a3e3c009e5332be (diff) | |
| parent | b182cd7245a999ac702f88c89dcc28811d6fdf8a (diff) | |
| download | rust-dccdde4007c191aa8b8d9cfffb0c7d3509fa675e.tar.gz rust-dccdde4007c191aa8b8d9cfffb0c7d3509fa675e.zip | |
Auto merge of #22755 - Manishearth:rollup, r=Manishearth
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 1 | ||||
| -rw-r--r-- | src/libstd/collections/hash/state.rs | 1 | ||||
| -rw-r--r-- | src/libstd/io/impls.rs | 37 | ||||
| -rw-r--r-- | src/libstd/prelude/v1.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sync/barrier.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sync/condvar.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/blocking.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/mod.rs | 188 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/oneshot.rs | 30 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/select.rs | 60 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/shared.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/spsc_queue.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/stream.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/sync.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sync/mutex.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sync/task_pool.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs2.rs | 33 | ||||
| -rw-r--r-- | src/libstd/sys/windows/fs2.rs | 39 | ||||
| -rw-r--r-- | src/libstd/thread.rs | 13 | ||||
| -rw-r--r-- | src/libstd/thread_local/mod.rs | 18 | ||||
| -rw-r--r-- | src/libstd/thread_local/scoped.rs | 12 |
21 files changed, 284 insertions, 225 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 4d38d17576d..94457a5d714 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -37,6 +37,7 @@ pub trait OwnedAsciiExt { /// Extension methods for ASCII-subset only operations on string slices #[stable(feature = "rust1", since = "1.0.0")] pub trait AsciiExt { + /// Container type for copied ASCII characters. #[stable(feature = "rust1", since = "1.0.0")] type Owned; diff --git a/src/libstd/collections/hash/state.rs b/src/libstd/collections/hash/state.rs index 7e6dd45b51e..3a06d2d03bf 100644 --- a/src/libstd/collections/hash/state.rs +++ b/src/libstd/collections/hash/state.rs @@ -27,6 +27,7 @@ use marker; /// to `Default` when asked to create a hasher. #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] pub trait HashState { + /// Type of the hasher that will be created. type Hasher: hash::Hasher; /// Creates a new hasher based on the given state of this object. diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index 7f3ce7924c1..82b69ddebff 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -12,9 +12,11 @@ use core::prelude::*; use boxed::Box; use cmp; -use io::{self, SeekFrom, Read, Write, Seek, BufRead}; +use io::{self, SeekFrom, Read, Write, Seek, BufRead, Error, ErrorKind}; +use fmt; use mem; use slice; +use string::String; use vec::Vec; // ============================================================================= @@ -22,9 +24,20 @@ use vec::Vec; impl<'a, R: Read + ?Sized> Read for &'a mut R { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { (**self).read(buf) } + + fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<()> { (**self).read_to_end(buf) } + + fn read_to_string(&mut self, buf: &mut String) -> io::Result<()> { + (**self).read_to_string(buf) + } } impl<'a, W: Write + ?Sized> Write for &'a mut W { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) } + + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { (**self).write_all(buf) } + + fn write_fmt(&mut self, fmt: fmt::Arguments) -> io::Result<()> { (**self).write_fmt(fmt) } + fn flush(&mut self) -> io::Result<()> { (**self).flush() } } impl<'a, S: Seek + ?Sized> Seek for &'a mut S { @@ -32,7 +45,14 @@ impl<'a, S: Seek + ?Sized> Seek for &'a mut S { } impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } + fn consume(&mut self, amt: usize) { (**self).consume(amt) } + + fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<()> { + (**self).read_until(byte, buf) + } + + fn read_line(&mut self, buf: &mut String) -> io::Result<()> { (**self).read_line(buf) } } impl<R: Read + ?Sized> Read for Box<R> { @@ -76,6 +96,15 @@ impl<'a> Write for &'a mut [u8] { *self = b; Ok(amt) } + + fn write_all(&mut self, data: &[u8]) -> io::Result<()> { + if try!(self.write(data)) == data.len() { + Ok(()) + } else { + Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer", None)) + } + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } @@ -84,5 +113,11 @@ impl Write for Vec<u8> { self.push_all(buf); Ok(buf.len()) } + + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { + try!(self.write(buf)); + Ok(()) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs index d2dc3345120..dad0ff0a15e 100644 --- a/src/libstd/prelude/v1.rs +++ b/src/libstd/prelude/v1.rs @@ -23,7 +23,6 @@ #[doc(no_inline)] pub use mem::drop; // Reexported types and traits - #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use boxed::Box; #[stable(feature = "rust1", since = "1.0.0")] @@ -45,9 +44,7 @@ #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use result::Result::{self, Ok, Err}; #[stable(feature = "rust1", since = "1.0.0")] -#[doc(no_inline)] pub use slice::AsSlice; -#[stable(feature = "rust1", since = "1.0.0")] -#[doc(no_inline)] pub use slice::{SliceExt, SliceConcatExt}; +#[doc(no_inline)] pub use slice::{SliceExt, SliceConcatExt, AsSlice}; #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use str::{Str, StrExt}; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index b036177af15..f697d10d5df 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -33,13 +33,13 @@ use sync::{Mutex, Condvar}; pub struct Barrier { lock: Mutex<BarrierState>, cvar: Condvar, - num_threads: uint, + num_threads: usize, } // The inner state of a double barrier struct BarrierState { - count: uint, - generation_id: uint, + count: usize, + generation_id: usize, } /// A result returned from wait. @@ -54,7 +54,7 @@ impl Barrier { /// A barrier will block `n`-1 threads which call `wait` and then wake up /// all threads at once when the `n`th thread calls `wait`. #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(n: uint) -> Barrier { + pub fn new(n: usize) -> Barrier { Barrier { lock: Mutex::new(BarrierState { count: 0, @@ -115,7 +115,7 @@ mod tests { #[test] fn test_barrier() { - const N: uint = 10; + const N: usize = 10; let barrier = Arc::new(Barrier::new(N)); let (tx, rx) = channel(); diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 52561d482c3..aa87abc6e9a 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -327,7 +327,7 @@ impl StaticCondvar { } fn verify(&self, mutex: &sys_mutex::Mutex) { - let addr = mutex as *const _ as uint; + let addr = mutex as *const _ as usize; 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. @@ -388,7 +388,7 @@ mod tests { #[test] fn notify_all() { - const N: uint = 10; + const N: usize = 10; let data = Arc::new((Mutex::new(0), Condvar::new())); let (tx, rx) = channel(); diff --git a/src/libstd/sync/mpsc/blocking.rs b/src/libstd/sync/mpsc/blocking.rs index 69b1e242b15..2e4155ea351 100644 --- a/src/libstd/sync/mpsc/blocking.rs +++ b/src/libstd/sync/mpsc/blocking.rs @@ -61,17 +61,17 @@ impl SignalToken { wake } - /// Convert to an unsafe uint value. Useful for storing in a pipe's state + /// Convert to an unsafe usize value. Useful for storing in a pipe's state /// flag. #[inline] - pub unsafe fn cast_to_uint(self) -> uint { + pub unsafe fn cast_to_usize(self) -> usize { mem::transmute(self.inner) } - /// Convert from an unsafe uint value. Useful for retrieving a pipe's state + /// Convert from an unsafe usize value. Useful for retrieving a pipe's state /// flag. #[inline] - pub unsafe fn cast_from_uint(signal_ptr: uint) -> SignalToken { + pub unsafe fn cast_from_usize(signal_ptr: usize) -> SignalToken { SignalToken { inner: mem::transmute(signal_ptr) } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index b437549a044..7bd1f3542eb 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -94,7 +94,7 @@ //! //! // The call to recv() will return an error because the channel has already //! // hung up (or been deallocated) -//! let (tx, rx) = channel::<int>(); +//! let (tx, rx) = channel::<i32>(); //! drop(tx); //! assert!(rx.recv().is_err()); //! ``` @@ -105,7 +105,7 @@ //! use std::thread; //! use std::sync::mpsc::sync_channel; //! -//! let (tx, rx) = sync_channel::<int>(0); +//! let (tx, rx) = sync_channel::<i32>(0); //! thread::spawn(move|| { //! // This will wait for the parent task to start receiving //! tx.send(53).unwrap(); @@ -123,7 +123,7 @@ //! use std::old_io::timer::Timer; //! use std::time::Duration; //! -//! let (tx, rx) = channel::<int>(); +//! let (tx, rx) = channel::<i32>(); //! let mut timer = Timer::new().unwrap(); //! let timeout = timer.oneshot(Duration::seconds(10)); //! @@ -147,7 +147,7 @@ //! use std::old_io::timer::Timer; //! use std::time::Duration; //! -//! let (tx, rx) = channel::<int>(); +//! let (tx, rx) = channel::<i32>(); //! let mut timer = Timer::new().unwrap(); //! //! loop { @@ -525,7 +525,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) { /// assert_eq!(rx.recv().unwrap(), 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) { +pub fn sync_channel<T: Send>(bound: usize) -> (SyncSender<T>, Receiver<T>) { let a = Arc::new(UnsafeCell::new(sync::Packet::new(bound))); (SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a))) } @@ -1028,7 +1028,7 @@ mod test { use super::*; use thread; - pub fn stress_factor() -> uint { + pub fn stress_factor() -> usize { match env::var("RUST_TEST_STRESS") { Ok(val) => val.parse().unwrap(), Err(..) => 1, @@ -1037,7 +1037,7 @@ mod test { #[test] fn smoke() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); tx.send(1).unwrap(); assert_eq!(rx.recv().unwrap(), 1); } @@ -1058,7 +1058,7 @@ mod test { #[test] fn smoke_shared() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); tx.send(1).unwrap(); assert_eq!(rx.recv().unwrap(), 1); let tx = tx.clone(); @@ -1068,7 +1068,7 @@ mod test { #[test] fn smoke_threads() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let _t = thread::spawn(move|| { tx.send(1).unwrap(); }); @@ -1077,21 +1077,21 @@ mod test { #[test] fn smoke_port_gone() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(rx); assert!(tx.send(1).is_err()); } #[test] fn smoke_shared_port_gone() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(rx); assert!(tx.send(1).is_err()) } #[test] fn smoke_shared_port_gone2() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(rx); let tx2 = tx.clone(); drop(tx); @@ -1100,7 +1100,7 @@ mod test { #[test] fn port_gone_concurrent() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let _t = thread::spawn(move|| { rx.recv().unwrap(); }); @@ -1109,7 +1109,7 @@ mod test { #[test] fn port_gone_concurrent_shared() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let tx2 = tx.clone(); let _t = thread::spawn(move|| { rx.recv().unwrap(); @@ -1119,7 +1119,7 @@ mod test { #[test] fn smoke_chan_gone() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(tx); assert!(rx.recv().is_err()); } @@ -1135,7 +1135,7 @@ mod test { #[test] fn chan_gone_concurrent() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let _t = thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); @@ -1145,7 +1145,7 @@ mod test { #[test] fn stress() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let t = thread::spawn(move|| { for _ in 0..10000 { tx.send(1).unwrap(); } }); @@ -1157,9 +1157,9 @@ mod test { #[test] fn stress_shared() { - static AMT: uint = 10000; - static NTHREADS: uint = 8; - let (tx, rx) = channel::<int>(); + static AMT: u32 = 10000; + static NTHREADS: u32 = 8; + let (tx, rx) = channel::<i32>(); let t = thread::spawn(move|| { for _ in 0..AMT * NTHREADS { @@ -1184,7 +1184,7 @@ mod test { #[test] fn send_from_outside_runtime() { let (tx1, rx1) = channel::<()>(); - let (tx2, rx2) = channel::<int>(); + let (tx2, rx2) = channel::<i32>(); let t1 = thread::spawn(move|| { tx1.send(()).unwrap(); for _ in 0..40 { @@ -1203,7 +1203,7 @@ mod test { #[test] fn recv_from_outside_runtime() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let t = thread::spawn(move|| { for _ in 0..40 { assert_eq!(rx.recv().unwrap(), 1); @@ -1217,8 +1217,8 @@ mod test { #[test] fn no_runtime() { - let (tx1, rx1) = channel::<int>(); - let (tx2, rx2) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); + let (tx2, rx2) = channel::<i32>(); let t1 = thread::spawn(move|| { assert_eq!(rx1.recv().unwrap(), 1); tx2.send(2).unwrap(); @@ -1234,21 +1234,21 @@ mod test { #[test] fn oneshot_single_thread_close_port_first() { // Simple test of closing without sending - let (_tx, rx) = channel::<int>(); + let (_tx, rx) = channel::<i32>(); drop(rx); } #[test] fn oneshot_single_thread_close_chan_first() { // Simple test of closing without sending - let (tx, _rx) = channel::<int>(); + let (tx, _rx) = channel::<i32>(); drop(tx); } #[test] fn oneshot_single_thread_send_port_close() { // Testing that the sender cleans up the payload if receiver is closed - let (tx, rx) = channel::<Box<int>>(); + let (tx, rx) = channel::<Box<i32>>(); drop(rx); assert!(tx.send(box 0).is_err()); } @@ -1257,7 +1257,7 @@ mod test { fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic let res = thread::spawn(move|| { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(tx); rx.recv().unwrap(); }).join(); @@ -1267,42 +1267,42 @@ mod test { #[test] fn oneshot_single_thread_send_then_recv() { - let (tx, rx) = channel::<Box<int>>(); + let (tx, rx) = channel::<Box<i32>>(); tx.send(box 10).unwrap(); assert!(rx.recv().unwrap() == box 10); } #[test] fn oneshot_single_thread_try_send_open() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); assert!(tx.send(10).is_ok()); assert!(rx.recv().unwrap() == 10); } #[test] fn oneshot_single_thread_try_send_closed() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(rx); assert!(tx.send(10).is_err()); } #[test] fn oneshot_single_thread_try_recv_open() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); tx.send(10).unwrap(); assert!(rx.recv() == Ok(10)); } #[test] fn oneshot_single_thread_try_recv_closed() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(tx); assert!(rx.recv().is_err()); } #[test] fn oneshot_single_thread_peek_data() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); assert_eq!(rx.try_recv(), Err(TryRecvError::Empty)); tx.send(10).unwrap(); assert_eq!(rx.try_recv(), Ok(10)); @@ -1310,7 +1310,7 @@ mod test { #[test] fn oneshot_single_thread_peek_close() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); drop(tx); assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected)); assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected)); @@ -1318,13 +1318,13 @@ mod test { #[test] fn oneshot_single_thread_peek_open() { - let (_tx, rx) = channel::<int>(); + let (_tx, rx) = channel::<i32>(); assert_eq!(rx.try_recv(), Err(TryRecvError::Empty)); } #[test] fn oneshot_multi_task_recv_then_send() { - let (tx, rx) = channel::<Box<int>>(); + let (tx, rx) = channel::<Box<i32>>(); let _t = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }); @@ -1334,7 +1334,7 @@ mod test { #[test] fn oneshot_multi_task_recv_then_close() { - let (tx, rx) = channel::<Box<int>>(); + let (tx, rx) = channel::<Box<i32>>(); let _t = thread::spawn(move|| { drop(tx); }); @@ -1347,7 +1347,7 @@ mod test { #[test] fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let _t = thread::spawn(move|| { drop(rx); }); @@ -1358,7 +1358,7 @@ mod test { #[test] fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let _t = thread::spawn(move|| { drop(rx); }); @@ -1371,7 +1371,7 @@ mod test { #[test] fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); thread::spawn(move|| { let res = thread::spawn(move|| { rx.recv().unwrap(); @@ -1405,7 +1405,7 @@ mod test { send(tx, 0); recv(rx, 0); - fn send(tx: Sender<Box<int>>, i: int) { + fn send(tx: Sender<Box<i32>>, i: i32) { if i == 10 { return } thread::spawn(move|| { @@ -1414,7 +1414,7 @@ mod test { }); } - fn recv(rx: Receiver<Box<int>>, i: int) { + fn recv(rx: Receiver<Box<i32>>, i: i32) { if i == 10 { return } thread::spawn(move|| { @@ -1451,8 +1451,8 @@ mod test { #[test] fn test_nested_recv_iter() { - let (tx, rx) = channel::<int>(); - let (total_tx, total_rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); + let (total_tx, total_rx) = channel::<i32>(); let _t = thread::spawn(move|| { let mut acc = 0; @@ -1471,7 +1471,7 @@ mod test { #[test] fn test_recv_iter_break() { - let (tx, rx) = channel::<int>(); + let (tx, rx) = channel::<i32>(); let (count_tx, count_rx) = channel(); let _t = thread::spawn(move|| { @@ -1496,7 +1496,7 @@ mod test { #[test] fn try_recv_states() { - let (tx1, rx1) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); let (tx2, rx2) = channel::<()>(); let (tx3, rx3) = channel::<()>(); let _t = thread::spawn(move|| { @@ -1550,7 +1550,7 @@ mod sync_tests { use thread; use super::*; - pub fn stress_factor() -> uint { + pub fn stress_factor() -> usize { match env::var("RUST_TEST_STRESS") { Ok(val) => val.parse().unwrap(), Err(..) => 1, @@ -1559,7 +1559,7 @@ mod sync_tests { #[test] fn smoke() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); tx.send(1).unwrap(); assert_eq!(rx.recv().unwrap(), 1); } @@ -1572,7 +1572,7 @@ mod sync_tests { #[test] fn smoke_shared() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); tx.send(1).unwrap(); assert_eq!(rx.recv().unwrap(), 1); let tx = tx.clone(); @@ -1582,7 +1582,7 @@ mod sync_tests { #[test] fn smoke_threads() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { tx.send(1).unwrap(); }); @@ -1591,14 +1591,14 @@ mod sync_tests { #[test] fn smoke_port_gone() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(rx); assert!(tx.send(1).is_err()); } #[test] fn smoke_shared_port_gone2() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(rx); let tx2 = tx.clone(); drop(tx); @@ -1607,7 +1607,7 @@ mod sync_tests { #[test] fn port_gone_concurrent() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { rx.recv().unwrap(); }); @@ -1616,7 +1616,7 @@ mod sync_tests { #[test] fn port_gone_concurrent_shared() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let tx2 = tx.clone(); let _t = thread::spawn(move|| { rx.recv().unwrap(); @@ -1626,7 +1626,7 @@ mod sync_tests { #[test] fn smoke_chan_gone() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(tx); assert!(rx.recv().is_err()); } @@ -1642,7 +1642,7 @@ mod sync_tests { #[test] fn chan_gone_concurrent() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); @@ -1652,7 +1652,7 @@ mod sync_tests { #[test] fn stress() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); thread::spawn(move|| { for _ in 0..10000 { tx.send(1).unwrap(); } }); @@ -1663,9 +1663,9 @@ mod sync_tests { #[test] fn stress_shared() { - static AMT: uint = 1000; - static NTHREADS: uint = 8; - let (tx, rx) = sync_channel::<int>(0); + static AMT: u32 = 1000; + static NTHREADS: u32 = 8; + let (tx, rx) = sync_channel::<i32>(0); let (dtx, drx) = sync_channel::<()>(0); thread::spawn(move|| { @@ -1692,21 +1692,21 @@ mod sync_tests { #[test] fn oneshot_single_thread_close_port_first() { // Simple test of closing without sending - let (_tx, rx) = sync_channel::<int>(0); + let (_tx, rx) = sync_channel::<i32>(0); drop(rx); } #[test] fn oneshot_single_thread_close_chan_first() { // Simple test of closing without sending - let (tx, _rx) = sync_channel::<int>(0); + let (tx, _rx) = sync_channel::<i32>(0); drop(tx); } #[test] fn oneshot_single_thread_send_port_close() { // Testing that the sender cleans up the payload if receiver is closed - let (tx, rx) = sync_channel::<Box<int>>(0); + let (tx, rx) = sync_channel::<Box<i32>>(0); drop(rx); assert!(tx.send(box 0).is_err()); } @@ -1715,7 +1715,7 @@ mod sync_tests { fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic let res = thread::spawn(move|| { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(tx); rx.recv().unwrap(); }).join(); @@ -1725,48 +1725,48 @@ mod sync_tests { #[test] fn oneshot_single_thread_send_then_recv() { - let (tx, rx) = sync_channel::<Box<int>>(1); + let (tx, rx) = sync_channel::<Box<i32>>(1); tx.send(box 10).unwrap(); assert!(rx.recv().unwrap() == box 10); } #[test] fn oneshot_single_thread_try_send_open() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); assert_eq!(tx.try_send(10), Ok(())); assert!(rx.recv().unwrap() == 10); } #[test] fn oneshot_single_thread_try_send_closed() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(rx); assert_eq!(tx.try_send(10), Err(TrySendError::Disconnected(10))); } #[test] fn oneshot_single_thread_try_send_closed2() { - let (tx, _rx) = sync_channel::<int>(0); + let (tx, _rx) = sync_channel::<i32>(0); assert_eq!(tx.try_send(10), Err(TrySendError::Full(10))); } #[test] fn oneshot_single_thread_try_recv_open() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); tx.send(10).unwrap(); assert!(rx.recv() == Ok(10)); } #[test] fn oneshot_single_thread_try_recv_closed() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(tx); assert!(rx.recv().is_err()); } #[test] fn oneshot_single_thread_peek_data() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); assert_eq!(rx.try_recv(), Err(TryRecvError::Empty)); tx.send(10).unwrap(); assert_eq!(rx.try_recv(), Ok(10)); @@ -1774,7 +1774,7 @@ mod sync_tests { #[test] fn oneshot_single_thread_peek_close() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); drop(tx); assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected)); assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected)); @@ -1782,13 +1782,13 @@ mod sync_tests { #[test] fn oneshot_single_thread_peek_open() { - let (_tx, rx) = sync_channel::<int>(0); + let (_tx, rx) = sync_channel::<i32>(0); assert_eq!(rx.try_recv(), Err(TryRecvError::Empty)); } #[test] fn oneshot_multi_task_recv_then_send() { - let (tx, rx) = sync_channel::<Box<int>>(0); + let (tx, rx) = sync_channel::<Box<i32>>(0); let _t = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }); @@ -1798,7 +1798,7 @@ mod sync_tests { #[test] fn oneshot_multi_task_recv_then_close() { - let (tx, rx) = sync_channel::<Box<int>>(0); + let (tx, rx) = sync_channel::<Box<i32>>(0); let _t = thread::spawn(move|| { drop(tx); }); @@ -1811,7 +1811,7 @@ mod sync_tests { #[test] fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { drop(rx); }); @@ -1822,7 +1822,7 @@ mod sync_tests { #[test] fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { drop(rx); }); @@ -1835,7 +1835,7 @@ mod sync_tests { #[test] fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { let res = thread::spawn(move|| { rx.recv().unwrap(); @@ -1853,7 +1853,7 @@ mod sync_tests { #[test] fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { - let (tx, rx) = sync_channel::<Box<int>>(0); + let (tx, rx) = sync_channel::<Box<i32>>(0); let _t = thread::spawn(move|| { tx.send(box 10).unwrap(); }); @@ -1864,12 +1864,12 @@ mod sync_tests { #[test] fn stream_send_recv_stress() { for _ in 0..stress_factor() { - let (tx, rx) = sync_channel::<Box<int>>(0); + let (tx, rx) = sync_channel::<Box<i32>>(0); send(tx, 0); recv(rx, 0); - fn send(tx: SyncSender<Box<int>>, i: int) { + fn send(tx: SyncSender<Box<i32>>, i: i32) { if i == 10 { return } thread::spawn(move|| { @@ -1878,7 +1878,7 @@ mod sync_tests { }); } - fn recv(rx: Receiver<Box<int>>, i: int) { + fn recv(rx: Receiver<Box<i32>>, i: i32) { if i == 10 { return } thread::spawn(move|| { @@ -1915,8 +1915,8 @@ mod sync_tests { #[test] fn test_nested_recv_iter() { - let (tx, rx) = sync_channel::<int>(0); - let (total_tx, total_rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); + let (total_tx, total_rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { let mut acc = 0; @@ -1935,7 +1935,7 @@ mod sync_tests { #[test] fn test_recv_iter_break() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let (count_tx, count_rx) = sync_channel(0); let _t = thread::spawn(move|| { @@ -1960,7 +1960,7 @@ mod sync_tests { #[test] fn try_recv_states() { - let (tx1, rx1) = sync_channel::<int>(1); + let (tx1, rx1) = sync_channel::<i32>(1); let (tx2, rx2) = sync_channel::<()>(1); let (tx3, rx3) = sync_channel::<()>(1); let _t = thread::spawn(move|| { @@ -2007,21 +2007,21 @@ mod sync_tests { #[test] fn send1() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { rx.recv().unwrap(); }); assert_eq!(tx.send(1), Ok(())); } #[test] fn send2() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { drop(rx); }); assert!(tx.send(1).is_err()); } #[test] fn send3() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); assert_eq!(tx.send(1), Ok(())); let _t =thread::spawn(move|| { drop(rx); }); assert!(tx.send(1).is_err()); @@ -2029,7 +2029,7 @@ mod sync_tests { #[test] fn send4() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let tx2 = tx.clone(); let (done, donerx) = channel(); let done2 = done.clone(); @@ -2048,20 +2048,20 @@ mod sync_tests { #[test] fn try_send1() { - let (tx, _rx) = sync_channel::<int>(0); + let (tx, _rx) = sync_channel::<i32>(0); assert_eq!(tx.try_send(1), Err(TrySendError::Full(1))); } #[test] fn try_send2() { - let (tx, _rx) = sync_channel::<int>(1); + let (tx, _rx) = sync_channel::<i32>(1); assert_eq!(tx.try_send(1), Ok(())); assert_eq!(tx.try_send(1), Err(TrySendError::Full(1))); } #[test] fn try_send3() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); assert_eq!(tx.try_send(1), Ok(())); drop(rx); assert_eq!(tx.try_send(1), Err(TrySendError::Disconnected(1))); diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index eb45681fa62..f287712d9d4 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -22,7 +22,7 @@ /// /// # Implementation /// -/// Oneshots are implemented around one atomic uint variable. This variable +/// Oneshots are implemented around one atomic usize variable. This variable /// indicates both the state of the port/chan but also contains any tasks /// blocked on the port. All atomic operations happen on this one word. /// @@ -45,9 +45,9 @@ use core::mem; use sync::atomic::{AtomicUsize, Ordering}; // Various states you can find a port in. -const EMPTY: uint = 0; // initial state: no data, no blocked receiver -const DATA: uint = 1; // data ready for receiver to take -const DISCONNECTED: uint = 2; // channel is disconnected OR upgraded +const EMPTY: usize = 0; // initial state: no data, no blocked receiver +const DATA: usize = 1; // data ready for receiver to take +const DISCONNECTED: usize = 2; // channel is disconnected OR upgraded // Any other value represents a pointer to a SignalToken value. The // protocol ensures that when the state moves *to* a pointer, // ownership of the token is given to the packet, and when the state @@ -123,7 +123,7 @@ impl<T: Send> Packet<T> { // There is a thread waiting on the other end. We leave the 'DATA' // state inside so it'll pick it up on the other end. ptr => unsafe { - SignalToken::cast_from_uint(ptr).signal(); + SignalToken::cast_from_usize(ptr).signal(); Ok(()) } } @@ -143,7 +143,7 @@ impl<T: Send> Packet<T> { // like we're not empty, then immediately go through to `try_recv`. if self.state.load(Ordering::SeqCst) == EMPTY { let (wait_token, signal_token) = blocking::tokens(); - let ptr = unsafe { signal_token.cast_to_uint() }; + let ptr = unsafe { signal_token.cast_to_usize() }; // race with senders to enter the blocking state if self.state.compare_and_swap(EMPTY, ptr, Ordering::SeqCst) == EMPTY { @@ -151,7 +151,7 @@ impl<T: Send> Packet<T> { debug_assert!(self.state.load(Ordering::SeqCst) != EMPTY); } else { // drop the signal token, since we never blocked - drop(unsafe { SignalToken::cast_from_uint(ptr) }); + drop(unsafe { SignalToken::cast_from_usize(ptr) }); } } @@ -220,7 +220,7 @@ impl<T: Send> Packet<T> { DISCONNECTED => { self.upgrade = prev; UpDisconnected } // If someone's waiting, we gotta wake them up - ptr => UpWoke(unsafe { SignalToken::cast_from_uint(ptr) }) + ptr => UpWoke(unsafe { SignalToken::cast_from_usize(ptr) }) } } @@ -230,7 +230,7 @@ impl<T: Send> Packet<T> { // If someone's waiting, we gotta wake them up ptr => unsafe { - SignalToken::cast_from_uint(ptr).signal(); + SignalToken::cast_from_usize(ptr).signal(); } } } @@ -283,15 +283,15 @@ impl<T: Send> Packet<T> { // Attempts to start selection on this port. This can either succeed, fail // 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() }; + let ptr = unsafe { token.cast_to_usize() }; match self.state.compare_and_swap(EMPTY, ptr, Ordering::SeqCst) { EMPTY => SelSuccess, DATA => { - drop(unsafe { SignalToken::cast_from_uint(ptr) }); + drop(unsafe { SignalToken::cast_from_usize(ptr) }); SelCanceled } DISCONNECTED if self.data.is_some() => { - drop(unsafe { SignalToken::cast_from_uint(ptr) }); + drop(unsafe { SignalToken::cast_from_usize(ptr) }); SelCanceled } DISCONNECTED => { @@ -300,7 +300,7 @@ impl<T: Send> Packet<T> { // propagate upwards whether the upgrade can receive // data GoUp(upgrade) => { - SelUpgraded(unsafe { SignalToken::cast_from_uint(ptr) }, upgrade) + SelUpgraded(unsafe { SignalToken::cast_from_usize(ptr) }, upgrade) } // If the other end disconnected without sending an @@ -308,7 +308,7 @@ impl<T: Send> Packet<T> { // disconnected). up => { self.upgrade = up; - drop(unsafe { SignalToken::cast_from_uint(ptr) }); + drop(unsafe { SignalToken::cast_from_usize(ptr) }); SelCanceled } } @@ -360,7 +360,7 @@ impl<T: Send> Packet<T> { // We woke ourselves up from select. ptr => unsafe { - drop(SignalToken::cast_from_uint(ptr)); + drop(SignalToken::cast_from_usize(ptr)); Ok(false) } } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index db8efe19dc1..8de5bbc6206 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -71,7 +71,7 @@ use sync::mpsc::blocking::{self, SignalToken}; pub struct Select { head: *mut Handle<'static, ()>, tail: *mut Handle<'static, ()>, - next_id: Cell<uint>, + next_id: Cell<usize>, } impl !marker::Send for Select {} @@ -82,7 +82,7 @@ impl !marker::Send for Select {} pub struct Handle<'rx, T:'rx> { /// The ID of this handle, used to compare against the return value of /// `Select::wait()` - id: uint, + id: usize, selector: &'rx Select, next: *mut Handle<'static, ()>, prev: *mut Handle<'static, ()>, @@ -154,12 +154,12 @@ impl Select { /// the matching `id` will have some sort of event available on it. The /// event could either be that data is available or the corresponding /// channel has been closed. - pub fn wait(&self) -> uint { + pub fn wait(&self) -> usize { self.wait2(true) } /// Helper method for skipping the preflight checks during testing - fn wait2(&self, do_preflight_checks: bool) -> uint { + fn wait2(&self, do_preflight_checks: bool) -> usize { // Note that this is currently an inefficient implementation. We in // theory have knowledge about all receivers in the set ahead of time, // so this method shouldn't really have to iterate over all of them yet @@ -254,7 +254,7 @@ impl Select { impl<'rx, T: Send> Handle<'rx, T> { /// Retrieve the id of this handle. #[inline] - pub fn id(&self) -> uint { self.id } + pub fn id(&self) -> usize { self.id } /// Block to receive a value on the underlying receiver, returning `Some` on /// success or `None` if the channel disconnects. This function has the same @@ -369,8 +369,8 @@ mod test { #[test] fn smoke() { - let (tx1, rx1) = channel::<int>(); - let (tx2, rx2) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); + let (tx2, rx2) = channel::<i32>(); tx1.send(1).unwrap(); select! { foo = rx1.recv() => { assert_eq!(foo.unwrap(), 1); }, @@ -394,11 +394,11 @@ mod test { #[test] fn smoke2() { - let (_tx1, rx1) = channel::<int>(); - let (_tx2, rx2) = channel::<int>(); - let (_tx3, rx3) = channel::<int>(); - let (_tx4, rx4) = channel::<int>(); - let (tx5, rx5) = channel::<int>(); + let (_tx1, rx1) = channel::<i32>(); + let (_tx2, rx2) = channel::<i32>(); + let (_tx3, rx3) = channel::<i32>(); + let (_tx4, rx4) = channel::<i32>(); + let (tx5, rx5) = channel::<i32>(); tx5.send(4).unwrap(); select! { _foo = rx1.recv() => { panic!("1") }, @@ -411,8 +411,8 @@ mod test { #[test] fn closed() { - let (_tx1, rx1) = channel::<int>(); - let (tx2, rx2) = channel::<int>(); + let (_tx1, rx1) = channel::<i32>(); + let (tx2, rx2) = channel::<i32>(); drop(tx2); select! { @@ -423,9 +423,9 @@ mod test { #[test] fn unblocks() { - let (tx1, rx1) = channel::<int>(); - let (_tx2, rx2) = channel::<int>(); - let (tx3, rx3) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); + let (_tx2, rx2) = channel::<i32>(); + let (tx3, rx3) = channel::<i32>(); let _t = thread::spawn(move|| { for _ in 0..20 { thread::yield_now(); } @@ -447,8 +447,8 @@ mod test { #[test] fn both_ready() { - let (tx1, rx1) = channel::<int>(); - let (tx2, rx2) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); + let (tx2, rx2) = channel::<i32>(); let (tx3, rx3) = channel::<()>(); let _t = thread::spawn(move|| { @@ -473,9 +473,9 @@ mod test { #[test] fn stress() { - static AMT: int = 10000; - let (tx1, rx1) = channel::<int>(); - let (tx2, rx2) = channel::<int>(); + static AMT: i32 = 10000; + let (tx1, rx1) = channel::<i32>(); + let (tx2, rx2) = channel::<i32>(); let (tx3, rx3) = channel::<()>(); let _t = thread::spawn(move|| { @@ -500,8 +500,8 @@ mod test { #[test] fn cloning() { - let (tx1, rx1) = channel::<int>(); - let (_tx2, rx2) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); + let (_tx2, rx2) = channel::<i32>(); let (tx3, rx3) = channel::<()>(); let _t = thread::spawn(move|| { @@ -522,8 +522,8 @@ mod test { #[test] fn cloning2() { - let (tx1, rx1) = channel::<int>(); - let (_tx2, rx2) = channel::<int>(); + let (tx1, rx1) = channel::<i32>(); + let (_tx2, rx2) = channel::<i32>(); let (tx3, rx3) = channel::<()>(); let _t = thread::spawn(move|| { @@ -716,7 +716,7 @@ mod test { #[test] fn sync1() { - let (tx, rx) = sync_channel::<int>(1); + let (tx, rx) = sync_channel::<i32>(1); tx.send(1).unwrap(); select! { n = rx.recv() => { assert_eq!(n.unwrap(), 1); } @@ -725,7 +725,7 @@ mod test { #[test] fn sync2() { - let (tx, rx) = sync_channel::<int>(0); + let (tx, rx) = sync_channel::<i32>(0); let _t = thread::spawn(move|| { for _ in 0..100 { thread::yield_now() } tx.send(1).unwrap(); @@ -737,8 +737,8 @@ mod test { #[test] fn sync3() { - let (tx1, rx1) = sync_channel::<int>(0); - let (tx2, rx2): (Sender<int>, Receiver<int>) = channel(); + let (tx1, rx1) = sync_channel::<i32>(0); + let (tx2, rx2): (Sender<i32>, Receiver<i32>) = channel(); let _t = thread::spawn(move|| { tx1.send(1).unwrap(); }); let _t = thread::spawn(move|| { tx2.send(2).unwrap(); }); select! { diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index 729e7991f97..8d14824d37f 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -101,7 +101,7 @@ impl<T: Send> Packet<T> { token.map(|token| { 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.to_wake.store(unsafe { token.cast_to_usize() }, Ordering::SeqCst); self.cnt.store(-1, Ordering::SeqCst); // This store is a little sketchy. What's happening here is that @@ -241,7 +241,7 @@ impl<T: Send> Packet<T> { // Returns true if blocking should proceed. fn decrement(&mut self, token: SignalToken) -> StartResult { assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); - let ptr = unsafe { token.cast_to_uint() }; + let ptr = unsafe { token.cast_to_usize() }; self.to_wake.store(ptr, Ordering::SeqCst); let steals = self.steals; @@ -258,7 +258,7 @@ impl<T: Send> Packet<T> { } self.to_wake.store(0, Ordering::SeqCst); - drop(unsafe { SignalToken::cast_from_uint(ptr) }); + drop(unsafe { SignalToken::cast_from_usize(ptr) }); Abort } @@ -380,7 +380,7 @@ impl<T: Send> Packet<T> { let ptr = self.to_wake.load(Ordering::SeqCst); self.to_wake.store(0, Ordering::SeqCst); assert!(ptr != 0); - unsafe { SignalToken::cast_from_uint(ptr) } + unsafe { SignalToken::cast_from_usize(ptr) } } //////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 7b5c614536d..ce40fa2672a 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -69,7 +69,7 @@ pub struct Queue<T> { // Cache maintenance fields. Additions and subtractions are stored // separately in order to allow them to use nonatomic addition/subtraction. - cache_bound: uint, + cache_bound: usize, cache_additions: AtomicUsize, cache_subtractions: AtomicUsize, } @@ -107,7 +107,7 @@ impl<T: Send> Queue<T> { /// cache (if desired). If the value is 0, then the cache has /// no bound. Otherwise, the cache will never grow larger than /// `bound` (although the queue itself could be much larger. - pub unsafe fn new(bound: uint) -> Queue<T> { + pub unsafe fn new(bound: usize) -> Queue<T> { let n1 = Node::new(); let n2 = Node::new(); (*n1).next.store(n2, Ordering::Relaxed); @@ -319,7 +319,7 @@ mod test { stress_bound(1); } - unsafe fn stress_bound(bound: uint) { + unsafe fn stress_bound(bound: usize) { let q = Arc::new(Queue::new(bound)); let (tx, rx) = channel(); diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index 2d528662f64..5a1e05f9c15 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -43,7 +43,7 @@ pub struct Packet<T> { queue: spsc::Queue<Message<T>>, // internal queue for all message cnt: AtomicIsize, // How many items are on this channel - steals: int, // How many times has a port received without blocking? + steals: isize, // How many times has a port received without blocking? to_wake: AtomicUsize, // SignalToken for the blocked thread to wake up port_dropped: AtomicBool, // flag if the channel has been destroyed. @@ -146,7 +146,7 @@ impl<T: Send> Packet<T> { let ptr = self.to_wake.load(Ordering::SeqCst); self.to_wake.store(0, Ordering::SeqCst); assert!(ptr != 0); - unsafe { SignalToken::cast_from_uint(ptr) } + unsafe { SignalToken::cast_from_usize(ptr) } } // Decrements the count on the channel for a sleeper, returning the sleeper @@ -154,7 +154,7 @@ impl<T: Send> Packet<T> { // steals into account. fn decrement(&mut self, token: SignalToken) -> Result<(), SignalToken> { assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); - let ptr = unsafe { token.cast_to_uint() }; + let ptr = unsafe { token.cast_to_usize() }; self.to_wake.store(ptr, Ordering::SeqCst); let steals = self.steals; @@ -171,7 +171,7 @@ impl<T: Send> Packet<T> { } self.to_wake.store(0, Ordering::SeqCst); - Err(unsafe { SignalToken::cast_from_uint(ptr) }) + Err(unsafe { SignalToken::cast_from_usize(ptr) }) } pub fn recv(&mut self) -> Result<T, Failure<T>> { @@ -350,7 +350,7 @@ impl<T: Send> Packet<T> { } // increment the count on the channel (used for selection) - fn bump(&mut self, amt: int) -> int { + fn bump(&mut self, amt: isize) -> isize { match self.cnt.fetch_add(amt, Ordering::SeqCst) { DISCONNECTED => { self.cnt.store(DISCONNECTED, Ordering::SeqCst); diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 36b50b0d4af..33c1614e1b2 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -64,7 +64,7 @@ struct State<T> { queue: Queue, // queue of senders waiting to send data blocker: Blocker, // currently blocked task on this channel buf: Buffer<T>, // storage for buffered messages - cap: uint, // capacity of this channel + cap: usize, // capacity of this channel /// A curious flag used to indicate whether a sender failed or succeeded in /// blocking. This is used to transmit information back to the task that it @@ -101,8 +101,8 @@ unsafe impl Send for Node {} /// A simple ring-buffer struct Buffer<T> { buf: Vec<Option<T>>, - start: uint, - size: uint, + start: usize, + size: usize, } #[derive(Debug)] @@ -137,7 +137,7 @@ fn wakeup<T>(token: SignalToken, guard: MutexGuard<State<T>>) { } impl<T: Send> Packet<T> { - pub fn new(cap: uint) -> Packet<T> { + pub fn new(cap: usize) -> Packet<T> { Packet { channels: AtomicUsize::new(1), lock: Mutex::new(State { @@ -442,8 +442,8 @@ impl<T> Buffer<T> { result.take().unwrap() } - fn size(&self) -> uint { self.size } - fn cap(&self) -> uint { self.buf.len() } + fn size(&self) -> usize { self.size } + fn cap(&self) -> usize { self.buf.len() } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index b71cc0c2653..02b2db572ec 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -50,7 +50,7 @@ use sys_common::mutex as sys; /// use std::thread; /// use std::sync::mpsc::channel; /// -/// const N: uint = 10; +/// const N: usize = 10; /// /// // Spawn a few threads to increment a shared variable (non-atomically), and /// // let the main thread know once all increments are done. @@ -377,9 +377,9 @@ mod test { #[test] fn lots_and_lots() { static M: StaticMutex = MUTEX_INIT; - static mut CNT: uint = 0; - static J: uint = 1000; - static K: uint = 3; + static mut CNT: u32 = 0; + static J: u32 = 1000; + static K: u32 = 3; fn inc() { for _ in 0..J { @@ -501,7 +501,7 @@ mod test { let arc2 = arc.clone(); let _ = thread::spawn(move|| -> () { struct Unwinder { - i: Arc<Mutex<int>>, + i: Arc<Mutex<i32>>, } impl Drop for Unwinder { fn drop(&mut self) { diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index a45048be24c..31f3dfd877c 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -89,7 +89,7 @@ impl TaskPool { /// # Panics /// /// This function will panic if `threads` is 0. - pub fn new(threads: uint) -> TaskPool { + pub fn new(threads: usize) -> TaskPool { assert!(threads >= 1); let (tx, rx) = channel::<Thunk>(); @@ -142,7 +142,7 @@ mod test { use super::*; use sync::mpsc::channel; - const TEST_TASKS: uint = 4; + const TEST_TASKS: usize = 4; #[test] fn test_works() { diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index 92a47c6c385..c6b9c2cba52 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -18,7 +18,7 @@ use libc::{self, c_int, c_void, size_t, off_t, c_char, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; -use rc::Rc; +use sync::Arc; use sys::fd::FileDesc; use sys::{c, cvt, cvt_r}; use sys_common::FromInner; @@ -31,14 +31,18 @@ pub struct FileAttr { } pub struct ReadDir { - dirp: *mut libc::DIR, - root: Rc<PathBuf>, + dirp: Dir, + root: Arc<PathBuf>, } +struct Dir(*mut libc::DIR); + +unsafe impl Send for Dir {} +unsafe impl Sync for Dir {} + pub struct DirEntry { - buf: Vec<u8>, - dirent: *mut libc::dirent_t, - root: Rc<PathBuf>, + buf: Vec<u8>, // actually *mut libc::dirent_t + root: Arc<PathBuf>, } #[derive(Clone)] @@ -109,7 +113,7 @@ impl Iterator for ReadDir { let mut entry_ptr = ptr::null_mut(); loop { - if unsafe { libc::readdir_r(self.dirp, ptr, &mut entry_ptr) != 0 } { + if unsafe { libc::readdir_r(self.dirp.0, ptr, &mut entry_ptr) != 0 } { return Some(Err(Error::last_os_error())) } if entry_ptr.is_null() { @@ -118,7 +122,6 @@ impl Iterator for ReadDir { let entry = DirEntry { buf: buf, - dirent: entry_ptr, root: self.root.clone() }; if entry.name_bytes() == b"." || entry.name_bytes() == b".." { @@ -130,9 +133,9 @@ impl Iterator for ReadDir { } } -impl Drop for ReadDir { +impl Drop for Dir { fn drop(&mut self) { - let r = unsafe { libc::closedir(self.dirp) }; + let r = unsafe { libc::closedir(self.0) }; debug_assert_eq!(r, 0); } } @@ -147,9 +150,13 @@ impl DirEntry { fn rust_list_dir_val(ptr: *mut libc::dirent_t) -> *const c_char; } unsafe { - CStr::from_ptr(rust_list_dir_val(self.dirent)).to_bytes() + CStr::from_ptr(rust_list_dir_val(self.dirent())).to_bytes() } } + + fn dirent(&self) -> *mut libc::dirent_t { + self.buf.as_ptr() as *mut _ + } } impl OpenOptions { @@ -279,14 +286,14 @@ pub fn mkdir(p: &Path) -> io::Result<()> { } pub fn readdir(p: &Path) -> io::Result<ReadDir> { - let root = Rc::new(p.to_path_buf()); + let root = Arc::new(p.to_path_buf()); let p = try!(cstr(p)); unsafe { let ptr = libc::opendir(p.as_ptr()); if ptr.is_null() { Err(Error::last_os_error()) } else { - Ok(ReadDir { dirp: ptr, root: root }) + Ok(ReadDir { dirp: Dir(ptr), root: root }) } } } diff --git a/src/libstd/sys/windows/fs2.rs b/src/libstd/sys/windows/fs2.rs index 8abcd90efe8..117f819eeeb 100644 --- a/src/libstd/sys/windows/fs2.rs +++ b/src/libstd/sys/windows/fs2.rs @@ -19,6 +19,7 @@ use libc::{self, HANDLE}; use mem; use path::{Path, PathBuf}; use ptr; +use sync::Arc; use sys::handle::Handle as RawHandle; use sys::{c, cvt}; use vec::Vec; @@ -27,12 +28,20 @@ pub struct File { handle: RawHandle } pub struct FileAttr { data: c::WIN32_FILE_ATTRIBUTE_DATA } pub struct ReadDir { - handle: libc::HANDLE, - root: PathBuf, + handle: FindNextFileHandle, + root: Arc<PathBuf>, first: Option<libc::WIN32_FIND_DATAW>, } -pub struct DirEntry { path: PathBuf } +struct FindNextFileHandle(libc::HANDLE); + +unsafe impl Send for FindNextFileHandle {} +unsafe impl Sync for FindNextFileHandle {} + +pub struct DirEntry { + root: Arc<PathBuf>, + data: libc::WIN32_FIND_DATAW, +} #[derive(Clone, Default)] pub struct OpenOptions { @@ -61,7 +70,7 @@ impl Iterator for ReadDir { unsafe { let mut wfd = mem::zeroed(); loop { - if libc::FindNextFileW(self.handle, &mut wfd) == 0 { + if libc::FindNextFileW(self.handle.0, &mut wfd) == 0 { if libc::GetLastError() == c::ERROR_NO_MORE_FILES as libc::DWORD { return None @@ -77,15 +86,15 @@ impl Iterator for ReadDir { } } -impl Drop for ReadDir { +impl Drop for FindNextFileHandle { fn drop(&mut self) { - let r = unsafe { libc::FindClose(self.handle) }; + let r = unsafe { libc::FindClose(self.0) }; debug_assert!(r != 0); } } impl DirEntry { - fn new(root: &Path, wfd: &libc::WIN32_FIND_DATAW) -> Option<DirEntry> { + fn new(root: &Arc<PathBuf>, wfd: &libc::WIN32_FIND_DATAW) -> Option<DirEntry> { match &wfd.cFileName[0..3] { // check for '.' and '..' [46, 0, ..] | @@ -93,13 +102,15 @@ impl DirEntry { _ => {} } - let filename = super::truncate_utf16_at_nul(&wfd.cFileName); - let filename: OsString = OsStringExt::from_wide(filename); - Some(DirEntry { path: root.join(&filename) }) + Some(DirEntry { + root: root.clone(), + data: *wfd, + }) } pub fn path(&self) -> PathBuf { - self.path.clone() + let filename = super::truncate_utf16_at_nul(&self.data.cFileName); + self.root.join(&<OsString as OsStringExt>::from_wide(filename)) } } @@ -312,7 +323,11 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> { let mut wfd = mem::zeroed(); let find_handle = libc::FindFirstFileW(path.as_ptr(), &mut wfd); if find_handle != libc::INVALID_HANDLE_VALUE { - Ok(ReadDir { handle: find_handle, root: root, first: Some(wfd) }) + Ok(ReadDir { + handle: FindNextFileHandle(find_handle), + root: Arc::new(root), + first: Some(wfd), + }) } else { Err(Error::last_os_error()) } diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 1f70e1526a0..6aad2bbcc7f 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -342,12 +342,15 @@ impl Builder { } } -/// Spawn a new, returning a join handle for it. +/// Spawn a new thread, returning a `JoinHandle` for it. /// -/// The child thread may outlive the parent (unless the parent thread -/// is the main thread; the whole process is terminated when the main -/// thread finishes.) The join handle can be used to block on -/// termination of the child thread, including recovering its panics. +/// The join handle will implicitly *detach* the child thread upon being +/// dropped. In this case, the child thread may outlive the parent (unless +/// the parent thread is the main thread; the whole process is terminated when +/// the main thread finishes.) Additionally, the join handle provides a `join` +/// method that can be used to join the child thread. If the child thread +/// panics, `join` will return an `Err` containing the argument given to +/// `panic`. /// /// # Panics /// diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index cdd71d440fe..d65156dae96 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -74,7 +74,7 @@ pub mod __impl { /// use std::cell::RefCell; /// use std::thread; /// -/// thread_local!(static FOO: RefCell<uint> = RefCell::new(1)); +/// thread_local!(static FOO: RefCell<u32> = RefCell::new(1)); /// /// FOO.with(|f| { /// assert_eq!(*f.borrow(), 1); @@ -503,7 +503,7 @@ mod imp { unsafe fn ptr(&'static self) -> Option<*mut T> { let ptr = self.os.get() as *mut Value<T>; if !ptr.is_null() { - if ptr as uint == 1 { + if ptr as usize == 1 { return None } return Some(&mut (*ptr).value as *mut T); @@ -563,7 +563,7 @@ mod tests { #[test] fn smoke_no_dtor() { - thread_local!(static FOO: UnsafeCell<int> = UnsafeCell { value: 1 }); + thread_local!(static FOO: UnsafeCell<i32> = UnsafeCell { value: 1 }); FOO.with(|f| unsafe { assert_eq!(*f.get(), 1); @@ -632,7 +632,7 @@ mod tests { thread_local!(static K2: UnsafeCell<Option<S2>> = UnsafeCell { value: None }); - static mut HITS: uint = 0; + static mut HITS: u32 = 0; impl Drop for S1 { fn drop(&mut self) { @@ -723,8 +723,8 @@ mod dynamic_tests { #[test] fn smoke() { - fn square(i: int) -> int { i * i } - thread_local!(static FOO: int = square(3)); + fn square(i: i32) -> i32 { i * i } + thread_local!(static FOO: i32 = square(3)); FOO.with(|f| { assert_eq!(*f, 9); @@ -733,12 +733,12 @@ mod dynamic_tests { #[test] fn hashmap() { - fn map() -> RefCell<HashMap<int, int>> { + fn map() -> RefCell<HashMap<i32, i32>> { let mut m = HashMap::new(); m.insert(1, 2); RefCell::new(m) } - thread_local!(static FOO: RefCell<HashMap<int, int>> = map()); + thread_local!(static FOO: RefCell<HashMap<i32, i32>> = map()); FOO.with(|map| { assert_eq!(map.borrow()[1], 2); @@ -747,7 +747,7 @@ mod dynamic_tests { #[test] fn refcell_vec() { - thread_local!(static FOO: RefCell<Vec<uint>> = RefCell::new(vec![1, 2, 3])); + thread_local!(static FOO: RefCell<Vec<u32>> = RefCell::new(vec![1, 2, 3])); FOO.with(|vec| { assert_eq!(vec.borrow().len(), 3); diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index 01220e7bc1f..a2a5d8b81f4 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -24,7 +24,7 @@ //! # Example //! //! ``` -//! scoped_thread_local!(static FOO: uint); +//! scoped_thread_local!(static FOO: u32); //! //! // Initially each scoped slot is empty. //! assert!(!FOO.is_set()); @@ -140,7 +140,7 @@ impl<T> Key<T> { /// # Example /// /// ``` - /// scoped_thread_local!(static FOO: uint); + /// scoped_thread_local!(static FOO: u32); /// /// FOO.set(&100, || { /// let val = FOO.with(|v| *v); @@ -192,7 +192,7 @@ impl<T> Key<T> { /// # Example /// /// ```no_run - /// scoped_thread_local!(static FOO: uint); + /// scoped_thread_local!(static FOO: u32); /// /// FOO.with(|slot| { /// // work with `slot` @@ -269,11 +269,11 @@ mod tests { use cell::Cell; use prelude::v1::*; - scoped_thread_local!(static FOO: uint); + scoped_thread_local!(static FOO: u32); #[test] fn smoke() { - scoped_thread_local!(static BAR: uint); + scoped_thread_local!(static BAR: u32); assert!(!BAR.is_set()); BAR.set(&1, || { @@ -287,7 +287,7 @@ mod tests { #[test] fn cell_allowed() { - scoped_thread_local!(static BAR: Cell<uint>); + scoped_thread_local!(static BAR: Cell<u32>); BAR.set(&Cell::new(1), || { BAR.with(|slot| { |
