pull/1839/head
Stefano Balzarotti 3 months ago
parent b4446224fc
commit 00a28a710e
No known key found for this signature in database
GPG Key ID: 7E7FC24DA4B9F8C9

@ -5,6 +5,7 @@ package cpu
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"unsafe" "unsafe"
@ -15,8 +16,10 @@ import (
"github.com/shirou/gopsutil/v4/internal/common" "github.com/shirou/gopsutil/v4/internal/common"
) )
var procGetNativeSystemInfo = common.Modkernel32.NewProc("GetNativeSystemInfo") var (
var getLogicalProcessorInformationEx = common.Modkernel32.NewProc("GetLogicalProcessorInformationEx") procGetNativeSystemInfo = common.Modkernel32.NewProc("GetNativeSystemInfo")
getLogicalProcessorInformationEx = common.Modkernel32.NewProc("GetLogicalProcessorInformationEx")
)
type win32_Processor struct { //nolint:revive //FIXME type win32_Processor struct { //nolint:revive //FIXME
Family uint16 Family uint16
@ -230,7 +233,7 @@ func getPhysicalCoreCount(ctx context.Context) (int, error) {
// First call to determine the required buffer size // First call to determine the required buffer size
_, _, err := getLogicalProcessorInformationEx.Call(uintptr(relationAll), 0, uintptr(unsafe.Pointer(&length))) _, _, err := getLogicalProcessorInformationEx.Call(uintptr(relationAll), 0, uintptr(unsafe.Pointer(&length)))
if err != nil && err != windows.ERROR_INSUFFICIENT_BUFFER { if err != nil && !errors.Is(err, windows.ERROR_INSUFFICIENT_BUFFER) {
return 0, fmt.Errorf("failed to get buffer size: %w", err) return 0, fmt.Errorf("failed to get buffer size: %w", err)
} }
@ -239,7 +242,7 @@ func getPhysicalCoreCount(ctx context.Context) (int, error) {
// Second call to retrieve the processor information // Second call to retrieve the processor information
_, _, err = getLogicalProcessorInformationEx.Call(uintptr(relationAll), uintptr(unsafe.Pointer(&buffer[0])), uintptr(unsafe.Pointer(&length))) _, _, err = getLogicalProcessorInformationEx.Call(uintptr(relationAll), uintptr(unsafe.Pointer(&buffer[0])), uintptr(unsafe.Pointer(&length)))
if err != nil && err != windows.NTE_OP_OK { if err != nil && !errors.Is(err, windows.NTE_OP_OK) {
return 0, fmt.Errorf("failed to get logical processor information: %w", err) return 0, fmt.Errorf("failed to get logical processor information: %w", err)
} }

Loading…
Cancel
Save