Skip to content

Commit ac5aa1d

Browse files
committed
Use Drop instead of destroy() for locks.
1 parent fb19760 commit ac5aa1d

File tree

24 files changed

+39
-87
lines changed

24 files changed

+39
-87
lines changed

library/std/src/sys/hermit/condvar.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ impl Condvar {
7070
mutex.lock();
7171
res == 0
7272
}
73+
}
7374

74-
pub unsafe fn destroy(&self) {
75-
let _ = abi::sem_destroy(self.sem1);
76-
let _ = abi::sem_destroy(self.sem2);
75+
impl Drop for Condvar {
76+
fn drop(&mut self) {
77+
unsafe {
78+
let _ = abi::sem_destroy(self.sem1);
79+
let _ = abi::sem_destroy(self.sem2);
80+
}
7781
}
7882
}

library/std/src/sys/hermit/mutex.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,4 @@ impl Mutex {
215215
}
216216
guard.locked
217217
}
218-
219-
#[inline]
220-
pub unsafe fn destroy(&self) {}
221218
}

library/std/src/sys/hermit/rwlock.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ impl RwLock {
8484
// FIXME: should only wake up one of these some of the time
8585
self.cond.notify_all();
8686
}
87-
88-
#[inline]
89-
pub unsafe fn destroy(&self) {
90-
self.lock.destroy();
91-
self.cond.destroy();
92-
}
9387
}
9488

9589
impl State {

library/std/src/sys/itron/condvar.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ impl Condvar {
117117
unsafe { mutex.lock() };
118118
success
119119
}
120-
121-
pub unsafe fn destroy(&self) {}
122120
}
123121

124122
mod waiter_queue {

library/std/src/sys/itron/mutex.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ impl Mutex {
6464
}
6565
}
6666
}
67+
}
6768

68-
pub unsafe fn destroy(&self) {
69+
impl Drop for Mutex {
70+
fn drop(&mut self) {
6971
if let Some(mtx) = self.mtx.get().map(|x| x.0) {
7072
expect_success_aborting(unsafe { abi::del_mtx(mtx) }, &"del_mtx");
7173
}

library/std/src/sys/sgx/condvar.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,4 @@ impl Condvar {
3838
unsafe { mutex.lock() };
3939
success
4040
}
41-
42-
#[inline]
43-
pub unsafe fn destroy(&self) {}
4441
}

library/std/src/sys/sgx/mutex.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,4 @@ impl Mutex {
5252
true
5353
}
5454
}
55-
56-
#[inline]
57-
pub unsafe fn destroy(&self) {}
5855
}

library/std/src/sys/sgx/rwlock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ impl RwLock {
168168
unsafe { self.__read_unlock(rguard, wguard) };
169169
}
170170
}
171-
172-
#[inline]
173-
pub unsafe fn destroy(&self) {}
174171
}
175172

176173
// The following functions are needed by libunwind. These symbols are named

library/std/src/sys/solid/rwlock.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ impl RwLock {
8282
let rwl = self.raw();
8383
expect_success_aborting(unsafe { abi::rwl_unl_rwl(rwl) }, &"rwl_unl_rwl");
8484
}
85+
}
8586

87+
impl Drop for RwLock {
8688
#[inline]
87-
pub unsafe fn destroy(&self) {
89+
fn drop(&mut self) {
8890
if let Some(rwl) = self.rwl.get().map(|x| x.0) {
8991
expect_success_aborting(unsafe { abi::rwl_del_rwl(rwl) }, &"rwl_del_rwl");
9092
}

library/std/src/sys/unix/locks/futex.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ impl Mutex {
2424
#[inline]
2525
pub unsafe fn init(&mut self) {}
2626

27-
#[inline]
28-
pub unsafe fn destroy(&self) {}
29-
3027
#[inline]
3128
pub unsafe fn try_lock(&self) -> bool {
3229
self.futex.compare_exchange(0, 1, Acquire, Relaxed).is_ok()
@@ -121,9 +118,6 @@ impl Condvar {
121118
#[inline]
122119
pub unsafe fn init(&mut self) {}
123120

124-
#[inline]
125-
pub unsafe fn destroy(&self) {}
126-
127121
// All the memory orderings here are `Relaxed`,
128122
// because synchronization is done by unlocking and locking the mutex.
129123

0 commit comments

Comments
 (0)