Skip to content

Commit e633249

Browse files
committed
Test fixes and rebase conflicts
1 parent 0a6b921 commit e633249

File tree

5 files changed

+31
-44
lines changed

5 files changed

+31
-44
lines changed

src/libstd/comm/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ use clone::Clone;
242242
use iter::Iterator;
243243
use kinds::Send;
244244
use kinds::marker;
245+
use mem;
245246
use ops::Drop;
246247
use option::{Some, None, Option};
247248
use result::{Ok, Err, Result};
248249
use rt::local::Local;
249250
use rt::task::{Task, BlockedTask};
250251
use sync::arc::UnsafeArc;
251-
use util;
252252

253253
pub use comm::select::{Select, Handle};
254254

@@ -427,7 +427,7 @@ impl<T: Send> Chan<T> {
427427

428428
unsafe {
429429
let mut tmp = Chan::my_new(Stream(new_inner));
430-
util::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
430+
mem::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
431431
}
432432
return ret;
433433
}
@@ -460,7 +460,7 @@ impl<T: Send> Clone for Chan<T> {
460460
(*packet.get()).inherit_blocker(sleeper);
461461

462462
let mut tmp = Chan::my_new(Shared(packet.clone()));
463-
util::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
463+
mem::swap(&mut cast::transmute_mut(self).inner, &mut tmp.inner);
464464
}
465465
Chan::my_new(Shared(packet))
466466
}
@@ -556,8 +556,8 @@ impl<T: Send> Port<T> {
556556
}
557557
};
558558
unsafe {
559-
util::swap(&mut cast::transmute_mut(self).inner,
560-
&mut new_port.inner);
559+
mem::swap(&mut cast::transmute_mut(self).inner,
560+
&mut new_port.inner);
561561
}
562562
}
563563
}
@@ -602,8 +602,8 @@ impl<T: Send> Port<T> {
602602
}
603603
};
604604
unsafe {
605-
util::swap(&mut cast::transmute_mut(self).inner,
606-
&mut new_port.inner);
605+
mem::swap(&mut cast::transmute_mut(self).inner,
606+
&mut new_port.inner);
607607
}
608608
}
609609
}
@@ -636,8 +636,8 @@ impl<T: Send> select::Packet for Port<T> {
636636
}
637637
};
638638
unsafe {
639-
util::swap(&mut cast::transmute_mut(self).inner,
640-
&mut new_port.inner);
639+
mem::swap(&mut cast::transmute_mut(self).inner,
640+
&mut new_port.inner);
641641
}
642642
}
643643
}
@@ -665,8 +665,8 @@ impl<T: Send> select::Packet for Port<T> {
665665
};
666666
task = t;
667667
unsafe {
668-
util::swap(&mut cast::transmute_mut(self).inner,
669-
&mut new_port.inner);
668+
mem::swap(&mut cast::transmute_mut(self).inner,
669+
&mut new_port.inner);
670670
}
671671
}
672672
}
@@ -686,8 +686,8 @@ impl<T: Send> select::Packet for Port<T> {
686686
let mut new_port = match result { Ok(b) => return b, Err(p) => p };
687687
was_upgrade = true;
688688
unsafe {
689-
util::swap(&mut cast::transmute_mut(self).inner,
690-
&mut new_port.inner);
689+
mem::swap(&mut cast::transmute_mut(self).inner,
690+
&mut new_port.inner);
691691
}
692692
}
693693
}

src/libstd/comm/oneshot.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
3535
use comm::Port;
3636
use kinds::Send;
37+
use mem;
3738
use ops::Drop;
3839
use option::{Some, None, Option};
3940
use result::{Result, Ok, Err};
4041
use rt::local::Local;
4142
use rt::task::{Task, BlockedTask};
4243
use sync::atomics;
43-
use util;
4444

