@@ -10,7 +10,7 @@ use core::pin::Pin;
10
10
#[ cfg( feature = "bilock" ) ]
11
11
use core:: ptr;
12
12
use core:: sync:: atomic:: AtomicU8 ;
13
- use core:: sync:: atomic:: Ordering :: { Acquire , AcqRel } ;
13
+ use core:: sync:: atomic:: Ordering :: { Acquire , AcqRel , Relaxed , Release } ;
14
14
#[ cfg( feature = "bilock" ) ]
15
15
use futures_core:: future:: Future ;
16
16
use futures_core:: task:: { Context , Poll , Waker } ;
@@ -160,10 +160,12 @@ impl<T> BiLock<T> {
160
160
/// task.
161
161
pub fn poll_lock ( & mut self , cx : & mut Context < ' _ > ) -> Poll < BiLockGuard < ' _ , T > > {
162
162
assert_ne ! ( self . token, TOKEN_LOCK ) ;
163
- self . token = self . arc . token . swap ( self . token , if self . token == TOKEN_WAKE { AcqRel } else { Acquire } ) ;
163
+ let arc_token = & self . arc . token ;
164
+ self . token = arc_token. swap ( self . token , if self . token == TOKEN_WAKE { Release } else { Relaxed } ) ;
164
165
match self . token {
165
166
TOKEN_NULL => { }
166
167
TOKEN_WAKE => {
168
+ arc_token. load ( Acquire ) ;
167
169
let our_waker = cx. waker ( ) ;
168
170
// SAFETY: we own the wake token, so we have exclusive access to this field.
169
171
// The mutable reference we create goes out of scope before we give up the
@@ -179,17 +181,19 @@ impl<T> BiLock<T> {
179
181
}
180
182
}
181
183
TOKEN_LOCK => {
184
+ arc_token. load ( Acquire ) ;
182
185
return Poll :: Ready ( BiLockGuard { bilock : self } ) ;
183
186
}
184
187
_ => unreachable ! ( ) ,
185
188
}
186
189
// We only need Release if we previously stored our waker
187
- self . token = self . arc . token . swap ( self . token , if self . token == TOKEN_WAKE { AcqRel } else { Acquire } ) ;
190
+ self . token = arc_token . swap ( self . token , if self . token == TOKEN_WAKE { Release } else { Relaxed } ) ;
188
191
match self . token {
189
192
TOKEN_NULL => {
190
193
return Poll :: Pending ;
191
194
}
192
195
TOKEN_WAKE => {
196
+ arc_token. load ( Acquire ) ;
193
197
let our_waker = cx. waker ( ) ;
194
198
// SAFETY: we own the wake token, so we have exclusive access to this field.
195
199
// The mutable reference we create goes out of scope before we give up the
@@ -205,17 +209,19 @@ impl<T> BiLock<T> {
205
209
}
206
210
}
207
211
TOKEN_LOCK => {
212
+ arc_token. load ( Acquire ) ;
208
213
return Poll :: Ready ( BiLockGuard { bilock : self } ) ;
209
214
}
210
215
_ => unreachable ! ( ) ,
211
216
}
212
- self . token = self . arc . token . swap ( self . token , AcqRel ) ;
217
+ self . token = arc_token . swap ( self . token , Release ) ;
213
218
match self . token {
214
219
TOKEN_NULL => {
215
- return Poll :: Pending ;
220
+ Poll :: Pending
216
221
}
217
222
TOKEN_LOCK => {
218
- return Poll :: Ready ( BiLockGuard { bilock : self } ) ;
223
+ arc_token. load ( Acquire ) ;
224
+ Poll :: Ready ( BiLockGuard { bilock : self } )
219
225
}
220
226
_ => unreachable ! ( ) ,
221
227
}
@@ -255,10 +261,12 @@ impl<T> BiLock<T> {
255
261
256
262
fn unlock ( & mut self ) {
257
263
assert_eq ! ( self . token, TOKEN_LOCK ) ;
258
- self . token = self . arc . token . swap ( self . token , AcqRel ) ;
264
+ let arc_token = self . arc . token ;
265
+ self . token = self . arc . token . swap ( self . token , Release ) ;
259
266
match self . token {
260
267
TOKEN_NULL => { } // lock uncontended
261
268
TOKEN_WAKE => {
269
+ arc_token. load ( Acquire ) ;
262
270
// SAFETY: we own the wake token, so we have exclusive access to this field.
263
271
if let Some ( ( left, wake) ) = unsafe { & mut * self . arc . waker . get ( ) } {
264
272
if self . left != * left {
0 commit comments