Skip to content

Commit fe6652f

Browse files
committed
Add SAFETY comments for mutex.rs
1 parent c1665e7 commit fe6652f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl Mutex {
6767
#[inline]
6868
pub unsafe fn init(&mut self) {}
6969
pub unsafe fn lock(&self) {
70+
// SAFETY: The caller must ensure that the mutex is not moved or copied
7071
unsafe {
7172
match kind() {
7273
Kind::SRWLock => c::AcquireSRWLockExclusive(raw(self)),
@@ -83,6 +84,7 @@ impl Mutex {
8384
}
8485
}
8586
pub unsafe fn try_lock(&self) -> bool {
87+
// SAFETY: The caller must ensure that the mutex is not moved or copied
8688
unsafe {
8789
match kind() {
8890
Kind::SRWLock => c::TryAcquireSRWLockExclusive(raw(self)) != 0,
@@ -102,6 +104,7 @@ impl Mutex {
102104
}
103105
}
104106
pub unsafe fn unlock(&self) {
107+
// SAFETY: The caller must ensure that the mutex is not moved or copied
105108
unsafe {
106109
match kind() {
107110
Kind::SRWLock => c::ReleaseSRWLockExclusive(raw(self)),
@@ -114,6 +117,7 @@ impl Mutex {
114117
}
115118
}
116119
pub unsafe fn destroy(&self) {
120+
// SAFETY: The caller must ensure that the mutex is not moved or copied
117121
unsafe {
118122
match kind() {
119123
Kind::SRWLock => {}
@@ -134,8 +138,10 @@ impl Mutex {
134138
unsafe {
135139
inner.remutex.init();
136140
}
137-
let inner = Box::into_raw(inner);
138-
141+
}
142+
143+
unsafe fn flag_locked(&self) -> bool {
144+
// SAFETY: The caller must ensure that the mutex is not moved or copied
139145
unsafe {
140146
match self.lock.compare_and_swap(0, inner as usize, Ordering::SeqCst) {
141147
0 => inner,

0 commit comments

Comments
 (0)