Rollup merge of #22700 - nick29581:ints_hash, r=alexcrichton

fmt and hash are pretty straightforward I think. sync is a bit more complex. I thought one or two of the `isize`s ought to be `i32`s, but that would require a bunch of casting (the root cause being the lack of atomics other than isize/usize).

r? @alexcrichton
This commit is contained in:
Manish Goregaokar 2015-02-24 07:14:41 +05:30
commit 3ca5439009
22 changed files with 253 additions and 232 deletions

View File

@ -40,10 +40,10 @@ pub enum ExponentFormat {
pub enum SignificantDigits {
/// At most the given number of digits will be printed, truncating any
/// trailing zeroes.
DigMax(uint),
DigMax(usize),
/// Precisely the given number of digits will be printed.
DigExact(uint)
DigExact(usize)
}
/// How to emit the sign of a number.
@ -240,27 +240,27 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
// If reached left end of number, have to
// insert additional digit:
if i < 0
|| buf[i as uint] == b'-'
|| buf[i as uint] == b'+' {
for j in (i as uint + 1..end).rev() {
|| buf[i as usize] == b'-'
|| buf[i as usize] == b'+' {
for j in (i as usize + 1..end).rev() {
buf[j + 1] = buf[j];
}
buf[(i + 1) as uint] = value2ascii(1);
buf[(i + 1) as usize] = value2ascii(1);
end += 1;
break;
}
// Skip the '.'
if buf[i as uint] == b'.' { i -= 1; continue; }
if buf[i as usize] == b'.' { i -= 1; continue; }
// Either increment the digit,
// or set to 0 if max and carry the 1.
let current_digit = ascii2value(buf[i as uint]);
let current_digit = ascii2value(buf[i as usize]);
if current_digit < (radix - 1) {
buf[i as uint] = value2ascii(current_digit+1);
buf[i as usize] = value2ascii(current_digit+1);
break;
} else {
buf[i as uint] = value2ascii(0);
buf[i as usize] = value2ascii(0);
i -= 1;
}
}
@ -311,7 +311,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
struct Filler<'a> {
buf: &'a mut [u8],
end: &'a mut uint,
end: &'a mut usize,
}
impl<'a> fmt::Write for Filler<'a> {

View File

@ -110,11 +110,14 @@ pub trait Write {
/// traits.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Formatter<'a> {
flags: uint,
#[cfg(not(stage0))]
flags: u32,
#[cfg(stage0)]
flags: usize,
fill: char,
align: rt::v1::Alignment,
width: Option<uint>,
precision: Option<uint>,
width: Option<usize>,
precision: Option<usize>,
buf: &'a mut (Write+'a),
curarg: slice::Iter<'a, ArgumentV1<'a>>,
@ -140,7 +143,7 @@ pub struct ArgumentV1<'a> {
impl<'a> ArgumentV1<'a> {
#[inline(never)]
fn show_uint(x: &uint, f: &mut Formatter) -> Result {
fn show_usize(x: &usize, f: &mut Formatter) -> Result {
Display::fmt(x, f)
}
@ -156,15 +159,22 @@ impl<'a> ArgumentV1<'a> {
}
}
#[cfg(stage0)]
#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_uint(x: &uint) -> ArgumentV1 {
ArgumentV1::new(x, ArgumentV1::show_uint)
ArgumentV1::new(x, ArgumentV1::show_usize)
}
#[cfg(not(stage0))]
#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_usize(x: &usize) -> ArgumentV1 {
ArgumentV1::new(x, ArgumentV1::show_usize)
}
fn as_uint(&self) -> Option<uint> {
if self.formatter as uint == ArgumentV1::show_uint as uint {
Some(unsafe { *(self.value as *const _ as *const uint) })
fn as_usize(&self) -> Option<usize> {
if self.formatter as usize == ArgumentV1::show_usize as usize {
Some(unsafe { *(self.value as *const _ as *const usize) })
} else {
None
}
@ -194,7 +204,7 @@ impl<'a> Arguments<'a> {
/// The `pieces` array must be at least as long as `fmt` to construct
/// a valid Arguments structure. Also, any `Count` within `fmt` that is
/// `CountIsParam` or `CountIsNextParam` has to point to an argument
/// created with `argumentuint`. However, failing to do so doesn't cause
/// created with `argumentusize`. However, failing to do so doesn't cause
/// unsafety, but will ignore invalid .
#[doc(hidden)] #[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -402,15 +412,15 @@ impl<'a> Formatter<'a> {
(value.formatter)(value.value, self)
}
fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<uint> {
fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
match *cnt {
rt::v1::Count::Is(n) => Some(n),
rt::v1::Count::Implied => None,
rt::v1::Count::Param(i) => {
self.args[i].as_uint()
self.args[i].as_usize()
}
rt::v1::Count::NextParam => {
self.curarg.next().and_then(|arg| arg.as_uint())
self.curarg.next().and_then(|arg| arg.as_usize())
}
}
}
@ -444,12 +454,12 @@ impl<'a> Formatter<'a> {
let mut sign = None;
if !is_positive {
sign = Some('-'); width += 1;
} else if self.flags & (1 << (FlagV1::SignPlus as uint)) != 0 {
} else if self.flags & (1 << (FlagV1::SignPlus as u32)) != 0 {
sign = Some('+'); width += 1;
}
let mut prefixed = false;
if self.flags & (1 << (FlagV1::Alternate as uint)) != 0 {
if self.flags & (1 << (FlagV1::Alternate as u32)) != 0 {
prefixed = true; width += prefix.char_len();
}
@ -479,7 +489,7 @@ impl<'a> Formatter<'a> {
}
// The sign and prefix goes before the padding if the fill character
// is zero
Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as uint)) != 0 => {
Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as u32)) != 0 => {
self.fill = '0';
try!(write_prefix(self));
self.with_padding(min - width, Alignment::Right, |f| {
@ -549,7 +559,7 @@ impl<'a> Formatter<'a> {
/// Runs a callback, emitting the correct padding either before or
/// afterwards depending on whether right or left alignment is requested.
fn with_padding<F>(&mut self, padding: uint, default: Alignment,
fn with_padding<F>(&mut self, padding: usize, default: Alignment,
f: F) -> Result
where F: FnOnce(&mut Formatter) -> Result,
{
@ -595,6 +605,11 @@ impl<'a> Formatter<'a> {
write(self.buf, fmt)
}
#[cfg(not(stage0))]
/// Flags for formatting (packed version of rt::Flag)
#[stable(feature = "rust1", since = "1.0.0")]
pub fn flags(&self) -> u32 { self.flags }
#[cfg(stage0)]
/// Flags for formatting (packed version of rt::Flag)
#[stable(feature = "rust1", since = "1.0.0")]
pub fn flags(&self) -> usize { self.flags }
@ -609,11 +624,11 @@ impl<'a> Formatter<'a> {
/// Optionally specified integer width that the output should be
#[unstable(feature = "core", reason = "method was just created")]
pub fn width(&self) -> Option<uint> { self.width }
pub fn width(&self) -> Option<usize> { self.width }
/// Optionally specified precision for numeric types
#[unstable(feature = "core", reason = "method was just created")]
pub fn precision(&self) -> Option<uint> { self.precision }
pub fn precision(&self) -> Option<usize> { self.precision }
}
#[stable(feature = "rust1", since = "1.0.0")]
@ -699,9 +714,9 @@ impl Display for char {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Pointer for *const T {
fn fmt(&self, f: &mut Formatter) -> Result {
f.flags |= 1 << (FlagV1::Alternate as uint);
let ret = LowerHex::fmt(&(*self as uint), f);
f.flags &= !(1 << (FlagV1::Alternate as uint));
f.flags |= 1 << (FlagV1::Alternate as u32);
let ret = LowerHex::fmt(&(*self as u32), f);
f.flags &= !(1 << (FlagV1::Alternate as u32));
ret
}
}
@ -857,7 +872,7 @@ impl<'a> Debug for &'a (any::Any+'a) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for [T] {
fn fmt(&self, f: &mut Formatter) -> Result {
if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 {
if f.flags & (1 << (FlagV1::Alternate as u32)) == 0 {
try!(write!(f, "["));
}
let mut is_first = true;
@ -869,7 +884,7 @@ impl<T: Debug> Debug for [T] {
}
try!(write!(f, "{:?}", *x))
}
if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 {
if f.flags & (1 << (FlagV1::Alternate as u32)) == 0 {
try!(write!(f, "]"));
}
Ok(())

View File

@ -214,7 +214,7 @@ macro_rules! integer {
show! { $Uint with $SU }
}
}
integer! { int, uint, "i", "u" }
integer! { isize, usize, "i", "u" }
integer! { i8, u8 }
integer! { i16, u16 }
integer! { i32, u32 }

View File

@ -32,8 +32,12 @@ pub struct FormatSpec {
pub fill: char,
#[stable(feature = "rust1", since = "1.0.0")]
pub align: Alignment,
#[cfg(stage0)]
#[stable(feature = "rust1", since = "1.0.0")]
pub flags: uint,
pub flags: usize,
#[cfg(not(stage0))]
#[stable(feature = "rust1", since = "1.0.0")]
pub flags: u32,
#[stable(feature = "rust1", since = "1.0.0")]
pub precision: Count,
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -20,7 +20,7 @@
//!
//! #[derive(Hash)]
//! struct Person {
//! id: uint,
//! id: u32,
//! name: String,
//! phone: u64,
//! }
@ -38,7 +38,7 @@
//! use std::hash::{hash, Hash, Hasher, SipHasher};
//!
//! struct Person {
//! id: uint,
//! id: u32,
//! name: String,
//! phone: u64,
//! }

View File

@ -34,13 +34,13 @@ use super::Hasher;
pub struct SipHasher {
k0: u64,
k1: u64,
length: uint, // how many bytes we've processed
length: usize, // how many bytes we've processed
v0: u64, // hash state
v1: u64,
v2: u64,
v3: u64,
tail: u64, // unprocessed bytes le
ntail: uint, // how many bytes in tail are valid
ntail: usize, // how many bytes in tail are valid
}
// sadly, these macro definitions can't appear later,

View File

@ -24,7 +24,6 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(int_uint)]
#![feature(staged_api)]
#![feature(unicode)]
@ -65,7 +64,7 @@ pub struct FormatSpec<'a> {
/// Optionally specified alignment
pub align: Alignment,
/// Packed version of various flags provided
pub flags: uint,
pub flags: u32,
/// The integer precision to use
pub precision: Count<'a>,
/// The string width requested for the resulting format
@ -82,7 +81,7 @@ pub enum Position<'a> {
/// The argument will be in the next position. This is the default.
ArgumentNext,
/// The argument is located at a specific index.
ArgumentIs(uint),
ArgumentIs(usize),
/// The argument has a name.
ArgumentNamed(&'a str),
}
@ -121,11 +120,11 @@ pub enum Flag {
#[derive(Copy, PartialEq)]
pub enum Count<'a> {
/// The count is specified explicitly.
CountIs(uint),
CountIs(usize),
/// The count is specified by the argument with the given name.
CountIsName(&'a str),
/// The count is specified by the argument at the given index.
CountIsParam(uint),
CountIsParam(usize),
/// The count is specified by the next parameter.
CountIsNextParam,
/// The count is implied and cannot be explicitly specified.
@ -237,7 +236,7 @@ impl<'a> Parser<'a> {
/// Parses all of a string which is to be considered a "raw literal" in a
/// format string. This is everything outside of the braces.
fn string(&mut self, start: uint) -> &'a str {
fn string(&mut self, start: usize) -> &'a str {
loop {
// we may not consume the character, so clone the iterator
match self.cur.clone().next() {
@ -314,13 +313,13 @@ impl<'a> Parser<'a> {
}
// Sign flags
if self.consume('+') {
spec.flags |= 1 << (FlagSignPlus as uint);
spec.flags |= 1 << (FlagSignPlus as u32);
} else if self.consume('-') {
spec.flags |= 1 << (FlagSignMinus as uint);
spec.flags |= 1 << (FlagSignMinus as u32);
}
// Alternate marker
if self.consume('#') {
spec.flags |= 1 << (FlagAlternate as uint);
spec.flags |= 1 << (FlagAlternate as u32);
}
// Width and precision
let mut havewidth = false;
@ -333,7 +332,7 @@ impl<'a> Parser<'a> {
spec.width = CountIsParam(0);
havewidth = true;
} else {
spec.flags |= 1 << (FlagSignAwareZeroPad as uint);
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
}
}
if !havewidth {
@ -413,7 +412,7 @@ impl<'a> Parser<'a> {
/// Optionally parses an integer at the current position. This doesn't deal
/// with overflow at all, it's just accumulating digits.
fn integer(&mut self) -> Option<uint> {
fn integer(&mut self) -> Option<usize> {
let mut cur = 0;
let mut found = false;
loop {
@ -617,7 +616,7 @@ mod tests {
format: FormatSpec {
fill: None,
align: AlignUnknown,
flags: (1 << FlagSignMinus as uint),
flags: (1 << FlagSignMinus as u32),
precision: CountImplied,
width: CountImplied,
ty: "",
@ -628,7 +627,7 @@ mod tests {
format: FormatSpec {
fill: None,
align: AlignUnknown,
flags: (1 << FlagSignPlus as uint) | (1 << FlagAlternate as uint),
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
precision: CountImplied,
width: CountImplied,
ty: "",

View File

@ -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();

View File

@ -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();

View File

@ -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) }
}

View File

@ -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)));

View File

@ -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)
}
}

View File

@ -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: u32 = 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! {

View File

@ -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) }
}
////////////////////////////////////////////////////////////////////////////

View File

@ -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();

View File

@ -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);

View File

@ -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() }
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -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) {

View File

@ -425,8 +425,8 @@ mod tests {
#[test]
fn frob() {
static R: StaticRwLock = RW_LOCK_INIT;
static N: usize = 10;
static M: usize = 1000;
static N: u32 = 10;
static M: u32 = 1000;
let (tx, rx) = channel::<()>();
for _ in 0..N {

View File

@ -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: u32 = 4;
#[test]
fn test_works() {

View File

@ -702,6 +702,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false),
ast::Sign::new(i))))
}
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32)))
}
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))
}

View File

@ -417,7 +417,7 @@ impl<'a, 'b> Context<'a, 'b> {
parse::AlignUnknown => align("Unknown"),
};
let align = self.ecx.expr_path(align);
let flags = self.ecx.expr_usize(sp, arg.format.flags);
let flags = self.ecx.expr_u32(sp, arg.format.flags);
let prec = self.trans_count(arg.format.precision);
let width = self.trans_count(arg.format.width);
let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, "FormatSpec"));
@ -610,7 +610,7 @@ impl<'a, 'b> Context<'a, 'b> {
ecx.ident_of_std("core"),
ecx.ident_of("fmt"),
ecx.ident_of("ArgumentV1"),
ecx.ident_of("from_uint")], vec![arg])
ecx.ident_of("from_usize")], vec![arg])
}
};