@@ -22,7 +22,7 @@ use ops::Drop;
22
22
use kinds:: Owned ;
23
23
use rt:: sched:: { Scheduler , Coroutine } ;
24
24
use rt:: local:: Local ;
25
- use unstable:: intrinsics :: { atomic_xchg , atomic_load } ;
25
+ use unstable:: atomics :: { AtomicUint , SeqCst } ;
26
26
use util:: Void ;
27
27
use comm:: { GenericChan , GenericSmartChan , GenericPort , Peekable } ;
28
28
use cell:: Cell ;
@@ -34,14 +34,14 @@ use cell::Cell;
34
34
/// * 2 - both endpoints are alive
35
35
/// * 1 - either the sender or the receiver is dead, determined by context
36
36
/// * <ptr> - A pointer to a blocked Task that can be transmuted to ~Task
37
- type State = int ;
37
+ type State = uint ;
38
38
39
39
static STATE_BOTH : State = 2 ;
40
40
static STATE_ONE : State = 1 ;
41
41
42
42
/// The heap-allocated structure shared between two endpoints.
43
43
struct Packet < T > {
44
- state : State ,
44
+ state : AtomicUint ,
45
45
payload : Option < T > ,
46
46
}
47
47
@@ -70,7 +70,7 @@ pub struct PortOneHack<T> {
70
70
71
71
pub fn oneshot < T : Owned > ( ) -> ( PortOne < T > , ChanOne < T > ) {
72
72
let packet: ~Packet < T > = ~Packet {
73
- state : STATE_BOTH ,
73
+ state : AtomicUint :: new ( STATE_BOTH ) ,
74
74
payload : None
75
75
} ;
76
76
@@ -114,7 +114,7 @@ impl<T> ChanOne<T> {
114
114
// reordering of the payload write. This also issues an
115
115
// acquire barrier that keeps the subsequent access of the
116
116
// ~Task pointer from being reordered.
117
- let oldstate = atomic_xchg ( & mut ( * packet) . state , STATE_ONE ) ;
117
+ let oldstate = ( * packet) . state . swap ( STATE_ONE , SeqCst ) ;
118
118
match oldstate {
119
119
STATE_BOTH => {
120
120
// Port is not waiting yet. Nothing to do
@@ -175,7 +175,7 @@ impl<T> PortOne<T> {
175
175
// of the payload. Also issues a release barrier to prevent reordering
176
176
// of any previous writes to the task structure.
177
177
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 ) ;
179
179
match oldstate {
180
180
STATE_BOTH => {
181
181
// Data has not been sent. Now we're blocked.
@@ -227,7 +227,7 @@ impl<T> Peekable<T> for PortOne<T> {
227
227
fn peek ( & self ) -> bool {
228
228
unsafe {
229
229
let packet: * mut Packet < T > = self . inner . packet ( ) ;
230
- let oldstate = atomic_load ( & mut ( * packet) . state ) ;
230
+ let oldstate = ( * packet) . state . load ( SeqCst ) ;
231
231
match oldstate {
232
232
STATE_BOTH => false ,
233
233
STATE_ONE => ( * packet) . payload . is_some ( ) ,
@@ -244,7 +244,7 @@ impl<T> Drop for ChanOneHack<T> {
244
244
245
245
unsafe {
246
246
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 ) ;
248
248
match oldstate {
249
249
STATE_BOTH => {
250
250
// Port still active. It will destroy the Packet.
@@ -271,7 +271,7 @@ impl<T> Drop for PortOneHack<T> {
271
271
272
272
unsafe {
273
273
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 ) ;
275
275
match oldstate {
276
276
STATE_BOTH => {
277
277
// Chan still active. It will destroy the packet.
0 commit comments