ring

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ring provides a bounded lock-free queue from one goroutine to another, whose elements live off the Go heap. It moves pointer-free values between goroutines without allocating, and each side reads the other's position only when its cached copy runs out, which keeps the two cores off each other's cache lines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SPSC

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

SPSC is a queue with exactly one producer goroutine, calling Push, and exactly one consumer goroutine, calling Pop. More of either corrupts it.

func New

func New[T any](a memory.Allocator, capacity int) (*SPSC[T], error)

New returns an empty queue holding at least capacity elements, rounded up to a power of two.

func (*SPSC[T]) Cap

func (q *SPSC[T]) Cap() int

Cap returns the number of elements the queue holds when full.

func (*SPSC[T]) Free

func (q *SPSC[T]) Free() error

Free releases the elements. No goroutine may be using q.

func (*SPSC[T]) Pop

func (q *SPSC[T]) Pop() (T, bool)

Pop removes the oldest value, or reports false if the queue is empty. Only the consumer may call it.

func (*SPSC[T]) Push

func (q *SPSC[T]) Push(value T) bool

Push adds value, or reports false if the queue is full. Only the producer may call it.

Jump to

Keyboard shortcuts

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