buffer
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package buffer provides a high-performant lock free implementation of acircular buffer used by the profiling code.
Index¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeCircularBuffer¶
type CircularBuffer struct {// contains filtered or unexported fields}CircularBuffer is a lock-free data structure that supports Push and Drainoperations.
Note that CircularBuffer is built for performance more than reliability.That is, some Push operations may fail without retries in some situations(such as during a Drain operation). Order of pushes is not maintainedeither; that is, if A was pushed before B, the Drain operation may return anarray with B before A. These restrictions are acceptable within gRPC'sprofiling, but if your use-case does not permit these relaxed constraintsor if performance is not a primary concern, you should probably use alock-based data structure such as internal/buffer.UnboundedBuffer.
funcNewCircularBuffer¶
func NewCircularBuffer(sizeuint32) (*CircularBuffer,error)
NewCircularBuffer allocates a circular buffer of size size and returns areference to the struct. Only circular buffers of size 2^k are allowed(saves us from having to do expensive modulo operations).
func (*CircularBuffer)Drain¶
func (cb *CircularBuffer) Drain() []any
Drain allocates and returns an array of things Pushed in to the circularbuffer. Push order is not maintained; that is, if B was Pushed after A,drain may return B at a lower index than A in the returned array.
func (*CircularBuffer)Push¶
func (cb *CircularBuffer) Push(xany)
Push pushes an element in to the circular buffer. Guaranteed to complete ina finite number of steps (also lock-free). Does not guarantee that pushorder will be retained. Does not guarantee that the operation will succeedif a Drain operation concurrently begins execution.