lockfree

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package lockfree provides lock-free data structures for high-performance concurrent processing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicCounter

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

AtomicCounter provides a lock-free counter for statistics

func NewAtomicCounter

func NewAtomicCounter() *AtomicCounter

NewAtomicCounter creates a new atomic counter

func (*AtomicCounter) Add

func (c *AtomicCounter) Add(delta uint64)

Add atomically adds a value to the counter

func (*AtomicCounter) Get

func (c *AtomicCounter) Get() uint64

Get returns the current value

func (*AtomicCounter) Increment

func (c *AtomicCounter) Increment()

Increment atomically increments the counter

func (*AtomicCounter) Reset

func (c *AtomicCounter) Reset()

Reset atomically resets the counter to zero

type MPMCQueue

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

MPMCQueue implements a lock-free multi-producer multi-consumer queue

func NewMPMCQueue

func NewMPMCQueue(capacity int) *MPMCQueue

NewMPMCQueue creates a new multi-producer multi-consumer queue

func (*MPMCQueue) Dequeue

func (q *MPMCQueue) Dequeue() (interface{}, bool)

Dequeue removes an item from the MPMC queue

func (*MPMCQueue) Enqueue

func (q *MPMCQueue) Enqueue(item interface{}) bool

Enqueue adds an item to the MPMC queue

type Queue

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

Queue implements a lock-free multi-producer single-consumer queue optimized for 100K+ records/sec throughput

func NewQueue

func NewQueue(capacity int) *Queue

NewQueue creates a new lock-free queue with given capacity Capacity must be a power of 2 for efficient masking

func (*Queue) Dequeue

func (q *Queue) Dequeue() (interface{}, bool)

Dequeue removes an item from the queue (single-consumer)

func (*Queue) Enqueue

func (q *Queue) Enqueue(item interface{}) bool

Enqueue adds an item to the queue (multi-producer safe)

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

IsEmpty returns true if the queue is empty

func (*Queue) IsFull

func (q *Queue) IsFull() bool

IsFull returns true if the queue is full

func (*Queue) Size

func (q *Queue) Size() int

Size returns the current number of items in the queue

type RingBuffer

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

RingBuffer implements a lock-free single-producer single-consumer ring buffer

func NewRingBuffer

func NewRingBuffer(capacity int) *RingBuffer

NewRingBuffer creates a new lock-free ring buffer

func (*RingBuffer) Available

func (rb *RingBuffer) Available() int

Available returns the number of bytes available to read

func (*RingBuffer) Free

func (rb *RingBuffer) Free() int

Free returns the number of bytes available to write

func (*RingBuffer) Read

func (rb *RingBuffer) Read(data []byte) int

Read reads data from the ring buffer

func (*RingBuffer) Write

func (rb *RingBuffer) Write(data []byte) int

Write writes data to the ring buffer

Jump to

Keyboard shortcuts

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