all: use any in place of interface{}

Enabled by using Go 1.18. A bit less verbose.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2022-03-16 16:40:24 -07:00
parent 42c9af45e1
commit 46826fc4e5
4 changed files with 15 additions and 15 deletions

View File

@@ -18,13 +18,13 @@ type WaitPool struct {
max uint32
}
func NewWaitPool(max uint32, new func() interface{}) *WaitPool {
func NewWaitPool(max uint32, new func() any) *WaitPool {
p := &WaitPool{pool: sync.Pool{New: new}, max: max}
p.cond = sync.Cond{L: &p.lock}
return p
}
func (p *WaitPool) Get() interface{} {
func (p *WaitPool) Get() any {
if p.max != 0 {
p.lock.Lock()
for atomic.LoadUint32(&p.count) >= p.max {
@@ -36,7 +36,7 @@ func (p *WaitPool) Get() interface{} {
return p.pool.Get()
}
func (p *WaitPool) Put(x interface{}) {
func (p *WaitPool) Put(x any) {
p.pool.Put(x)
if p.max == 0 {
return
@@ -46,13 +46,13 @@ func (p *WaitPool) Put(x interface{}) {
}
func (device *Device) PopulatePools() {
device.pool.messageBuffers = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
device.pool.messageBuffers = NewWaitPool(PreallocatedBuffersPerPool, func() any {
return new([MaxMessageSize]byte)
})
device.pool.inboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
device.pool.inboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() any {
return new(QueueInboundElement)
})
device.pool.outboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
device.pool.outboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() any {
return new(QueueOutboundElement)
})
}