Skip to content

Commit 93310ef

Browse files
committed
Use AcquireSRWLockExclusive::is_available() instead of an extra lookup.
1 parent 8b2bdfd commit 93310ef

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::cell::{Cell, UnsafeCell};
2323
use crate::mem::{self, MaybeUninit};
2424
use crate::sync::atomic::{AtomicUsize, Ordering};
2525
use crate::sys::c;
26-
use crate::sys::compat;
2726

2827
pub struct Mutex {
2928
// This is either directly an SRWLOCK (if supported), or a Box<Inner> otherwise.
@@ -40,8 +39,8 @@ struct Inner {
4039

4140
#[derive(Clone, Copy)]
4241
enum Kind {
43-
SRWLock = 1,
44-
CriticalSection = 2,
42+
SRWLock,
43+
CriticalSection,
4544
}
4645

4746
#[inline]
@@ -130,21 +129,11 @@ impl Mutex {
130129
}
131130

132131
fn kind() -> Kind {
133-
static KIND: AtomicUsize = AtomicUsize::new(0);
134-
135-
let val = KIND.load(Ordering::SeqCst);
136-
if val == Kind::SRWLock as usize {
137-
return Kind::SRWLock;
138-
} else if val == Kind::CriticalSection as usize {
139-
return Kind::CriticalSection;
132+
if c::AcquireSRWLockExclusive::is_available() {
133+
Kind::SRWLock
134+
} else {
135+
Kind::CriticalSection
140136
}
141-
142-
let ret = match compat::lookup("kernel32", "AcquireSRWLockExclusive") {
143-
None => Kind::CriticalSection,
144-
Some(..) => Kind::SRWLock,
145-
};
146-
KIND.store(ret as usize, Ordering::SeqCst);
147-
ret
148137
}
149138

150139
pub struct ReentrantMutex {

0 commit comments

Comments
 (0)