File tree 3 files changed +23
-6
lines changed
library/std/src/sys/windows
3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ use crate::sync::atomic::Ordering;
25
25
use crate :: sys:: c;
26
26
27
27
mod version;
28
- pub use version:: { is_windows_nt , supports_async_io } ;
28
+ pub use version:: * ;
29
29
30
30
// This uses a static initializer to preload some imported functions.
31
31
// The CRT (C runtime) executes static initializers before `main`
Original file line number Diff line number Diff line change @@ -2,12 +2,22 @@ use crate::sys::c;
2
2
3
3
static mut IS_NT : bool = true ;
4
4
static mut SUPPORTS_ASYNC_IO : bool = true ;
5
+ static mut SUPPORTS_TRY_ENTER_CRITICAL_SECTION : bool = true ;
5
6
6
7
pub fn init_windows_version_check ( ) {
7
- // according to old MSDN info, the high-order bit is set only on 95/98/ME.
8
8
unsafe {
9
- IS_NT = c:: GetVersion ( ) < 0x8000_0000 ;
10
- SUPPORTS_ASYNC_IO = IS_NT && c:: CancelIo :: option ( ) . is_some ( ) ;
9
+ let version = c:: GetVersion ( ) ;
10
+ let major = version as u8 ;
11
+
12
+ // according to old MSDN info, the high-order bit is set only on 95/98/ME.
13
+ let is_nt = version < 0x8000_0000 ;
14
+
15
+ IS_NT = is_nt;
16
+ SUPPORTS_ASYNC_IO = is_nt && c:: CancelIo :: option ( ) . is_some ( ) ;
17
+
18
+ // at least 9x exports TryEnterCriticalSection, but it doesn't work, so we need to check the
19
+ // version. MSDN specifies that the function is available on NT4 and later.
20
+ SUPPORTS_TRY_ENTER_CRITICAL_SECTION = is_nt && major >= 4 ;
11
21
} ;
12
22
}
13
23
@@ -22,3 +32,8 @@ pub fn is_windows_nt() -> bool {
22
32
pub fn supports_async_io ( ) -> bool {
23
33
unsafe { SUPPORTS_ASYNC_IO }
24
34
}
35
+
36
+ #[ inline( always) ]
37
+ pub fn supports_try_enter_critical_section ( ) -> bool {
38
+ unsafe { SUPPORTS_TRY_ENTER_CRITICAL_SECTION }
39
+ }
Original file line number Diff line number Diff line change 1
- use crate :: sys:: c ;
1
+ use crate :: sys:: { c , compat } ;
2
2
3
3
#[ derive( Debug , PartialEq ) ]
4
4
pub enum MutexKind {
@@ -15,7 +15,9 @@ pub static mut MUTEX_KIND: MutexKind = MutexKind::SrwLock;
15
15
pub fn init ( ) {
16
16
let kind = if c:: TryAcquireSRWLockExclusive :: option ( ) . is_some ( ) {
17
17
MutexKind :: SrwLock
18
- } else if c:: TryEnterCriticalSection :: option ( ) . is_some ( ) {
18
+ } else if compat:: supports_try_enter_critical_section ( )
19
+ && c:: TryEnterCriticalSection :: option ( ) . is_some ( )
20
+ {
19
21
MutexKind :: CriticalSection
20
22
} else {
21
23
MutexKind :: Legacy
You can’t perform that action at this time.
0 commit comments