25
25
26
26
use crate :: pin:: Pin ;
27
27
use crate :: sync:: atomic:: AtomicI8 ;
28
- use crate :: sync:: atomic:: Ordering :: { Relaxed , SeqCst } ;
28
+ use crate :: sync:: atomic:: Ordering :: { Acquire , Relaxed , Release } ;
29
29
use crate :: sys:: wait_flag:: WaitFlag ;
30
30
use crate :: time:: Duration ;
31
31
@@ -47,7 +47,7 @@ impl Parker {
47
47
48
48
// This implementation doesn't require `unsafe` and `Pin`, but other implementations do.
49
49
pub unsafe fn park ( self : Pin < & Self > ) {
50
- match self . state . fetch_sub ( 1 , SeqCst ) {
50
+ match self . state . fetch_sub ( 1 , Acquire ) {
51
51
// NOTIFIED => EMPTY
52
52
NOTIFIED => return ,
53
53
// EMPTY => PARKED
@@ -59,7 +59,7 @@ impl Parker {
59
59
loop {
60
60
self . wait_flag . wait ( ) ;
61
61
62
- match self . state . compare_exchange ( NOTIFIED , EMPTY , SeqCst , Relaxed ) {
62
+ match self . state . compare_exchange ( NOTIFIED , EMPTY , Acquire , Relaxed ) {
63
63
Ok ( _) => return ,
64
64
Err ( PARKED ) => ( ) ,
65
65
Err ( _) => panic ! ( "inconsistent park state" ) ,
@@ -69,7 +69,7 @@ impl Parker {
69
69
70
70
// This implementation doesn't require `unsafe` and `Pin`, but other implementations do.
71
71
pub unsafe fn park_timeout ( self : Pin < & Self > , dur : Duration ) {
72
- match self . state . fetch_sub ( 1 , SeqCst ) {
72
+ match self . state . fetch_sub ( 1 , Acquire ) {
73
73
NOTIFIED => return ,
74
74
EMPTY => ( ) ,
75
75
_ => panic ! ( "inconsistent park state" ) ,
@@ -83,9 +83,8 @@ impl Parker {
83
83
// is protected against this by looping until the token is actually given, but
84
84
// here we cannot easily tell.
85
85
86
- // Use `swap` to provide acquire ordering (not strictly necessary, but all other
87
- // implementations do).
88
- match self . state . swap ( EMPTY , SeqCst ) {
86
+ // Use `swap` to provide acquire ordering.
87
+ match self . state . swap ( EMPTY , Acquire ) {
89
88
NOTIFIED => ( ) ,
90
89
PARKED => ( ) ,
91
90
_ => panic ! ( "inconsistent park state" ) ,
@@ -94,7 +93,7 @@ impl Parker {
94
93
95
94
// This implementation doesn't require `Pin`, but other implementations do.
96
95
pub fn unpark ( self : Pin < & Self > ) {
97
- let state = self . state . swap ( NOTIFIED , SeqCst ) ;
96
+ let state = self . state . swap ( NOTIFIED , Release ) ;
98
97
99
98
if state == PARKED {
100
99
self . wait_flag . raise ( ) ;
0 commit comments