@@ -162,7 +162,7 @@ impl<T: ?Sized> RwLock<T> {
162
162
pub fn read ( & self ) -> RwLockReadFuture < ' _ , T > {
163
163
RwLockReadFuture {
164
164
rwlock : Some ( self ) ,
165
- ticket : None ,
165
+ phase : None ,
166
166
wait_key : WAIT_KEY_NONE ,
167
167
}
168
168
}
@@ -236,27 +236,12 @@ impl<T: ?Sized> RwLock<T> {
236
236
}
237
237
}
238
238
239
- #[ derive( Debug ) ]
240
- enum Ticket {
241
- Read ( usize ) ,
242
- Write ( usize ) ,
243
- }
244
-
245
- impl Ticket {
246
- fn value ( & self ) -> usize {
247
- match self {
248
- Ticket :: Read ( value) => * value,
249
- Ticket :: Write ( value) => * value,
250
- }
251
- }
252
- }
253
-
254
239
/// A future which resolves when the target read access lock has been successfully
255
240
/// acquired.
256
241
pub struct RwLockReadFuture < ' a , T : ?Sized > {
257
242
// `None` indicates that the mutex was successfully acquired.
258
243
rwlock : Option < & ' a RwLock < T > > ,
259
- ticket : Option < Ticket > ,
244
+ phase : Option < usize > ,
260
245
wait_key : usize ,
261
246
}
262
247
@@ -265,7 +250,7 @@ impl<T: ?Sized> fmt::Debug for RwLockReadFuture<'_, T> {
265
250
f. debug_struct ( "RwLockReadFuture" )
266
251
. field ( "was_acquired" , & self . rwlock . is_none ( ) )
267
252
. field ( "rwlock" , & self . rwlock )
268
- . field ( "ticket " , & self . ticket )
253
+ . field ( "phase " , & self . phase )
269
254
. field (
270
255
"wait_key" ,
271
256
& ( if self . wait_key == WAIT_KEY_NONE {
@@ -292,19 +277,16 @@ impl<'a, T: ?Sized> Future for RwLockReadFuture<'a, T> {
292
277
. rwlock
293
278
. expect ( "polled RwLockReadFuture after completion" ) ;
294
279
295
- // The ticket is defined by the write bits stored within the read-in count
296
- let ticket = self
297
- . ticket
298
- . get_or_insert_with ( || Ticket :: Read ( rwlock. atomic . reserve_reader ( ) ) )
299
- . value ( ) ;
280
+ // The phase is defined by the write bits stored within the read-in count
281
+ let phase = * self . phase . get_or_insert_with ( || rwlock. atomic . reserve_reader ( ) ) ;
300
282
301
- // Safe to create guard when either there are no writers (ticket == 0) or if
283
+ // Safe to create guard when either there are no writers (phase == 0) or if
302
284
// at least one of the two write bits change.
303
285
// Writers always wait until the current reader phase completes before acquiring
304
286
// the lock; thus the PHASE bit both maintains the read-write condition and
305
287
// prevents deadlock in the case that this line isn't reached before a writer sets
306
288
// the ONE_WRITER bit.
307
- if ticket == 0 || ticket != rwlock. atomic . phase ( ) {
289
+ if phase == 0 || phase != rwlock. atomic . phase ( ) {
308
290
if self . wait_key != WAIT_KEY_NONE {
309
291
rwlock. readers . remove ( self . wait_key ) ;
310
292
}
@@ -329,6 +311,12 @@ impl<T: ?Sized> Drop for RwLockReadFuture<'_, T> {
329
311
}
330
312
}
331
313
314
+ #[ derive( Debug ) ]
315
+ enum Ticket {
316
+ Read ( usize ) ,
317
+ Write ( usize ) ,
318
+ }
319
+
332
320
/// A future which resolves when the target write access lock has been successfully
333
321
/// acquired.
334
322
pub struct RwLockWriteFuture < ' a , T : ?Sized > {
0 commit comments