summaryrefslogtreecommitdiffhomepage
path: root/device/pools.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2022-08-30 07:43:11 -0700
committerJason A. Donenfeld <Jason@zx2c4.com>2022-09-04 12:57:30 +0200
commitb51010ba13f0a3e59808fbdb1566cd2c6b834b95 (patch)
tree37a6753e5604c13f7141bd5613b0ab80e7b794f7 /device/pools.go
parentd1d08426b27b57990b1ee6782794f56d2c002aa3 (diff)
all: use Go 1.19 and its atomic types
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/pools.go')
-rw-r--r--device/pools.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/device/pools.go b/device/pools.go
index f40477b..9da0f79 100644
--- a/device/pools.go
+++ b/device/pools.go
@@ -14,7 +14,7 @@ type WaitPool struct {
pool sync.Pool
cond sync.Cond
lock sync.Mutex
- count uint32
+ count atomic.Uint32
max uint32
}
@@ -27,10 +27,10 @@ func NewWaitPool(max uint32, new func() any) *WaitPool {
func (p *WaitPool) Get() any {
if p.max != 0 {
p.lock.Lock()
- for atomic.LoadUint32(&p.count) >= p.max {
+ for p.count.Load() >= p.max {
p.cond.Wait()
}
- atomic.AddUint32(&p.count, 1)
+ p.count.Add(1)
p.lock.Unlock()
}
return p.pool.Get()
@@ -41,7 +41,7 @@ func (p *WaitPool) Put(x any) {
if p.max == 0 {
return
}
- atomic.AddUint32(&p.count, ^uint32(0))
+ p.count.Add(^uint32(0))
p.cond.Signal()
}