Skip to content

Commit

Permalink
Use ad-hoc struct type for clktck
Browse files Browse the repository at this point in the history
Also add a TODO comment to switch to sync.OnceValue once Go 1.21 is the
oldest supported version.
  • Loading branch information
tklauser committed Dec 1, 2023
1 parent de5ed6f commit c234513
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sysconf_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit c234513

Please sign in to comment.