@@ -258,7 +258,6 @@ impl<T: ?Sized> RwLock<T> {
258258 /// *writer = 2;
259259 /// # })
260260 /// ```
261- #[ inline]
262261 pub fn try_upgradable_read ( & self ) -> Option < RwLockUpgradableReadGuard < ' _ , T > > {
263262 // First try grabbing the mutex.
264263 let lock = self . mutex . try_lock ( ) ?;
@@ -510,14 +509,14 @@ unsafe impl<T: Send + Sync + ?Sized> Send for RwLockUpgradableReadGuard<'_, T> {
510509unsafe impl < T : Sync + ?Sized > Sync for RwLockUpgradableReadGuard < ' _ , T > { }
511510
512511impl < ' a , T : ?Sized > RwLockUpgradableReadGuard < ' a , T > {
513- /// Converts this guard into a write guard.
512+ /// Converts this guard into a writer guard.
514513 fn into_writer ( self ) -> RwLockWriteGuard < ' a , T > {
515514 let writer = RwLockWriteGuard { writer : RwLockWriteGuardInner ( self . reader . 0 ) , reserved : self . reserved } ;
516515 mem:: forget ( self . reader ) ;
517516 writer
518517 }
519518
520- /// Converts this guard into a reader guard.
519+ /// Downgrades into a regular reader guard.
521520 ///
522521 /// # Examples
523522 ///
@@ -537,7 +536,6 @@ impl<'a, T: ?Sized> RwLockUpgradableReadGuard<'a, T> {
537536 /// assert!(lock.try_upgradable_read().is_some());
538537 /// # })
539538 /// ```
540- #[ inline]
541539 pub fn downgrade ( guard : Self ) -> RwLockReadGuard < ' a , T > {
542540 guard. reader
543541 }
@@ -667,7 +665,7 @@ unsafe impl<T: Send + ?Sized> Send for RwLockWriteGuard<'_, T> {}
667665unsafe impl < T : Sync + ?Sized > Sync for RwLockWriteGuard < ' _ , T > { }
668666
669667impl < ' a , T : ?Sized > RwLockWriteGuard < ' a , T > {
670- /// Converts this guard into a reader guard.
668+ /// Downgrades into a regular reader guard.
671669 ///
672670 /// # Examples
673671 ///
@@ -688,20 +686,20 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
688686 /// assert!(lock.try_read().is_some());
689687 /// # })
690688 /// ```
691- #[ inline]
692- pub fn downgrade ( write_guard : Self ) -> RwLockReadGuard < ' a , T > {
689+ pub fn downgrade ( guard : Self ) -> RwLockReadGuard < ' a , T > {
693690 // 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+
695693 // 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
701700 }
702701
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.
705703 ///
706704 /// # Examples
707705 ///
@@ -728,14 +726,14 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
728726 pub fn downgrade_to_upgradable ( guard : Self ) -> RwLockUpgradableReadGuard < ' a , T > {
729727 // Atomically downgrade state.
730728 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 !
734729
735- RwLockUpgradableReadGuard {
736- reader,
730+ // Convert into an upgradable read guard and return.
731+ let new_guard = RwLockUpgradableReadGuard {
732+ reader : RwLockReadGuard ( guard. writer . 0 ) ,
737733 reserved : guard. reserved ,
738- }
734+ } ;
735+ mem:: forget ( guard. writer ) ; // `RwLockWriteGuardInner::drop()` should not be called!
736+ new_guard
739737 }
740738}
741739
0 commit comments