]> Cypherpunks repositories - gostls13.git/commitdiff
internal/sysinfo: use sync.OnceValue for CPUName
authorTobias Klauser <tklauser@distanz.ch>
Fri, 3 May 2024 11:14:00 +0000 (13:14 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 3 May 2024 16:47:15 +0000 (16:47 +0000)
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>

src/internal/sysinfo/sysinfo.go

index 6a29ad2bc10ffeabd12dbe9938cd56dddd0d6318..ae0d5a440c02d59fc3a111595bcda4734e970fed 100644 (file)
@@ -11,25 +11,14 @@ import (
        "sync"
 )
 
-var cpuInfo struct {
-       once sync.Once
-       name string
-}
+var CPUName = sync.OnceValue(func() string {
+       if name := cpu.Name(); name != "" {
+               return name
+       }
 
-func CPUName() string {
-       cpuInfo.once.Do(func() {
-               // Try to get the information from internal/cpu.
-               if name := cpu.Name(); name != "" {
-                       cpuInfo.name = name
-                       return
-               }
+       if name := osCpuInfoName(); name != "" {
+               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 cpuInfo.name
-}
+       return ""
+})