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>
This commit is contained in:
Brad Fitzpatrick
2022-08-30 07:43:11 -07:00
committed by Jason A. Donenfeld
parent d1d08426b2
commit b51010ba13
20 changed files with 156 additions and 288 deletions

View File

@@ -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()
}