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

@ -14,8 +14,9 @@ import (
"os"
"runtime"
"strings"
"sync/atomic"
"time"
"tailscale.com/syncs"
)
// CommonNonRoutableMetadataIP is the IP address of the metadata server
@ -69,15 +70,14 @@ func (c Cloud) HasInternalTLD() bool {
return false
}
var cloudAtomic atomic.Value // of Cloud
var cloudAtomic syncs.AtomicValue[Cloud]
// Get returns the current cloud, or the empty string if unknown.
func Get() Cloud {
c, ok := cloudAtomic.Load().(Cloud)
if ok {
if c, ok := cloudAtomic.LoadOk(); ok {
return c
}
c = getCloud()
c := getCloud()
cloudAtomic.Store(c) // even if empty
return c
}