3434
3535use comm:: Port ;
3636use kinds:: Send ;
37+ use mem;
3738use ops:: Drop ;
3839use option:: { Some , None , Option } ;
3940use result:: { Result , Ok , Err } ;
4041use rt:: local:: Local ;
4142use rt:: task:: { Task , BlockedTask } ;
4243use sync:: atomics;
43- use util;
4444
4545// Various states you can find a port in.
4646static 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 }
0 commit comments