1
1
mod pipes {
2
- import unsafe:: { forget, reinterpret_cast } ;
2
+ import unsafe:: { forget, transmute } ;
3
3
4
4
enum state {
5
5
empty,
@@ -25,30 +25,26 @@ mod pipes {
25
25
26
26
#[ abi = "rust-intrinsic" ]
27
27
mod rusti {
28
- fn atomic_xchng ( & dst : int , src : int ) -> int { fail; }
29
- fn atomic_xchng_acq ( & dst : int , src : int ) -> int { fail; }
30
- fn atomic_xchng_rel ( & dst : int , src : int ) -> int { fail; }
28
+ fn atomic_xchg ( _dst : & mut int , _src : int ) -> int { fail; }
29
+ fn atomic_xchg_acq ( _dst : & mut int , _src : int ) -> int { fail; }
30
+ fn atomic_xchg_rel ( _dst : & mut int , _src : int ) -> int { fail; }
31
31
}
32
32
33
33
// We should consider moving this to core::unsafe, although I
34
34
// suspect graydon would want us to use void pointers instead.
35
- unsafe fn uniquify < T > ( x : * T ) -> ~T {
36
- unsafe { unsafe :: reinterpret_cast ( x) }
35
+ unsafe fn uniquify < T > ( + x: * T ) -> ~T {
36
+ unsafe { unsafe :: transmute ( x) }
37
37
}
38
38
39
- fn swap_state_acq ( & dst: state , src : state ) -> state {
39
+ fn swap_state_acq ( + dst : & mut state , src : state ) -> state {
40
40
unsafe {
41
- reinterpret_cast ( rusti:: atomic_xchng_acq (
42
- * ( ptr:: mut_addr_of ( dst) as * mut int ) ,
43
- src as int ) )
41
+ transmute ( rusti:: atomic_xchg_acq ( transmute ( dst) , src as int ) )
44
42
}
45
43
}
46
44
47
- fn swap_state_rel ( & dst: state , src : state ) -> state {
45
+ fn swap_state_rel ( + dst : & mut state , src : state ) -> state {
48
46
unsafe {
49
- reinterpret_cast ( rusti:: atomic_xchng_rel (
50
- * ( ptr:: mut_addr_of ( dst) as * mut int ) ,
51
- src as int ) )
47
+ transmute ( rusti:: atomic_xchg_rel ( transmute ( dst) , src as int ) )
52
48
}
53
49
}
54
50
@@ -57,7 +53,7 @@ mod pipes {
57
53
let p = unsafe { uniquify ( p) } ;
58
54
assert ( * p) . payload == none;
59
55
( * p) . payload <- some ( payload) ;
60
- let old_state = swap_state_rel ( ( * p) . state , full) ;
56
+ let old_state = swap_state_rel ( & mut ( * p) . state , full) ;
61
57
match old_state {
62
58
empty => {
63
59
// Yay, fastpath.
@@ -82,7 +78,7 @@ mod pipes {
82
78
let p = p. unwrap ( ) ;
83
79
let p = unsafe { uniquify ( p) } ;
84
80
loop {
85
- let old_state = swap_state_acq ( ( * p) . state ,
81
+ let old_state = swap_state_acq ( & mut ( * p) . state ,
86
82
blocked) ;
87
83
match old_state {
88
84
empty | blocked => { task:: yield ( ) ; }
@@ -101,7 +97,7 @@ mod pipes {
101
97
102
98
fn sender_terminate < T : send > ( p : * packet < T > ) {
103
99
let p = unsafe { uniquify ( p) } ;
104
- match swap_state_rel ( ( * p) . state , terminated) {
100
+ match swap_state_rel ( & mut ( * p) . state , terminated) {
105
101
empty | blocked => {
106
102
// The receiver will eventually clean up.
107
103
unsafe { forget ( p) }
@@ -118,7 +114,7 @@ mod pipes {
118
114
119
115
fn receiver_terminate < T : send > ( p : * packet < T > ) {
120
116
let p = unsafe { uniquify ( p) } ;
121
- match swap_state_rel ( ( * p) . state , terminated) {
117
+ match swap_state_rel ( & mut ( * p) . state , terminated) {
122
118
empty => {
123
119
// the sender will clean up
124
120
unsafe { forget ( p) }
@@ -179,7 +175,7 @@ mod pingpong {
179
175
180
176
fn liberate_ping( -p: ping) -> pipes:: send_packet < pong > unsafe {
181
177
let addr : * pipes:: send_packet <pong > = match p {
182
- ping( x) => { unsafe :: reinterpret_cast ( ptr:: addr_of ( x) ) }
178
+ ping( x) => { unsafe :: transmute ( ptr:: addr_of ( x) ) }
183
179
} ;
184
180
let liberated_value <- * addr;
185
181
unsafe :: forget ( p ) ;
@@ -188,7 +184,7 @@ mod pingpong {
188
184
189
185
fn liberate_pong ( -p : pong ) -> pipes:: send_packet < ping > unsafe {
190
186
let addr : * pipes:: send_packet < ping > = match p {
191
- pong ( x) => { unsafe :: reinterpret_cast ( ptr:: addr_of ( x) ) }
187
+ pong ( x) => { unsafe :: transmute ( ptr:: addr_of ( x) ) }
192
188
} ;
193
189
let liberated_value <- * addr;
194
190
unsafe :: forget ( p ) ;
0 commit comments