Use AcquireSRWLockExclusive::is_available() instead of an extra lookup.

This commit is contained in:
Mara Bos 2020-09-20 14:49:04 +02:00
parent 8b2bdfd453
commit 93310efdbe
1 changed files with 6 additions and 17 deletions

View File

@ -23,7 +23,6 @@ use crate::cell::{Cell, UnsafeCell};
use crate::mem::{self, MaybeUninit};
use crate::sync::atomic::{AtomicUsize, Ordering};
use crate::sys::c;
use crate::sys::compat;
pub struct Mutex {
// This is either directly an SRWLOCK (if supported), or a Box<Inner> otherwise.
@ -40,8 +39,8 @@ struct Inner {
#[derive(Clone, Copy)]
enum Kind {
SRWLock = 1,
CriticalSection = 2,
SRWLock,
CriticalSection,
}
#[inline]
@ -130,21 +129,11 @@ impl Mutex {
}
fn kind() -> Kind {
static KIND: AtomicUsize = AtomicUsize::new(0);
let val = KIND.load(Ordering::SeqCst);
if val == Kind::SRWLock as usize {
return Kind::SRWLock;
} else if val == Kind::CriticalSection as usize {
return Kind::CriticalSection;
if c::AcquireSRWLockExclusive::is_available() {
Kind::SRWLock
} else {
Kind::CriticalSection
}
let ret = match compat::lookup("kernel32", "AcquireSRWLockExclusive") {
None => Kind::CriticalSection,
Some(..) => Kind::SRWLock,
};
KIND.store(ret as usize, Ordering::SeqCst);
ret
}
pub struct ReentrantMutex {