Skip to content

Commit 98c8e28

Browse files
committed
Use sync.OnceValue to implement hasSMEDarwin()
Signed-off-by: Jan Dubois <[email protected]>
1 parent d6585bc commit 98c8e28

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

pkg/limayaml/defaults.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,18 +1174,7 @@ func IsAccelOS() bool {
11741174
return false
11751175
}
11761176

1177-
var (
1178-
hasSMEDarwin bool
1179-
hasSMEDarwinOnce sync.Once
1180-
)
1181-
1182-
func init() {
1183-
hasSMEDarwinOnce.Do(func() {
1184-
hasSMEDarwin = hasSMEDarwinFn()
1185-
})
1186-
}
1187-
1188-
func hasSMEDarwinFn() bool {
1177+
var hasSMEDarwin = sync.OnceValue(func() bool {
11891178
if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
11901179
return false
11911180
}
@@ -1195,12 +1184,12 @@ func hasSMEDarwinFn() bool {
11951184
logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME")
11961185
}
11971186
return s == "1"
1198-
}
1187+
})
11991188

12001189
func HasHostCPU() bool {
12011190
switch runtime.GOOS {
12021191
case "darwin":
1203-
if hasSMEDarwin {
1192+
if hasSMEDarwin() {
12041193
// SME is available since Apple M4 running macOS 15.2.
12051194
//
12061195
// However, QEMU is not ready to handle SME yet.

0 commit comments

Comments
 (0)