github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/gtl/randomized_freepool_race.go.tpl (about) 1 // +build race 2 3 package PACKAGE 4 5 import "sync/atomic" 6 7 type ZZFreePool struct { 8 new func() ELEM 9 len int64 10 } 11 12 func NewZZFreePool(new func() ELEM, maxSize int) *ZZFreePool { 13 return &ZZFreePool{new: new} 14 } 15 16 func (p *ZZFreePool) Put(x ELEM) { 17 atomic.AddInt64(&p.len, -1) 18 } 19 20 func (p *ZZFreePool) Get() ELEM { 21 atomic.AddInt64(&p.len, 1) 22 return p.new() 23 } 24 25 func (p *ZZFreePool) ApproxLen() int { return int(atomic.LoadInt64(&p.len)) }