github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/intervalmap/search_freepool_race.go (about) 1 // Code generated by "../gtl/generate.py --output=search_freepool_race.go --prefix=searcher --PREFIX=searcher -DELEM=*searcher --package=intervalmap ../gtl/randomized_freepool_race.go.tpl". DO NOT EDIT. 2 3 //go:build race 4 // +build race 5 6 package intervalmap 7 8 import "sync/atomic" 9 10 type searcherFreePool struct { 11 new func() *searcher 12 len int64 13 } 14 15 func NewsearcherFreePool(new func() *searcher, maxSize int) *searcherFreePool { 16 return &searcherFreePool{new: new} 17 } 18 19 func (p *searcherFreePool) Put(x *searcher) { 20 atomic.AddInt64(&p.len, -1) 21 } 22 23 func (p *searcherFreePool) Get() *searcher { 24 atomic.AddInt64(&p.len, 1) 25 return p.new() 26 } 27 28 func (p *searcherFreePool) ApproxLen() int { return int(atomic.LoadInt64(&p.len)) }