diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2022-06-03 16:45:47 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2022-06-03 16:45:47 +0200 |
| commit | ac5aa1ded529cd8317b351ba952ff9cd78b1e172 (patch) | |
| tree | 209ea71e0de957f31459e3a1d97c0ef2f074d1bb /library/std/src/sys/unix/locks/pthread_mutex.rs | |
| parent | fb1976011e3df96b5d3eccd6b2f4e51ef7dc8f16 (diff) | |
| download | rust-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.rs | 11 |
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<'_> { |
