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
capacityPerChunkintThe capacity per chunk.
handleAllocationHandleThe allocation handle.
allocationOptionAllocationOptionThe allocation option.
Properties
IsCreated
public readonly bool IsCreated { get; }
Property Value
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
capacityPerChunkintThe capacity per chunk.
handleAllocationHandleThe allocation handle.
allocationOptionAllocationOptionThe 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
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
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
itemTThe item to enqueue.
TryDequeue(out T)
Attempts to dequeue an item.
public bool TryDequeue(out T item)
Parameters
itemTThe dequeued item if successful; otherwise, the default value of T.
Returns
- bool
True if an item was dequeued successfully; otherwise, false.