open-vault/vendor/github.com/DataDog/datadog-go/statsd/buffer_pool.go
Sam Salisbury b589fbfbd9
ci: switch to go1.12.12 on machine executors (#7703)
* ci: switch to go1.12.12 on machine executors

- This brings in recent ci changes from the release/1.2.x branch.

* go mod vendor

* ci: remove ent build tags

* ci: fix gopath

* go mod vendor

* ci: ensure yarn install

* ci: add debug commands

* ci: debugging

* ci: increment yarn cache; remove debugging

* ci: remove redundant yarn install
2019-11-06 13:15:06 +00:00

41 lines
834 B
Go

package statsd
type bufferPool struct {
pool chan *statsdBuffer
bufferMaxSize int
bufferMaxElements int
}
func newBufferPool(poolSize, bufferMaxSize, bufferMaxElements int) *bufferPool {
p := &bufferPool{
pool: make(chan *statsdBuffer, poolSize),
bufferMaxSize: bufferMaxSize,
bufferMaxElements: bufferMaxElements,
}
for i := 0; i < poolSize; i++ {
p.addNewBuffer()
}
return p
}
func (p *bufferPool) addNewBuffer() {
p.pool <- newStatsdBuffer(p.bufferMaxSize, p.bufferMaxElements)
}
func (p *bufferPool) borrowBuffer() *statsdBuffer {
select {
case b := <-p.pool:
return b
default:
return newStatsdBuffer(p.bufferMaxSize, p.bufferMaxElements)
}
}
func (p *bufferPool) returnBuffer(buffer *statsdBuffer) {
buffer.reset()
select {
case p.pool <- buffer:
default:
}
}