@@ -102,47 +102,46 @@ impl StaticRWLock {
102
102
///
103
103
/// The lock is automatically unlocked when the returned guard is dropped.
104
104
#[ inline]
105
- pub fn read_with_guard ( & ' static self ) -> RWLockGuard {
105
+ pub fn read_with_guard ( & ' static self ) -> RWLockReadGuard {
106
106
// Safety: All methods require static references, therefore self
107
107
// cannot be moved between invocations.
108
108
unsafe {
109
109
self . 0 . read ( ) ;
110
110
}
111
- RWLockGuard ( & self . 0 , GuardType :: Read )
111
+ RWLockReadGuard ( & self . 0 )
112
112
}
113
113
114
114
/// Acquires write access to the underlying lock, blocking the current thread
115
115
/// to do so.
116
116
///
117
117
/// The lock is automatically unlocked when the returned guard is dropped.
118
118
#[ inline]
119
- pub fn write_with_guard ( & ' static self ) -> RWLockGuard {
119
+ pub fn write_with_guard ( & ' static self ) -> RWLockWriteGuard {
120
120
// Safety: All methods require static references, therefore self
121
121
// cannot be moved between invocations.
122
122
unsafe {
123
123
self . 0 . write ( ) ;
124
124
}
125
- RWLockGuard ( & self . 0 , GuardType :: Write )
125
+ RWLockWriteGuard ( & self . 0 )
126
126
}
127
127
}
128
128
129
129
#[ 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
+ }
133
137
}
134
138
135
139
#[ cfg( unix) ]
136
- pub struct RWLockGuard ( & ' static RWLock , GuardType ) ;
140
+ pub struct RWLockWriteGuard ( & ' static RWLock ) ;
137
141
138
142
#[ cfg( unix) ]
139
- impl Drop for RWLockGuard {
143
+ impl Drop for RWLockWriteGuard {
140
144
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 ( ) }
147
146
}
148
147
}
0 commit comments