From c23451320cdf3429d7c5832641ad641d71606801 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 1 Dec 2023 11:32:10 +0100 Subject: [PATCH] Use ad-hoc struct type for clktck Also add a TODO comment to switch to sync.OnceValue once Go 1.21 is the oldest supported version. --- sysconf_netbsd.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sysconf_netbsd.go b/sysconf_netbsd.go index 325d4a6..40f6c34 100644 --- a/sysconf_netbsd.go +++ b/sysconf_netbsd.go @@ -25,10 +25,10 @@ const ( _POSIX2_UPE = -1 ) -var ( - clktck int64 - clktckOnce sync.Once -) +var clktck struct { + sync.Once + v int64 +} func sysconfPOSIX(name int) (int64, error) { // NetBSD does not define all _POSIX_* values used in sysconf_posix.go @@ -42,7 +42,6 @@ func sysconf(name int) (int64, error) { // Duplicate the relevant values here. switch name { - // 1003.1 case SC_ARG_MAX: return sysctl32("kern.argmax"), nil @@ -55,13 +54,14 @@ func sysconf(name int) (int64, error) { } return -1, nil case SC_CLK_TCK: - clktckOnce.Do(func() { - clktck = -1 + // TODO: use sync.OnceValue once Go 1.21 is the minimal supported version + clktck.Do(func() { + clktck.v = -1 if ci, err := unix.SysctlClockinfo("kern.clockrate"); err == nil { - clktck = int64(ci.Hz) + clktck.v = int64(ci.Hz) } }) - return clktck, nil + return clktck.v, nil case SC_NGROUPS_MAX: return sysctl32("kern.ngroups"), nil case SC_JOB_CONTROL: