about summary refs log tree commit diff
path: root/library/std/src/sys/unix/locks/pthread_mutex.rs
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2022-06-03 16:45:47 +0200
committerMara Bos <m-ou.se@m-ou.se>2022-06-03 16:45:47 +0200
commitac5aa1ded529cd8317b351ba952ff9cd78b1e172 (patch)
tree209ea71e0de957f31459e3a1d97c0ef2f074d1bb /library/std/src/sys/unix/locks/pthread_mutex.rs
parentfb1976011e3df96b5d3eccd6b2f4e51ef7dc8f16 (diff)
downloadrust-ac5aa1ded529cd8317b351ba952ff9cd78b1e172.tar.gz
rust-ac5aa1ded529cd8317b351ba952ff9cd78b1e172.zip
Use Drop instead of destroy() for locks.
Diffstat (limited to 'library/std/src/sys/unix/locks/pthread_mutex.rs')
-rw-r--r--library/std/src/sys/unix/locks/pthread_mutex.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/locks/pthread_mutex.rs b/library/std/src/sys/unix/locks/pthread_mutex.rs
index 76840ce74dd..13a234668af 100644
--- a/library/std/src/sys/unix/locks/pthread_mutex.rs
+++ b/library/std/src/sys/unix/locks/pthread_mutex.rs
@@ -73,13 +73,13 @@ impl Mutex {
     }
     #[inline]
     #[cfg(not(target_os = "dragonfly"))]
-    pub unsafe fn destroy(&self) {
+    unsafe fn destroy(&mut self) {
         let r = libc::pthread_mutex_destroy(self.inner.get());
         debug_assert_eq!(r, 0);
     }
     #[inline]
     #[cfg(target_os = "dragonfly")]
-    pub unsafe fn destroy(&self) {
+    unsafe fn destroy(&mut self) {
         let r = libc::pthread_mutex_destroy(self.inner.get());
         // On DragonFly pthread_mutex_destroy() returns EINVAL if called on a
         // mutex that was just initialized with libc::PTHREAD_MUTEX_INITIALIZER.
@@ -89,6 +89,13 @@ impl Mutex {
     }
 }
 
+impl Drop for Mutex {
+    #[inline]
+    fn drop(&mut self) {
+        unsafe { self.destroy() };
+    }
+}
+
 pub(super) struct PthreadMutexAttr<'a>(pub &'a mut MaybeUninit<libc::pthread_mutexattr_t>);
 
 impl Drop for PthreadMutexAttr<'_> {