4545
// Various states you can find a port in.
4646
static EMPTY: uint = 0;
@@ -100,10 +100,7 @@ impl<T: Send> Packet<T> {
100100
self.data = Some(t);
101101
self.upgrade = SendUsed;
102102

103-
// This atomic swap uses a "Release" memory ordering to ensure that all
104-
// our previous memory writes are visible to the other thread (notably
105-
// the write of data/upgrade)
106-
match self.state.swap(DATA, atomics::Release) {
103+
match self.state.swap(DATA, atomics::SeqCst) {
107104
// Sent the data, no one was waiting
108105
EMPTY => true,
109106

@@ -141,14 +138,11 @@ impl<T: Send> Packet<T> {
141138
pub fn recv(&mut self) -> Result<T, Failure<T>> {
142139
// Attempt to not block the task (it's a little expensive). If it looks
143140
// like we're not empty, then immediately go through to `try_recv`.
144-
//
145-
// These atomics use an Acquire memory ordering in order to have all the
146-
// previous writes of the releasing thread visible to us.
147-
if self.state.load(atomics::Acquire) == EMPTY {
141+
if self.state.load(atomics::SeqCst) == EMPTY {
148142
let t: ~Task = Local::take();
149143
t.deschedule(1, |task| {
150144
let n = unsafe { task.cast_to_uint() };
151-
match self.state.compare_and_swap(EMPTY, n, atomics::Acquire) {
145+
match self.state.compare_and_swap(EMPTY, n, atomics::SeqCst) {
152146
// Nothing on the channel, we legitimately block
153147
EMPTY => Ok(()),
154148

@@ -168,8 +162,7 @@ impl<T: Send> Packet<T> {
168162
}
169163

170164
pub fn try_recv(&mut self) -> Result<T, Failure<T>> {
171-
// see above for why Acquire is used.
172-
match self.state.load(atomics::Acquire) {
165+
match self.state.load(atomics::SeqCst) {
173166
EMPTY => Err(Empty),
174167

175168
// We saw some data on the channel, but the channel can be used
@@ -179,7 +172,7 @@ impl<T: Send> Packet<T> {
179172
// the state changes under our feet we'd rather just see that state
180173
// change.
181174
DATA => {
182-
self.state.compare_and_swap(DATA, EMPTY, atomics::Acquire);
175+
self.state.compare_and_swap(DATA, EMPTY, atomics::SeqCst);
183176
match self.data.take() {
184177
Some(data) => Ok(data),
185178
None => unreachable!(),
@@ -194,7 +187,7 @@ impl<T: Send> Packet<T> {
194187
match self.data.take() {
195188
Some(data) => Ok(data),
196189
None => {
197-
match util::replace(&mut self.upgrade, SendUsed) {
190+
match mem::replace(&mut self.upgrade, SendUsed) {
198191
SendUsed | NothingSent => Err(Disconnected),
199192
GoUp(upgrade) => Err(Upgraded(upgrade))
200193
}
@@ -216,9 +209,7 @@ impl<T: Send> Packet<T> {
216209
};
217210
self.upgrade = GoUp(up);
218211

219-
// Use a Release memory ordering in order to make sure that our write to
220-
// `upgrade` is visible to the other thread.
221-
match self.state.swap(DISCONNECTED, atomics::Release) {
212+
match self.state.swap(DISCONNECTED, atomics::SeqCst) {
222213
// If the channel is empty or has data on it, then we're good to go.
223214
// Senders will check the data before the upgrade (in case we
224215
// plastered over the DATA state).
@@ -246,9 +237,7 @@ impl<T: Send> Packet<T> {
246237
}
247238

248239
pub fn drop_port(&mut self) {
249-
// Use an Acquire memory ordering in order to see the data that the
250-
// senders are sending.
251-
match self.state.swap(DISCONNECTED, atomics::Acquire) {
240+
match self.state.swap(DISCONNECTED, atomics::SeqCst) {
252241
// An empty channel has nothing to do, and a remotely disconnected
253242
// channel also has nothing to do b/c we're about to run the drop
254243
// glue
@@ -271,13 +260,12 @@ impl<T: Send> Packet<T> {
271260
// If Ok, the value is whether this port has data, if Err, then the upgraded
272261
// port needs to be checked instead of this one.
273262
pub fn can_recv(&mut self) -> Result<bool, Port<T>> {
274-
// Use Acquire so we can see all previous memory writes
275-
match self.state.load(atomics::Acquire) {
263+
match self.state.load(atomics::SeqCst) {
276264
EMPTY => Ok(false), // Welp, we tried
277265
DATA => Ok(true), // we have some un-acquired data
278266
DISCONNECTED if self.data.is_some() => Ok(true), // we have data
279267
DISCONNECTED => {
280-
match util::replace(&mut self.upgrade, SendUsed) {
268+
match mem::replace(&mut self.upgrade, SendUsed) {
281269
// The other end sent us an upgrade, so we need to
282270
// propagate upwards whether the upgrade can receive
283271
// data
@@ -304,7 +292,7 @@ impl<T: Send> Packet<T> {
304292
SelCanceled(unsafe { BlockedTask::cast_from_uint(n) })
305293
}
306294
DISCONNECTED => {
307-
match util::replace(&mut self.upgrade, SendUsed) {
295+
match mem::replace(&mut self.upgrade, SendUsed) {
308296
// The other end sent us an upgrade, so we need to
309297
// propagate upwards whether the upgrade can receive
310298
// data
@@ -331,8 +319,7 @@ impl<T: Send> Packet<T> {
331319
//
332320
// The return value indicates whether there's data on this port.
333321
pub fn abort_selection(&mut self) -> Result<bool, Port<T>> {
334-
// use Acquire to make sure we see all previous memory writes
335-
let state = match self.state.load(atomics::Acquire) {
322+
let state = match self.state.load(atomics::SeqCst) {
336323
// Each of these states means that no further activity will happen
337324
// with regard to abortion selection
338325
s @ EMPTY |
@@ -357,7 +344,7 @@ impl<T: Send> Packet<T> {
357344
// aborted.
358345
DISCONNECTED => {
359346
assert!(self.data.is_none());
360-
match util::replace(&mut self.upgrade, SendUsed) {
347+
match mem::replace(&mut self.upgrade, SendUsed) {
361348
GoUp(port) => Err(port),
362349
_ => Ok(true),
363350
}

src/libstd/io/net/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ mod test {
698698
iotest!(fn tcp_clone_two_read() {
699699
let addr = next_test_ip6();
700700
let mut acceptor = TcpListener::bind(addr).listen();
701-
let (p, c) = SharedChan::new();
701+
let (p, c) = Chan::new();
702702
let c2 = c.clone();
703703

704704
spawn(proc() {

src/libstd/io/net/udp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ mod test {
301301
let addr2 = next_test_ip4();
302302
let mut sock1 = UdpSocket::bind(addr1).unwrap();
303303
let sock2 = UdpSocket::bind(addr2).unwrap();
304-
let (p, c) = SharedChan::new();
304+
let (p, c) = Chan::new();
305305
let c2 = c.clone();
306306

307307
spawn(proc() {
@@ -335,7 +335,7 @@ mod test {
335335
let mut sock1 = UdpSocket::bind(addr1).unwrap();
336336
let sock2 = UdpSocket::bind(addr2).unwrap();
337337

338-
let (p, c) = SharedChan::new();
338+
let (p, c) = Chan::new();
339339
let (serv_port, serv_chan) = Chan::new();
340340

341341
spawn(proc() {

src/libstd/io/net/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ mod tests {
270270
fn unix_clone_two_read() {
271271
let addr = next_test_unix();
272272
let mut acceptor = UnixListener::bind(&addr).listen();
273-
let (p, c) = SharedChan::new();
273+
let (p, c) = Chan::new();
274274
let c2 = c.clone();
275275

276276
spawn(proc() {

0 commit comments

Comments
 (0)