github.com/grailbio/base@v0.0.11/gtl/tests/int_freepool_race.go (about) 1 // Code generated by "../generate.py --output=int_freepool_race.go --prefix=ints -DELEM=[]int --package=tests ../randomized_freepool_race.go.tpl". DO NOT EDIT. 2 3 //go:build race 4 // +build race 5 6 package tests 7 8 import "sync/atomic" 9 10 type IntsFreePool struct { 11 new func() []int 12 len int64 13 } 14 15 func NewIntsFreePool(new func() []int, maxSize int) *IntsFreePool { 16 return &IntsFreePool{new: new} 17 } 18 19 func (p *IntsFreePool) Put(x []int) { 20 atomic.AddInt64(&p.len, -1) 21 } 22 23 func (p *IntsFreePool) Get() []int { 24 atomic.AddInt64(&p.len, 1) 25 return p.new() 26 } 27 28 func (p *IntsFreePool) ApproxLen() int { return int(atomic.LoadInt64(&p.len)) }