mpmc

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CacheLinePadSize = unsafe.Sizeof(cpu.CacheLinePad{})

CacheLinePadSize represents the CPU Cache Line Padding Size, compliant with the current running CPU Architect

View Source
const MaxUint32 = ^uint32(0)

MaxUint32 represents the maximal uint32 value

View Source
const MaxUint32_64 = uint64(^uint32(0))

MaxUint32_64 represents the maximal uint32 value

View Source
const MaxUint64 = ^uint64(0)

MaxUint64 represents the maximal uint64 value

Variables

View Source
var ErrQueueEmpty error

ErrQueueEmpty queue empty when dequeueing

View Source
var ErrQueueFull error

ErrQueueFull queue full when enqueueing

View Source
var ErrQueueNotReady error

ErrQueueNotReady queue not ready for enqueue or dequeue

View Source
var ErrRaced error

ErrRaced the exception raised if data racing

Functions

This section is empty.

Types

type Dbg

type Dbg interface {
	GetGetWaits() uint64
	GetPutWaits() uint64
	Debug(enabled bool) (lastState bool)
	ResetCounters()
}

Dbg exposes some internal fields for debugging

type Initializeable

type Initializeable[T any] interface {
	PreAlloc(index int) (newBlock T)
	CloneIn(srcBlock T, targetBlock *T)
	CloneOut(srcBlock *T) (targetBlock T)
}

Initializeable data item supports lighter-weight clone operations.

type Opt

type Opt[T any] func(rb *ringBuf[T])

Opt interface the functional options

func WithDebugMode

func WithDebugMode[T any](_ bool) Opt[T]

WithDebugMode enables the internal debug mode for more logging output, and collect the metrics for debugging

func WithItemInitializer

func WithItemInitializer[T any](initializeable Initializeable[T]) Opt[T]

WithItemInitializer provides your custom initializer for each data item.

type Queue

type Queue[T any] interface {
	Enqueue(item T) (err error)
	Dequeue() (item T, err error)
	// Cap returns the outer capacity of the ring buffer.
	Cap() uint32
	// CapReal returns the real (inner) capacity of the ring buffer.
	CapReal() uint32
	// Size returns the quantity of items in the ring buffer queue
	Size() uint32
	IsEmpty() (b bool)
	IsFull() (b bool)
	Reset()
}

Queue interface provides a set of standard queue operations

type RingBuffer

type RingBuffer[T any] interface {
	Close()

	Enqueue(item T) (err error)
	Dequeue() (item T, err error)
	// Cap returns the outer capacity of the ring buffer.
	Cap() uint32
	// CapReal returns the real (inner) capacity of the ring buffer.
	CapReal() uint32
	// Size returns the quantity of items in the ring buffer queue
	Size() uint32
	IsEmpty() (b bool)
	IsFull() (b bool)
	Reset()

	Put(item T) (err error)
	Get() (item T, err error)

	// Quantity returns the quantity of items in the ring buffer queue
	Quantity() uint32

	Debug(enabled bool) (lastState bool)

	ResetCounters()
}

RingBuffer interface provides a set of standard ring buffer operations

func New

func New[T any](capacity uint32, opts ...Opt[T]) (ringBuffer RingBuffer[T])

New returns the RingBuffer object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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