Skip to content

Commit 2e6d51f

Browse files
committed
std::rt: Use AtomicUint instead of intrinsics in comm
1 parent e2bedb1 commit 2e6d51f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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)