Skip to content

Commit 93158c3

Browse files
committed
---
yaml --- r: 142593 b: refs/heads/try2 c: 2e6d51f h: refs/heads/master i: 142591: dc0a883 v: v3
1 parent 0b11894 commit 93158c3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e2bedb1b868a634885df9f8a277bec1915c98fc2
8+
refs/heads/try2: 2e6d51f9cea14ff271223855454034b27ced4ce9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rt/comm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ops::Drop;
2222
use kinds::Owned;
2323
use rt::sched::{Scheduler, Coroutine};
2424
use rt::local::Local;
25-
use unstable::intrinsics::{atomic_xchg, atomic_load};
25+
use unstable::atomics::{AtomicUint, SeqCst};
2626
use util::Void;
2727
use comm::{GenericChan, GenericSmartChan, GenericPort, Peekable};
2828
use cell::Cell;
@@ -34,14 +34,14 @@ use cell::Cell;
3434
/// * 2 - both endpoints are alive
3535
/// * 1 - either the sender or the receiver is dead, determined by context
3636
/// * <ptr> - A pointer to a blocked Task that can be transmuted to ~Task
37-
type State = int;
37+
type State = uint;
3838

3939
static STATE_BOTH: State = 2;
4040
static STATE_ONE: State = 1;
4141

4242
/// The heap-allocated structure shared between two endpoints.
4343
struct Packet<T> {
44-
state: State,
44+
state: AtomicUint,
4545
payload: Option<T>,
4646
}
4747

@@ -70,7 +70,7 @@ pub struct PortOneHack<T> {
7070

7171
pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
7272
let packet: ~Packet<T> = ~Packet {
73-
state: STATE_BOTH,
73+
state: AtomicUint::new(STATE_BOTH),
7474
payload: None
7575
};
7676

@@ -114,7 +114,7 @@ impl<T> ChanOne<T> {
114114
// reordering of the payload write. This also issues an
115115
// acquire barrier that keeps the subsequent access of the
116116
// ~Task pointer from being reordered.
117-
let oldstate = atomic_xchg(&mut (*packet).state, STATE_ONE);
117+
let oldstate = (*packet).state.swap(STATE_ONE, SeqCst);
118118
match oldstate {
119119
STATE_BOTH => {
120120
// Port is not waiting yet. Nothing to do
@@ -175,7 +175,7 @@ impl<T> PortOne<T> {
175175
// of the payload. Also issues a release barrier to prevent reordering
176176
// of any previous writes to the task structure.
177177
let task_as_state: State = cast::transmute(task);
178-
let oldstate = atomic_xchg(&mut (*packet).state, task_as_state);
178+
let oldstate = (*packet).state.swap(task_as_state, SeqCst);
179179
match oldstate {
180180
STATE_BOTH => {
181181
// Data has not been sent. Now we're blocked.
@@ -227,7 +227,7 @@ impl<T> Peekable<T> for PortOne<T> {
227227
fn peek(&self) -> bool {
228228
unsafe {
229229
let packet: *mut Packet<T> = self.inner.packet();
230-
let oldstate = atomic_load(&mut (*packet).state);
230+
let oldstate = (*packet).state.load(SeqCst);
231231
match oldstate {
232232
STATE_BOTH => false,
233233
STATE_ONE => (*packet).payload.is_some(),
@@ -244,7 +244,7 @@ impl<T> Drop for ChanOneHack<T> {
244244

245245
unsafe {
246246
let this = cast::transmute_mut(self);
247-
let oldstate = atomic_xchg(&mut (*this.packet()).state, STATE_ONE);
247+
let oldstate = (*this.packet()).state.swap(STATE_ONE, SeqCst);
248248
match oldstate {
249249
STATE_BOTH => {
250250
// Port still active. It will destroy the Packet.
@@ -271,7 +271,7 @@ impl<T> Drop for PortOneHack<T> {
271271

272272
unsafe {
273273
let this = cast::transmute_mut(self);
274-
let oldstate = atomic_xchg(&mut (*this.packet()).state, STATE_ONE);
274+
let oldstate = (*this.packet()).state.swap(STATE_ONE, SeqCst);
275275
match oldstate {
276276
STATE_BOTH => {
277277
// Chan still active. It will destroy the packet.

0 commit comments

Comments
 (0)