mirror of
https://github.com/moby/moby.git
synced 2026-07-07 23:28:37 +00:00
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>
24 lines
522 B
Go
24 lines
522 B
Go
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// numCPU queries the system for the count of threads available
|
|
// for use to this process.
|
|
//
|
|
// Issues two syscalls.
|
|
// Returns 0 on errors. Use |runtime.NumCPU| in that case.
|
|
func numCPU() int {
|
|
// Gets the affinity mask for a process: The very one invoking this function.
|
|
pid := unix.Getpid()
|
|
|
|
var mask unix.CPUSet
|
|
err := unix.SchedGetaffinity(pid, &mask)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
return mask.Count()
|
|
}
|