pkg/sysinfo: unify NumCPU implementation
Use a single exported implementation, so that we can maintain the GoDoc string in one place, and use non-exported functions for the actual implementation (which were already in place). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
298d3aa8b8
commit
6919b9879b
4 changed files with 15 additions and 23 deletions
|
@ -1,13 +1,15 @@
|
|||
//go:build !linux && !windows
|
||||
// +build !linux,!windows
|
||||
|
||||
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// NumCPU returns the number of CPUs
|
||||
// NumCPU returns the number of CPUs. On Linux and Windows, it returns
|
||||
// the number of CPUs which are currently online. On other platforms,
|
||||
// it's the equivalent of [runtime.NumCPU].
|
||||
func NumCPU() int {
|
||||
if ncpu := numCPU(); ncpu > 0 {
|
||||
return ncpu
|
||||
}
|
||||
return runtime.NumCPU()
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
@ -23,11 +21,3 @@ func numCPU() int {
|
|||
|
||||
return mask.Count()
|
||||
}
|
||||
|
||||
// NumCPU returns the number of CPUs which are currently online
|
||||
func NumCPU() int {
|
||||
if ncpu := numCPU(); ncpu > 0 {
|
||||
return ncpu
|
||||
}
|
||||
return runtime.NumCPU()
|
||||
}
|
||||
|
|
9
pkg/sysinfo/numcpu_other.go
Normal file
9
pkg/sysinfo/numcpu_other.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
//go:build !linux && !windows
|
||||
// +build !linux,!windows
|
||||
|
||||
package sysinfo
|
||||
|
||||
func numCPU() int {
|
||||
// not implemented
|
||||
return 0
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
@ -35,11 +34,3 @@ func numCPU() int {
|
|||
ncpu := int(popcnt(uint64(mask)))
|
||||
return ncpu
|
||||
}
|
||||
|
||||
// NumCPU returns the number of CPUs which are currently online
|
||||
func NumCPU() int {
|
||||
if ncpu := numCPU(); ncpu > 0 {
|
||||
return ncpu
|
||||
}
|
||||
return runtime.NumCPU()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue