mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 12:06:47 +00:00
Test fixes and rebase conflicts
This commit is contained in:
parent
0a6b9219d1
commit
e633249b31
@ -242,13 +242,13 @@ use clone::Clone;
|
||||
use iter::Iterator;
|
||||
use kinds::Send;
|
||||
use kinds::marker;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Some, None, Option};
|
||||
use result::{Ok, Err, Result};
|
||||
use rt::local::Local;
|
||||
use rt::task::{Task, BlockedTask};
|
||||
use sync::arc::UnsafeArc;
|
||||
use util;
|
||||
|
||||
pub use comm::select::{Select, Handle};
|
||||
|
||||
@ -427,7 +427,7 @@ impl<T: Send> Chan<T> {
|
||||
|
||||
unsafe {
|
||||
let mut tmp = Chan::my_new(Stream(new_inner));
|
||||
util::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -460,7 +460,7 @@ impl<T: Send> Clone for Chan<T> {
|
||||
(*packet.get()).inherit_blocker(sleeper);
|
||||
|
||||
let mut tmp = Chan::my_new(Shared(packet.clone()));
|
||||
util::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
|
||||
}
|
||||
Chan::my_new(Shared(packet))
|
||||
}
|
||||
@ -556,8 +556,8 @@ impl<T: Send> Port<T> {
|
||||
}
|
||||
};
|
||||
unsafe {
|
||||
util::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -602,8 +602,8 @@ impl<T: Send> Port<T> {
|
||||
}
|
||||
};
|
||||
unsafe {
|
||||
util::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -636,8 +636,8 @@ impl<T: Send> select::Packet for Port<T> {
|
||||
}
|
||||
};
|
||||
unsafe {
|
||||
util::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -665,8 +665,8 @@ impl<T: Send> select::Packet for Port<T> {
|
||||
};
|
||||
task = t;
|
||||
unsafe {
|
||||
util::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -686,8 +686,8 @@ impl<T: Send> select::Packet for Port<T> {
|
||||
let mut new_port = match result { Ok(b) => return b, Err(p) => p };
|
||||
was_upgrade = true;
|
||||
unsafe {
|
||||
util::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
mem::swap(&mut cast::transmute_mut(self).inner,
|
||||
&mut new_port.inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +34,13 @@
|
||||
|
||||
use comm::Port;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Some, None, Option};
|
||||
use result::{Result, Ok, Err};
|
||||
use rt::local::Local;
|
||||
use rt::task::{Task, BlockedTask};
|
||||
use sync::atomics;
|
||||
use util;
|
||||
|
||||
// Various states you can find a port in.
|
||||
static EMPTY: uint = 0;
|
||||
@ -100,10 +100,7 @@ impl<T: Send> Packet<T> {
|
||||
self.data = Some(t);
|
||||
self.upgrade = SendUsed;
|
||||
|
||||
// This atomic swap uses a "Release" memory ordering to ensure that all
|
||||
// our previous memory writes are visible to the other thread (notably
|
||||
// the write of data/upgrade)
|
||||
match self.state.swap(DATA, atomics::Release) {
|
||||
match self.state.swap(DATA, atomics::SeqCst) {
|
||||
// Sent the data, no one was waiting
|
||||
EMPTY => true,
|
||||
|
||||
@ -141,14 +138,11 @@ impl<T: Send> Packet<T> {
|
||||
pub fn recv(&mut self) -> Result<T, Failure<T>> {
|
||||
// Attempt to not block the task (it's a little expensive). If it looks
|
||||
// like we're not empty, then immediately go through to `try_recv`.
|
||||
//
|
||||
// These atomics use an Acquire memory ordering in order to have all the
|
||||
// previous writes of the releasing thread visible to us.
|
||||
if self.state.load(atomics::Acquire) == EMPTY {
|
||||
if self.state.load(atomics::SeqCst) == EMPTY {
|
||||
let t: ~Task = Local::take();
|
||||
t.deschedule(1, |task| {
|
||||
let n = unsafe { task.cast_to_uint() };
|
||||
match self.state.compare_and_swap(EMPTY, n, atomics::Acquire) {
|
||||
match self.state.compare_and_swap(EMPTY, n, atomics::SeqCst) {
|
||||
// Nothing on the channel, we legitimately block
|
||||
EMPTY => Ok(()),
|
||||
|
||||
@ -168,8 +162,7 @@ impl<T: Send> Packet<T> {
|
||||
}
|
||||
|
||||
pub fn try_recv(&mut self) -> Result<T, Failure<T>> {
|
||||
// see above for why Acquire is used.
|
||||
match self.state.load(atomics::Acquire) {
|
||||
match self.state.load(atomics::SeqCst) {
|
||||
EMPTY => Err(Empty),
|
||||
|
||||
// We saw some data on the channel, but the channel can be used
|
||||
@ -179,7 +172,7 @@ impl<T: Send> Packet<T> {
|
||||
// the state changes under our feet we'd rather just see that state
|
||||
// change.
|
||||
DATA => {
|
||||
self.state.compare_and_swap(DATA, EMPTY, atomics::Acquire);
|
||||
self.state.compare_and_swap(DATA, EMPTY, atomics::SeqCst);
|
||||
match self.data.take() {
|
||||
Some(data) => Ok(data),
|
||||
None => unreachable!(),
|
||||
@ -194,7 +187,7 @@ impl<T: Send> Packet<T> {
|
||||
match self.data.take() {
|
||||
Some(data) => Ok(data),
|
||||
None => {
|
||||
match util::replace(&mut self.upgrade, SendUsed) {
|
||||
match mem::replace(&mut self.upgrade, SendUsed) {
|
||||
SendUsed | NothingSent => Err(Disconnected),
|
||||
GoUp(upgrade) => Err(Upgraded(upgrade))
|
||||
}
|
||||
@ -216,9 +209,7 @@ impl<T: Send> Packet<T> {
|
||||
};
|
||||
self.upgrade = GoUp(up);
|
||||
|
||||
// Use a Release memory ordering in order to make sure that our write to
|
||||
// `upgrade` is visible to the other thread.
|
||||
match self.state.swap(DISCONNECTED, atomics::Release) {
|
||||
match self.state.swap(DISCONNECTED, atomics::SeqCst) {
|
||||
// If the channel is empty or has data on it, then we're good to go.
|
||||
// Senders will check the data before the upgrade (in case we
|
||||
// plastered over the DATA state).
|
||||
@ -246,9 +237,7 @@ impl<T: Send> Packet<T> {
|
||||
}
|
||||
|
||||
pub fn drop_port(&mut self) {
|
||||
// Use an Acquire memory ordering in order to see the data that the
|
||||
// senders are sending.
|
||||
match self.state.swap(DISCONNECTED, atomics::Acquire) {
|
||||
match self.state.swap(DISCONNECTED, atomics::SeqCst) {
|
||||
// An empty channel has nothing to do, and a remotely disconnected
|
||||
// channel also has nothing to do b/c we're about to run the drop
|
||||
// glue
|
||||
@ -271,13 +260,12 @@ impl<T: Send> Packet<T> {
|
||||
// If Ok, the value is whether this port has data, if Err, then the upgraded
|
||||
// port needs to be checked instead of this one.
|
||||
pub fn can_recv(&mut self) -> Result<bool, Port<T>> {
|
||||
// Use Acquire so we can see all previous memory writes
|
||||
match self.state.load(atomics::Acquire) {
|
||||
match self.state.load(atomics::SeqCst) {
|
||||
EMPTY => Ok(false), // Welp, we tried
|
||||
DATA => Ok(true), // we have some un-acquired data
|
||||
DISCONNECTED if self.data.is_some() => Ok(true), // we have data
|
||||
DISCONNECTED => {
|
||||
match util::replace(&mut self.upgrade, SendUsed) {
|
||||
match mem::replace(&mut self.upgrade, SendUsed) {
|
||||
// The other end sent us an upgrade, so we need to
|
||||
// propagate upwards whether the upgrade can receive
|
||||
// data
|
||||
@ -304,7 +292,7 @@ impl<T: Send> Packet<T> {
|
||||
SelCanceled(unsafe { BlockedTask::cast_from_uint(n) })
|
||||
}
|
||||
DISCONNECTED => {
|
||||
match util::replace(&mut self.upgrade, SendUsed) {
|
||||
match mem::replace(&mut self.upgrade, SendUsed) {
|
||||
// The other end sent us an upgrade, so we need to
|
||||
// propagate upwards whether the upgrade can receive
|
||||
// data
|
||||
@ -331,8 +319,7 @@ impl<T: Send> Packet<T> {
|
||||
//
|
||||
// The return value indicates whether there's data on this port.
|
||||
pub fn abort_selection(&mut self) -> Result<bool, Port<T>> {
|
||||
// use Acquire to make sure we see all previous memory writes
|
||||
let state = match self.state.load(atomics::Acquire) {
|
||||
let state = match self.state.load(atomics::SeqCst) {
|
||||
// Each of these states means that no further activity will happen
|
||||
// with regard to abortion selection
|
||||
s @ EMPTY |
|
||||
@ -357,7 +344,7 @@ impl<T: Send> Packet<T> {
|
||||
// aborted.
|
||||
DISCONNECTED => {
|
||||
assert!(self.data.is_none());
|
||||
match util::replace(&mut self.upgrade, SendUsed) {
|
||||
match mem::replace(&mut self.upgrade, SendUsed) {
|
||||
GoUp(port) => Err(port),
|
||||
_ => Ok(true),
|
||||
}
|
||||
|
@ -698,7 +698,7 @@ mod test {
|
||||
iotest!(fn tcp_clone_two_read() {
|
||||
let addr = next_test_ip6();
|
||||
let mut acceptor = TcpListener::bind(addr).listen();
|
||||
let (p, c) = SharedChan::new();
|
||||
let (p, c) = Chan::new();
|
||||
let c2 = c.clone();
|
||||
|
||||
spawn(proc() {
|
||||
|
@ -301,7 +301,7 @@ mod test {
|
||||
let addr2 = next_test_ip4();
|
||||
let mut sock1 = UdpSocket::bind(addr1).unwrap();
|
||||
let sock2 = UdpSocket::bind(addr2).unwrap();
|
||||
let (p, c) = SharedChan::new();
|
||||
let (p, c) = Chan::new();
|
||||
let c2 = c.clone();
|
||||
|
||||
spawn(proc() {
|
||||
@ -335,7 +335,7 @@ mod test {
|
||||
let mut sock1 = UdpSocket::bind(addr1).unwrap();
|
||||
let sock2 = UdpSocket::bind(addr2).unwrap();
|
||||
|
||||
let (p, c) = SharedChan::new();
|
||||
let (p, c) = Chan::new();
|
||||
let (serv_port, serv_chan) = Chan::new();
|
||||
|
||||
spawn(proc() {
|
||||
|
@ -270,7 +270,7 @@ mod tests {
|
||||
fn unix_clone_two_read() {
|
||||
let addr = next_test_unix();
|
||||
let mut acceptor = UnixListener::bind(&addr).listen();
|
||||
let (p, c) = SharedChan::new();
|
||||
let (p, c) = Chan::new();
|
||||
let c2 = c.clone();
|
||||
|
||||
spawn(proc() {
|
||||
|
Loading…
Reference in New Issue
Block a user