mirror of
https://github.com/golang/go
synced 2024-11-15 02:10:21 -07:00
internal/sysinfo: use sync.OnceValue for CPUName
Change-Id: I0f3ae97f2bd5ff3f533c5bf4570a8cda8b92b16a Reviewed-on: https://go-review.googlesource.com/c/go/+/582836 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
parent
44e48c7e6c
commit
0bc093a1aa
@ -11,25 +11,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cpuInfo struct {
|
var CPUName = sync.OnceValue(func() string {
|
||||||
once sync.Once
|
if name := cpu.Name(); name != "" {
|
||||||
name string
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func CPUName() string {
|
if name := osCpuInfoName(); name != "" {
|
||||||
cpuInfo.once.Do(func() {
|
return name
|
||||||
// Try to get the information from internal/cpu.
|
}
|
||||||
if name := cpu.Name(); name != "" {
|
|
||||||
cpuInfo.name = name
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(martisch): use /proc/cpuinfo and /sys/devices/system/cpu/ on Linux as fallback.
|
return ""
|
||||||
if name := osCpuInfoName(); name != "" {
|
})
|
||||||
cpuInfo.name = name
|
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return cpuInfo.name
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user