@@ -102,47 +102,46 @@ impl StaticRWLock {
102102 ///
103103 /// The lock is automatically unlocked when the returned guard is dropped.
104104 #[ inline]
105- pub fn read_with_guard ( & ' static self ) -> RWLockGuard {
105+ pub fn read_with_guard ( & ' static self ) -> RWLockReadGuard {
106106 // Safety: All methods require static references, therefore self
107107 // cannot be moved between invocations.
108108 unsafe {
109109 self . 0 . read ( ) ;
110110 }
111- RWLockGuard ( & self . 0 , GuardType :: Read )
111+ RWLockReadGuard ( & self . 0 )
112112 }
113113
114114 /// Acquires write access to the underlying lock, blocking the current thread
115115 /// to do so.
116116 ///
117117 /// The lock is automatically unlocked when the returned guard is dropped.
118118 #[ inline]
119- pub fn write_with_guard ( & ' static self ) -> RWLockGuard {
119+ pub fn write_with_guard ( & ' static self ) -> RWLockWriteGuard {
120120 // Safety: All methods require static references, therefore self
121121 // cannot be moved between invocations.
122122 unsafe {
123123 self . 0 . write ( ) ;
124124 }
125- RWLockGuard ( & self . 0 , GuardType :: Write )
125+ RWLockWriteGuard ( & self . 0 )
126126 }
127127}
128128
129129#[ cfg( unix) ]
130- enum GuardType {
131- Read ,
132- Write ,
130+ pub struct RWLockReadGuard ( & ' static RWLock ) ;
131+
132+ #[ cfg( unix) ]
133+ impl Drop for RWLockReadGuard {
134+ fn drop ( & mut self ) {
135+ unsafe { self . 0 . read_unlock ( ) }
136+ }
133137}
134138
135139#[ cfg( unix) ]
136- pub struct RWLockGuard ( & ' static RWLock , GuardType ) ;
140+ pub struct RWLockWriteGuard ( & ' static RWLock ) ;
137141
138142#[ cfg( unix) ]
139- impl Drop for RWLockGuard {
143+ impl Drop for RWLockWriteGuard {
140144 fn drop ( & mut self ) {
141- unsafe {
142- match & self . 1 {
143- GuardType :: Read => self . 0 . read_unlock ( ) ,
144- GuardType :: Write => self . 0 . write_unlock ( ) ,
145- }
146- }
145+ unsafe { self . 0 . write_unlock ( ) }
147146 }
148147}
0 commit comments