ringbuf

package
v0.0.0-...-c8fc2fc Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxEntries *prometheus.GaugeVec
View Source
var ReadsBlocked *prometheus.CounterVec
View Source
var UsedEntries *prometheus.GaugeVec
View Source
var WriteEntries *prometheus.HistogramVec
View Source
var WritesBlocked *prometheus.CounterVec

Functions

func InitMetrics

func InitMetrics(namespace string, constLabels prometheus.Labels, labelNames []string)

Types

type Entry

type Entry interface{}

type EntryList

type EntryList []Entry

type NewEntryF

type NewEntryF func() interface{}

type Ring

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

Ring is a classic generic ring buffer on top of a fixed-sized slice. It is thread-safe.

func New

func New(count int, newf NewEntryF, desc string, labels prometheus.Labels) *Ring

New allocates a new Ring instance, with capacity for count entries. If newf is non-nil, it is called count times to pre-allocate the entries. labels are attached to the prometheus metrics, and desc is added as an extra label. N.B. InitMetrics must be called before the first New call.

func (*Ring) Close

func (r *Ring) Close()

Close closes the ring buffer, and causes all blocked readers/writers to be notified.

func (*Ring) Read

func (r *Ring) Read(entries EntryList, block bool) (int, bool)

Read copies entries from the internal ring buffer. If block is true, then Read will block until it is able to read at least one entry (or the Ring is closed). Otherwise it will return immediately if there's no entries available for reading. Returns the number of entries read, or -1 if the RingBuf is closed, and a bool indicating if the read blocked.

func (*Ring) Write

func (r *Ring) Write(entries EntryList, block bool) (int, bool)

Write copies entries to the internal ring buffer. If block is true, then Write will block until it is able to write at least one entry (or the Ring is closed). Otherwise it will return immediately if there's on space left for writing. Returns the number of entries written, or -1 if the RingBuf is closed, and a bool indicating if the write blocked.

Jump to

Keyboard shortcuts

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