lockfree

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Lock-free data structures

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue is a lock-free queue with a single consumer and multiple producers.

func NewQueue

func NewQueue[T any]() *Queue[T]

(AI GENERATED DESCRIPTION): Creates a new empty concurrent queue by initializing a sentinel head node and setting both the head and tail pointers to that node.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() (val T, ok bool)

(AI GENERATED DESCRIPTION): Pops and returns the front value of the queue, yielding `ok=false` if the queue is empty.

func (*Queue[T]) Push

func (q *Queue[T]) Push(v T)

(AI GENERATED DESCRIPTION): Adds a new element to the end of the lock‑free queue, atomically updating the tail pointer and linking the new node.

type YiQueue

type YiQueue[T any] struct {
	Notify chan struct{}
	// contains filtered or unexported fields
}

YiQueue is a lock-free Yielding Queue.

It is desgined to be used by a single consumer and multiple producers. Very little spin-locking is used; instead the ring will notify the consumer with a channel when the write rate is not keeping up with the read rate.

func NewYiQueue

func NewYiQueue[T any]() *YiQueue[T]

(AI GENERATED DESCRIPTION): Creates and returns a new YiQueue[T] initialized with a one‑slot buffered notification channel and an empty underlying queue.

func (*YiQueue[T]) Iter

func (yq *YiQueue[T]) Iter() iter.Seq[T]

(AI GENERATED DESCRIPTION): Returns an iterator that repeatedly pops and yields items from the queue until the queue is empty or the supplied yield function returns false.

func (*YiQueue[T]) Pop

func (yq *YiQueue[T]) Pop() (val T, ok bool)

(AI GENERATED DESCRIPTION): Pops the next value from the queue (decrementing the size counter) and returns it with a success flag, spinning until any in‑flight push completes.

func (*YiQueue[T]) Push

func (yq *YiQueue[T]) Push(v T)

(AI GENERATED DESCRIPTION): Adds an element to the YiQueue and, if it was the first item, notifies the consumer through the Notify channel in a non‑blocking fashion.

Jump to

Keyboard shortcuts

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