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