fastmpmc_ticket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FastMPMCQueueTicket

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

FastMPMCQueueTicket is a bounded, lock‑free multi‑producer/multi‑consumer queue using a ticket‑based approach to reduce contention on the shared counters.

func New

func New[T any](capacity uint64) *FastMPMCQueueTicket[T]

New creates a new FastMPMCQueueTicket with the specified capacity. If capacity is not a power of 2, it is rounded up.

func (*FastMPMCQueueTicket[T]) Dequeue

func (q *FastMPMCQueueTicket[T]) Dequeue() (T, bool)

Dequeue removes and returns a value from the queue. It busy-waits until a value is available or the queue is empty. The method first checks if the cell at the current dequeue position is ready. If not, it verifies whether the queue is truly empty (i.e. no producer holds a ticket for that slot).

func (*FastMPMCQueueTicket[T]) Enqueue

func (q *FastMPMCQueueTicket[T]) Enqueue(val T)

Enqueue inserts a value into the queue. It busy-waits until a slot becomes available.

func (*FastMPMCQueueTicket[T]) FreeSlots

func (q *FastMPMCQueueTicket[T]) FreeSlots() uint64

FreeSlots returns an approximate count of free slots in the queue.

func (*FastMPMCQueueTicket[T]) UsedSlots

func (q *FastMPMCQueueTicket[T]) UsedSlots() uint64

UsedSlots returns an approximate count of occupied slots in the queue.

Jump to

Keyboard shortcuts

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