about summary refs log tree commit diff
path: root/library/std/src/sys_common
diff options
context:
space:
mode:
authorThe8472 <git@infinite-source.de>2021-02-09 18:49:29 +0100
committerThe8472 <git@infinite-source.de>2021-02-09 19:13:21 +0100
commit4fc181dd62f38c7b424e5261756a2f01ded68a5b (patch)
tree4e7508d182ea51d434b1ec53fed5b0df6f20d9e7 /library/std/src/sys_common
parent44abad5b12afa58b9f495593f1c8b090e644fd7e (diff)
downloadrust-4fc181dd62f38c7b424e5261756a2f01ded68a5b.tar.gz
rust-4fc181dd62f38c7b424e5261756a2f01ded68a5b.zip
split guard into read and write types
Diffstat (limited to 'library/std/src/sys_common')
-rw-r--r--library/std/src/sys_common/rwlock.rs29
1 files changed, 14 insertions, 15 deletions
diff --git a/library/std/src/sys_common/rwlock.rs b/library/std/src/sys_common/rwlock.rs
index cc13771009f..41e8ad77294 100644
--- a/library/std/src/sys_common/rwlock.rs
+++ b/library/std/src/sys_common/rwlock.rs
@@ -102,13 +102,13 @@ impl StaticRWLock {
     ///
     /// The lock is automatically unlocked when the returned guard is dropped.
     #[inline]
-    pub fn read_with_guard(&'static self) -> RWLockGuard {
+    pub fn read_with_guard(&'static self) -> RWLockReadGuard {
         // Safety: All methods require static references, therefore self
         // cannot be moved between invocations.
         unsafe {
             self.0.read();
         }
-        RWLockGuard(&self.0, GuardType::Read)
+        RWLockReadGuard(&self.0)
     }
 
     /// Acquires write access to the underlying lock, blocking the current thread
@@ -116,33 +116,32 @@ impl StaticRWLock {
     ///
     /// The lock is automatically unlocked when the returned guard is dropped.
     #[inline]
-    pub fn write_with_guard(&'static self) -> RWLockGuard {
+    pub fn write_with_guard(&'static self) -> RWLockWriteGuard {
         // Safety: All methods require static references, therefore self
         // cannot be moved between invocations.
         unsafe {
             self.0.write();
         }
-        RWLockGuard(&self.0, GuardType::Write)
+        RWLockWriteGuard(&self.0)
     }
 }
 
 #[cfg(unix)]
-enum GuardType {
-    Read,
-    Write,
+pub struct RWLockReadGuard(&'static RWLock);
+
+#[cfg(unix)]
+impl Drop for RWLockReadGuard {
+    fn drop(&mut self) {
+        unsafe { self.0.read_unlock() }
+    }
 }
 
 #[cfg(unix)]
-pub struct RWLockGuard(&'static RWLock, GuardType);
+pub struct RWLockWriteGuard(&'static RWLock);
 
 #[cfg(unix)]
-impl Drop for RWLockGuard {
+impl Drop for RWLockWriteGuard {
     fn drop(&mut self) {
-        unsafe {
-            match &self.1 {
-                GuardType::Read => self.0.read_unlock(),
-                GuardType::Write => self.0.write_unlock(),
-            }
-        }
+        unsafe { self.0.write_unlock() }
     }
 }