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

@@ -13,11 +13,11 @@ import (
"io"
"net/netip"
"sync"
"sync/atomic"
"time"
"go4.org/mem"
"golang.org/x/time/rate"
"tailscale.com/syncs"
"tailscale.com/types/key"
"tailscale.com/types/logger"
)
@@ -39,8 +39,8 @@ type Client struct {
rate *rate.Limiter // if non-nil, rate limiter to use
// Owned by Recv:
peeked int // bytes to discard on next Recv
readErr atomic.Value // of error; sticky (set by Recv)
peeked int // bytes to discard on next Recv
readErr syncs.AtomicValue[error] // sticky (set by Recv)
}
// ClientOpt is an option passed to NewClient.
@@ -445,7 +445,7 @@ func (c *Client) Recv() (m ReceivedMessage, err error) {
}
func (c *Client) recvTimeout(timeout time.Duration) (m ReceivedMessage, err error) {
readErr, _ := c.readErr.Load().(error)
readErr := c.readErr.Load()
if readErr != nil {
return nil, readErr
}

View File

@@ -27,7 +27,6 @@ import (
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
"go4.org/mem"
@@ -37,6 +36,7 @@ import (
"tailscale.com/net/netns"
"tailscale.com/net/tlsdial"
"tailscale.com/net/tshttpproxy"
"tailscale.com/syncs"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/logger"
@@ -69,7 +69,7 @@ type Client struct {
// by SetAddressFamilySelector. It's an atomic because it needs
// to be accessed by multiple racing routines started while
// Client.conn holds mu.
addrFamSelAtomic atomic.Value // of AddressFamilySelector
addrFamSelAtomic syncs.AtomicValue[AddressFamilySelector]
mu sync.Mutex
preferred bool