optmpmc_sharded

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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ShardedOptimizedMPMCQueue

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

ShardedOptimizedMPMCQueue is a lock‑free, sharded MPMC queue.

func New

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

New creates a new sharded queue with the specified total capacity. The number of shards is determined by

var numShards uint64 = uint64(runtime.NumCPU())

and the logical capacity is partitioned among shards so that the sum equals the requested capacity. Each shard's internal buffer is allocated with a capacity that is a power‑of‑two.

func (*ShardedOptimizedMPMCQueue[T]) Dequeue

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

Dequeue removes a value from one of the shards selected at random. If the chosen shard is empty and a check shows that all shards are empty, it immediately returns with false.

func (*ShardedOptimizedMPMCQueue[T]) Enqueue

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

Enqueue adds a value into one of the shards selected at random. It spins within the chosen shard until a slot is available.

func (*ShardedOptimizedMPMCQueue[T]) FreeSlots

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

FreeSlots returns how many logical slots remain free across all shards.

func (*ShardedOptimizedMPMCQueue[T]) UsedSlots

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

UsedSlots returns the total number of used slots across shards.

Jump to

Keyboard shortcuts

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