diff options
Diffstat (limited to 'library/std/src/sys/unix/locks')
| -rw-r--r-- | library/std/src/sys/unix/locks/futex.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/futex_rwlock.rs | 3 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/pthread_condvar.rs | 11 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/pthread_mutex.rs | 11 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/pthread_rwlock.rs | 9 |
5 files changed, 26 insertions, 14 deletions
diff --git a/library/std/src/sys/unix/locks/futex.rs b/library/std/src/sys/unix/locks/futex.rs index 7a63af1ad7c..5731ce44286 100644 --- a/library/std/src/sys/unix/locks/futex.rs +++ b/library/std/src/sys/unix/locks/futex.rs @@ -25,9 +25,6 @@ impl Mutex { pub unsafe fn init(&mut self) {} #[inline] - pub unsafe fn destroy(&self) {} - - #[inline] pub unsafe fn try_lock(&self) -> bool { self.futex.compare_exchange(0, 1, Acquire, Relaxed).is_ok() } @@ -121,9 +118,6 @@ impl Condvar { #[inline] pub unsafe fn init(&mut self) {} - #[inline] - pub unsafe fn destroy(&self) {} - // All the memory orderings here are `Relaxed`, // because synchronization is done by unlocking and locking the mutex. diff --git a/library/std/src/sys/unix/locks/futex_rwlock.rs b/library/std/src/sys/unix/locks/futex_rwlock.rs index 5ff1aba7974..1f902f50587 100644 --- a/library/std/src/sys/unix/locks/futex_rwlock.rs +++ b/library/std/src/sys/unix/locks/futex_rwlock.rs @@ -64,9 +64,6 @@ impl RwLock { } #[inline] - pub unsafe fn destroy(&self) {} - - #[inline] pub unsafe fn try_read(&self) -> bool { self.state .fetch_update(Acquire, Relaxed, |s| is_read_lockable(s).then(|| s + READ_LOCKED)) diff --git a/library/std/src/sys/unix/locks/pthread_condvar.rs b/library/std/src/sys/unix/locks/pthread_condvar.rs index 099aa68706f..2488d5a4e06 100644 --- a/library/std/src/sys/unix/locks/pthread_condvar.rs +++ b/library/std/src/sys/unix/locks/pthread_condvar.rs @@ -179,14 +179,14 @@ impl Condvar { #[inline] #[cfg(not(target_os = "dragonfly"))] - pub unsafe fn destroy(&self) { + unsafe fn destroy(&mut self) { let r = libc::pthread_cond_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_cond_destroy(self.inner.get()); // On DragonFly pthread_cond_destroy() returns EINVAL if called on // a condvar that was just initialized with @@ -195,3 +195,10 @@ impl Condvar { debug_assert!(r == 0 || r == libc::EINVAL); } } + +impl Drop for Condvar { + #[inline] + fn drop(&mut self) { + unsafe { self.destroy() }; + } +} 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<'_> { diff --git a/library/std/src/sys/unix/locks/pthread_rwlock.rs b/library/std/src/sys/unix/locks/pthread_rwlock.rs index 11a0c0457cd..4f7f4783ad8 100644 --- a/library/std/src/sys/unix/locks/pthread_rwlock.rs +++ b/library/std/src/sys/unix/locks/pthread_rwlock.rs @@ -128,7 +128,7 @@ impl RwLock { self.raw_unlock(); } #[inline] - pub unsafe fn destroy(&self) { + unsafe fn destroy(&mut self) { let r = libc::pthread_rwlock_destroy(self.inner.get()); // On DragonFly pthread_rwlock_destroy() returns EINVAL if called on a // rwlock that was just initialized with @@ -141,3 +141,10 @@ impl RwLock { } } } + +impl Drop for RwLock { + #[inline] + fn drop(&mut self) { + unsafe { self.destroy() }; + } +} |
