Table of Contents

Struct UnsafeParallelQueue<T>

Namespace
Misaki.HighPerformance.LowLevel.Collections
Assembly
Misaki.HighPerformance.LowLevel.dll

A dynamically resizing, parallel, lock-free queue using unmanaged chunks. Uses a very brief spin lock only during chunk allocation, alongside a lock-free segment cache.

public struct UnsafeParallelQueue<T> : IDisposable where T : unmanaged

Type Parameters

T
Implements
Inherited Members

Constructors

UnsafeParallelQueue(int, AllocationHandle, AllocationOption)

Initializes a new instance of the UnsafeParallelQueue with the specified capacity per chunk and allocation handle.

public UnsafeParallelQueue(int capacityPerChunk, AllocationHandle handle, AllocationOption allocationOption = AllocationOption.None)

Parameters

capacityPerChunk int

The capacity per chunk.

handle AllocationHandle

The allocation handle.

allocationOption AllocationOption

The allocation option.

Properties

IsCreated

public readonly bool IsCreated { get; }

Property Value

bool

Methods

Allocate(int, AllocationHandle, AllocationOption)

Allocates a new UnsafeParallelQueue on the heap using the provided allocation handle and returns a DisposablePtr to it.

public static DisposablePtr<UnsafeParallelQueue<T>> Allocate(int capacityPerChunk, AllocationHandle handle, AllocationOption allocationOption = AllocationOption.None)

Parameters

capacityPerChunk int

The capacity per chunk.

handle AllocationHandle

The allocation handle.

allocationOption AllocationOption

The allocation option.

Returns

DisposablePtr<UnsafeParallelQueue<T>>

A DisposablePtr to the allocated UnsafeParallelQueue.

AsParallelConsumer()

Returns a parallel consumer for this queue. The returned struct contains a raw pointer to the queue and can be used from multiple threads as long as the queue struct itself remains alive and its address stable.

public UnsafeParallelQueue<T>.ParallelConsumer AsParallelConsumer()

Returns

UnsafeParallelQueue<T>.ParallelConsumer

AsParallelProducer()

Returns a parallel producer for this queue. The returned struct contains a raw pointer to the queue and can be used from multiple threads as long as the queue struct itself remains alive and its address stable.

public UnsafeParallelQueue<T>.ParallelProducer AsParallelProducer()

Returns

UnsafeParallelQueue<T>.ParallelProducer

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Enqueue(scoped in T)

Try to enqueue an item. Expands automatically if the current chunk is full.

public void Enqueue(scoped in T item)

Parameters

item T

The item to enqueue.

TryDequeue(out T)

Attempts to dequeue an item.

public bool TryDequeue(out T item)

Parameters

item T

The dequeued item if successful; otherwise, the default value of T.

Returns

bool

True if an item was dequeued successfully; otherwise, false.