buffer

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package buffer provides a high-performant lock free implementation of a circular buffer used by the profiling code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircularBuffer

type CircularBuffer struct {
	// contains filtered or unexported fields
}

CircularBuffer is a lock-free data structure that supports Push and Drain operations.

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 maintained either; that is, if A was pushed before B, the Drain operation may return an array with B before A. These restrictions are acceptable within gRPC's profiling, but if your use-case does not permit these relaxed constraints or if performance is not a primary concern, you should probably use a lock-based data structure such as internal/buffer.UnboundedBuffer.

func NewCircularBuffer

func NewCircularBuffer(size uint32) (*CircularBuffer, error)

NewCircularBuffer allocates a circular buffer of size size and returns a reference 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() []interface{}

Drain allocates and returns an array of things Pushed in to the circular buffer. 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(x interface{})

Push pushes an element in to the circular buffer. Guaranteed to complete in a finite number of steps (also lock-free). Does not guarantee that push order will be retained. Does not guarantee that the operation will succeed if a Drain operation concurrently begins execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL