all: use syncs.AtomicValue

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-08-04 10:43:49 -07:00
committed by Maisem Ali
parent b75f81ec00
commit a9f6cd41fd
23 changed files with 97 additions and 101 deletions

View File

@@ -9,7 +9,8 @@ import (
"os"
"runtime"
"strconv"
"sync/atomic"
"tailscale.com/syncs"
)
type Distro string
@@ -28,14 +29,14 @@ const (
WDMyCloud = Distro("wdmycloud")
)
var distroAtomic atomic.Value // of Distro
var distroAtomic syncs.AtomicValue[Distro]
// Get returns the current distro, or the empty string if unknown.
func Get() Distro {
d, ok := distroAtomic.Load().(Distro)
if ok {
if d, ok := distroAtomic.LoadOk(); ok {
return d
}
var d Distro
switch runtime.GOOS {
case "linux":
d = linuxDistro()

View File

@@ -9,7 +9,8 @@ import (
"path/filepath"
"runtime"
"strings"
"sync/atomic"
"tailscale.com/syncs"
)
// IsMobile reports whether this is a mobile client build.
@@ -43,7 +44,7 @@ func IsSandboxedMacOS() bool {
return strings.HasSuffix(exe, "/Contents/MacOS/Tailscale")
}
var isMacSysExt atomic.Value // of bool
var isMacSysExt syncs.AtomicValue[bool]
// IsMacSysExt whether this binary is from the standalone "System
// Extension" (a.k.a. "macsys") version of Tailscale for macOS.
@@ -51,7 +52,7 @@ func IsMacSysExt() bool {
if runtime.GOOS != "darwin" {
return false
}
if b, ok := isMacSysExt.Load().(bool); ok {
if b, ok := isMacSysExt.LoadOk(); ok {
return b
}
exe, err := os.Executable()