File tree Expand file tree Collapse file tree 3 files changed +12
-12
lines changed
library/std/src/sys/windows Expand file tree Collapse file tree 3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -2477,11 +2477,11 @@ Windows.Win32.System.Pipes.PIPE_TYPE_BYTE
2477
2477
Windows.Win32.System.Pipes.PIPE_TYPE_MESSAGE
2478
2478
Windows.Win32.System.Pipes.PIPE_WAIT
2479
2479
Windows.Win32.System.SystemInformation.GetSystemDirectoryW
2480
- Windows.Win32.System.SystemInformation.GetSystemInfo
2481
2480
Windows.Win32.System.SystemInformation.GetSystemTimeAsFileTime
2482
2481
Windows.Win32.System.SystemInformation.GetWindowsDirectoryW
2483
2482
Windows.Win32.System.SystemInformation.PROCESSOR_ARCHITECTURE
2484
2483
Windows.Win32.System.SystemInformation.SYSTEM_INFO
2484
+ Windows.Win32.System.SystemServices.ALL_PROCESSOR_GROUPS
2485
2485
Windows.Win32.System.SystemServices.DLL_PROCESS_DETACH
2486
2486
Windows.Win32.System.SystemServices.DLL_THREAD_DETACH
2487
2487
Windows.Win32.System.SystemServices.EXCEPTION_MAXIMUM_PARAMETERS
@@ -2513,6 +2513,7 @@ Windows.Win32.System.Threading.DEBUG_PROCESS
2513
2513
Windows.Win32.System.Threading.DETACHED_PROCESS
2514
2514
Windows.Win32.System.Threading.ExitProcess
2515
2515
Windows.Win32.System.Threading.EXTENDED_STARTUPINFO_PRESENT
2516
+ Windows.Win32.System.Threading.GetActiveProcessorCount
2516
2517
Windows.Win32.System.Threading.GetCurrentProcess
2517
2518
Windows.Win32.System.Threading.GetCurrentProcessId
2518
2519
Windows.Win32.System.Threading.GetCurrentThread
Original file line number Diff line number Diff line change @@ -219,6 +219,10 @@ extern "system" {
219
219
pub fn FreeEnvironmentStringsW ( penv : PCWSTR ) -> BOOL ;
220
220
}
221
221
#[ link( name = "kernel32" ) ]
222
+ extern "system" {
223
+ pub fn GetActiveProcessorCount ( groupnumber : u16 ) -> u32 ;
224
+ }
225
+ #[ link( name = "kernel32" ) ]
222
226
extern "system" {
223
227
pub fn GetCommandLineW ( ) -> PCWSTR ;
224
228
}
@@ -338,10 +342,6 @@ extern "system" {
338
342
pub fn GetSystemDirectoryW ( lpbuffer : PWSTR , usize : u32 ) -> u32 ;
339
343
}
340
344
#[ link( name = "kernel32" ) ]
341
- extern "system" {
342
- pub fn GetSystemInfo ( lpsysteminfo : * mut SYSTEM_INFO ) -> ( ) ;
343
- }
344
- #[ link( name = "kernel32" ) ]
345
345
extern "system" {
346
346
pub fn GetSystemTimeAsFileTime ( lpsystemtimeasfiletime : * mut FILETIME ) -> ( ) ;
347
347
}
@@ -822,6 +822,7 @@ impl ::core::clone::Clone for ADDRINFOA {
822
822
pub const AF_INET : ADDRESS_FAMILY = 2u16 ;
823
823
pub const AF_INET6 : ADDRESS_FAMILY = 23u16 ;
824
824
pub const AF_UNSPEC : ADDRESS_FAMILY = 0u16 ;
825
+ pub const ALL_PROCESSOR_GROUPS : u32 = 65535u32 ;
825
826
#[ repr( C ) ]
826
827
pub union ARM64_NT_NEON128 {
827
828
pub Anonymous : ARM64_NT_NEON128_0 ,
Original file line number Diff line number Diff line change @@ -101,15 +101,13 @@ impl Thread {
101
101
102
102
pub fn available_parallelism ( ) -> io:: Result < NonZeroUsize > {
103
103
let res = unsafe {
104
- let mut sysinfo: c:: SYSTEM_INFO = crate :: mem:: zeroed ( ) ;
105
- c:: GetSystemInfo ( & mut sysinfo) ;
106
- sysinfo. dwNumberOfProcessors as usize
104
+ // FIXME: windows::Win32::System::SystemServices::ALL_PROCESSOR_GROUPS should be u16, not u32
105
+ // FIXME: if you need even more accurate result on 32-bit Windows with more, than 64 cores,
106
+ // consider implementing this using GetLogicalProcessorInformationEx
107
+ c:: GetActiveProcessorCount ( c:: ALL_PROCESSOR_GROUPS as u16 ) as usize
107
108
} ;
108
109
match res {
109
- 0 => Err ( io:: const_io_error!(
110
- io:: ErrorKind :: NotFound ,
111
- "The number of hardware threads is not known for the target platform" ,
112
- ) ) ,
110
+ 0 => Err ( io:: Error :: last_os_error ( ) ) ,
113
111
cpus => Ok ( unsafe { NonZeroUsize :: new_unchecked ( cpus) } ) ,
114
112
}
115
113
}
You can’t perform that action at this time.
0 commit comments