@@ -258,7 +258,6 @@ impl<T: ?Sized> RwLock<T> {
258
258
/// *writer = 2;
259
259
/// # })
260
260
/// ```
261
- #[ inline]
262
261
pub fn try_upgradable_read ( & self ) -> Option < RwLockUpgradableReadGuard < ' _ , T > > {
263
262
// First try grabbing the mutex.
264
263
let lock = self . mutex . try_lock ( ) ?;
@@ -510,14 +509,14 @@ unsafe impl<T: Send + Sync + ?Sized> Send for RwLockUpgradableReadGuard<'_, T> {
510
509
unsafe impl < T : Sync + ?Sized > Sync for RwLockUpgradableReadGuard < ' _ , T > { }
511
510
512
511
impl < ' a , T : ?Sized > RwLockUpgradableReadGuard < ' a , T > {
513
- /// Converts this guard into a write guard.
512
+ /// Converts this guard into a writer guard.
514
513
fn into_writer ( self ) -> RwLockWriteGuard < ' a , T > {
515
514
let writer = RwLockWriteGuard { writer : RwLockWriteGuardInner ( self . reader . 0 ) , reserved : self . reserved } ;
516
515
mem:: forget ( self . reader ) ;
517
516
writer
518
517
}
519
518
520
- /// Converts this guard into a reader guard.
519
+ /// Downgrades into a regular reader guard.
521
520
///
522
521
/// # Examples
523
522
///
@@ -537,7 +536,6 @@ impl<'a, T: ?Sized> RwLockUpgradableReadGuard<'a, T> {
537
536
/// assert!(lock.try_upgradable_read().is_some());
538
537
/// # })
539
538
/// ```
540
- #[ inline]
541
539
pub fn downgrade ( guard : Self ) -> RwLockReadGuard < ' a , T > {
542
540
guard. reader
543
541
}
@@ -667,7 +665,7 @@ unsafe impl<T: Send + ?Sized> Send for RwLockWriteGuard<'_, T> {}
667
665
unsafe impl < T : Sync + ?Sized > Sync for RwLockWriteGuard < ' _ , T > { }
668
666
669
667
impl < ' a , T : ?Sized > RwLockWriteGuard < ' a , T > {
670
- /// Converts this guard into a reader guard.
668
+ /// Downgrades into a regular reader guard.
671
669
///
672
670
/// # Examples
673
671
///
@@ -688,20 +686,20 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
688
686
/// assert!(lock.try_read().is_some());
689
687
/// # })
690
688
/// ```
691
- #[ inline]
692
- pub fn downgrade ( write_guard : Self ) -> RwLockReadGuard < ' a , T > {
689
+ pub fn downgrade ( guard : Self ) -> RwLockReadGuard < ' a , T > {
693
690
// Atomically downgrade state.
694
- write_guard. writer . 0 . state . fetch_add ( ONE_READER - WRITER_BIT , Ordering :: SeqCst ) ;
691
+ guard. writer . 0 . state . fetch_add ( ONE_READER - WRITER_BIT , Ordering :: SeqCst ) ;
692
+
695
693
// Trigger the "no writer" event.
696
- write_guard. writer . 0 . no_writer . notify ( 1 ) ;
697
- // Create and return the read guard
698
- let read_guard = RwLockReadGuard ( write_guard. writer . 0 ) ;
699
- mem:: forget ( write_guard. writer ) ; // RwLockWriteGuardInner::drop should not be called !
700
- read_guard
694
+ guard. writer . 0 . no_writer . notify ( 1 ) ;
695
+
696
+ // Convert into a read guard and return.
697
+ let new_guard = RwLockReadGuard ( guard. writer . 0 ) ;
698
+ mem:: forget ( guard. writer ) ; // `RwLockWriteGuardInner::drop()` should not be called!
699
+ new_guard
701
700
}
702
701
703
- /// Atomically downgrades a write lock into an upgradable read lock
704
- /// without allowing any writers to take exclusive access of the lock in the meantime.
702
+ /// Downgrades into an upgradable reader guard.
705
703
///
706
704
/// # Examples
707
705
///
@@ -728,14 +726,14 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
728
726
pub fn downgrade_to_upgradable ( guard : Self ) -> RwLockUpgradableReadGuard < ' a , T > {
729
727
// Atomically downgrade state.
730
728
guard. writer . 0 . state . fetch_add ( ONE_READER - WRITER_BIT , Ordering :: SeqCst ) ;
731
- // Create and return the upgradable read guard
732
- let reader = RwLockReadGuard ( guard. writer . 0 ) ;
733
- mem:: forget ( guard. writer ) ; // RwLockWriteGuardInner::drop should not be called !
734
729
735
- RwLockUpgradableReadGuard {
736
- reader,
730
+ // Convert into an upgradable read guard and return.
731
+ let new_guard = RwLockUpgradableReadGuard {
732
+ reader : RwLockReadGuard ( guard. writer . 0 ) ,
737
733
reserved : guard. reserved ,
738
- }
734
+ } ;
735
+ mem:: forget ( guard. writer ) ; // `RwLockWriteGuardInner::drop()` should not be called!
736
+ new_guard
739
737
}
740
738
}
741
739
0 commit comments