Class ScyllaPriorityQueue<T>.SynchronizedScyllaPriorityQueue
Thread-safe wrapper around ScyllaPriorityQueue<T> that synchronizes all operations using a single exclusive lock object.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaPriorityQueue<T>.SynchronizedScyllaPriorityQueue : IScyllaCollection<T>, IScyllaCollection
Remarks
All mutating and reading operations are serialized via lock(_lock). This guarantees
that concurrent enqueue, dequeue, peek, and clear calls are safe, but it also means that
high-contention scenarios may become a bottleneck. For very high throughput, consider
using per-thread queues and merging results instead.
A few properties (IsFixedCapacity, Capabilities) are read from cached fields and do not acquire the lock. These values cannot change after construction.
Obtain an instance by calling AsSynchronized(object) or the builder's Synchronized(object) method rather than constructing this type directly.
Constructors
SynchronizedScyllaPriorityQueue(ScyllaPriorityQueue<T>, object)
Initializes a new instance of the synchronized wrapper around the specified priority queue.
Declaration
public SynchronizedScyllaPriorityQueue(ScyllaPriorityQueue<T> inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaPriorityQueue<T> | inner | The queue to wrap. Must not be null. |
| object | syncRoot | The lock object to use for synchronization. If null, a new private lock is created. |
Properties
Capabilities
Gets the capability flags supported by this priority queue instance. This value is cached at wrapper creation time and does not require synchronization.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities |
Capacity
Gets the current capacity of the backing buffer. This operation is thread-safe.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
Count
Gets the number of elements currently in the priority queue. This operation is thread-safe.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Gets a value indicating whether the priority queue is empty. This operation is thread-safe.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFixedCapacity
Gets whether the priority queue is fixed capacity. This value is cached at wrapper creation time and does not require synchronization.
Declaration
public bool IsFixedCapacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFull
Gets whether the priority queue is full. This is only meaningful when IsFixedCapacity is true. This operation is thread-safe.
Declaration
public bool IsFull { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SyncRoot
Gets the synchronization root object used for coordinating operations. All wrapper operations synchronize on this object.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object |
ThreadSafety
Gets the thread-safety guarantees provided by this wrapper. Always returns Synchronized.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Methods
Clear()
Removes all items from the priority queue, resetting it to an empty state. This operation is thread-safe.
Declaration
public void Clear()
Contains(T, IEqualityComparer<T>)
Determines whether the priority queue contains the specified item (O(n)). This operation is thread-safe.
Declaration
public bool Contains(T item, IEqualityComparer<T> comparer = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to locate |
| IEqualityComparer<T> | comparer | Optional equality comparer to use for comparison. If null, uses Default. |
Returns
| Type | Description |
|---|---|
| bool | True if the item is found; otherwise false |
CopyTo(Span<T>)
Copies up to destination.Length elements from the queue into the destination span
in heap internal order (not priority-sorted order). This operation is thread-safe.
Declaration
public int CopyTo(Span<T> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | destination | The span to copy elements into. Receives at most Count elements. |
Returns
| Type | Description |
|---|---|
| int | The number of elements actually copied. |
CopyTo(T[], int)
Copies up to destination.Length - destinationIndex elements from the queue into the
destination array starting at destinationIndex, in heap internal order
(not priority-sorted order). This operation is thread-safe.
Declaration
public int CopyTo(T[] destination, int destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | destination | The array to copy elements into. Must not be |
| int | destinationIndex | The zero-based index in |
Returns
| Type | Description |
|---|---|
| int | The number of elements actually copied. |
EnsureCapacity(int)
Ensures the priority queue can hold at least the specified number of items without resizing. This operation is thread-safe.
Declaration
public void EnsureCapacity(int minCapacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | minCapacity | Minimum capacity to ensure |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if the wrapped queue is fixed-capacity |
TryAdd(T)
Attempts to add an item to the priority queue. Equivalent to calling TryEnqueue(T). This operation is thread-safe.
Declaration
public bool TryAdd(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to add. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryDequeue(out T)
Attempts to dequeue the highest-priority item from the priority queue. This operation is thread-safe.
Declaration
public bool TryDequeue(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns, contains the dequeued item if successful, otherwise default |
Returns
| Type | Description |
|---|---|
| bool | True if an item was dequeued; false if empty |
TryEnqueue(T)
Attempts to enqueue an item into the priority queue. This operation is thread-safe.
Declaration
public bool TryEnqueue(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to enqueue |
Returns
| Type | Description |
|---|---|
| bool | True if enqueued; false if fixed-capacity and full |
TryPeek(out T)
Attempts to peek at the highest-priority item without removing it. Equivalent to calling TryPeekTop(out T). This operation is thread-safe.
Declaration
public bool TryPeek(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPeekTop(out T)
Attempts to peek at the highest-priority item without removing it. This operation is thread-safe.
Declaration
public bool TryPeekTop(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns, contains the top item if successful, otherwise default |
Returns
| Type | Description |
|---|---|
| bool | True if an item was available; false if empty |
TryRemove(out T)
Attempts to remove and return the highest-priority item from the queue. Equivalent to calling TryDequeue(out T). This operation is thread-safe.
Declaration
public bool TryRemove(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|