mirror of
https://github.com/golang/go
synced 2024-11-15 02:20:32 -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"
|
||||
)
|
||||
|
||||
var cpuInfo struct {
|
||||
once sync.Once
|
||||
name string
|
||||
}
|
||||
|
||||
func CPUName() string {
|
||||
cpuInfo.once.Do(func() {
|
||||
// Try to get the information from internal/cpu.
|
||||
var CPUName = sync.OnceValue(func() string {
|
||||
if name := cpu.Name(); name != "" {
|
||||
cpuInfo.name = name
|
||||
return
|
||||
return name
|
||||
}
|
||||
|
||||
// TODO(martisch): use /proc/cpuinfo and /sys/devices/system/cpu/ on Linux as fallback.
|
||||
if name := osCpuInfoName(); name != "" {
|
||||
cpuInfo.name = name
|
||||
return
|
||||
return name
|
||||
}
|
||||
})
|
||||
|
||||
return cpuInfo.name
|
||||
}
|
||||
return ""
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user