github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/gtl/tests/string_freepool_race.go (about)

     1  // Code generated by "../generate.py --output=string_freepool_race.go --prefix=strings -DELEM=[]string --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 StringsFreePool struct {
    11  	new func() []string
    12  	len int64
    13  }
    14  
    15  func NewStringsFreePool(new func() []string, maxSize int) *StringsFreePool {
    16  	return &StringsFreePool{new: new}
    17  }
    18  
    19  func (p *StringsFreePool) Put(x []string) {
    20  	atomic.AddInt64(&p.len, -1)
    21  }
    22  
    23  func (p *StringsFreePool) Get() []string {
    24  	atomic.AddInt64(&p.len, 1)
    25  	return p.new()
    26  }
    27  
    28  func (p *StringsFreePool) ApproxLen() int { return int(atomic.LoadInt64(&p.len)) }