Class ScyllaQueue<T>.SynchronizedScyllaQueue
Thread-safe wrapper around a ScyllaQueue<T> that serializes all operations through a single lock object.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaQueue<T>.SynchronizedScyllaQueue : IScyllaCollection<T>, IScyllaCollection
Remarks
Obtain an instance via AsSynchronized(object) or through the fluent builder's Synchronized(object) method. Do not construct this class directly in production code.
Capabilities and IsFixedCapacity are cached at wrapper creation time so that those properties can be read without acquiring the lock on every call.
Compound atomicity: Individual operations are atomic with respect to each other, but a check-then-act sequence (e.g. check IsEmpty then call TryDequeue(out T)) is still subject to a TOCTOU race. Use SyncRoot to hold the lock across the combined operation:
lock (wrapper.SyncRoot)
{
if (!wrapper.IsEmpty)
wrapper.TryDequeue(out var item);
}
Multiple ScyllaQueue<T>.SynchronizedScyllaQueue instances can share the same
syncRoot object (passed to AsSynchronized(object)) to
coordinate atomic operations across two wrappers.
Constructors
SynchronizedScyllaQueue(ScyllaQueue<T>, object)
Initializes a new ScyllaQueue<T>.SynchronizedScyllaQueue that wraps the given queue and serializes all operations through the specified lock object.
Declaration
public SynchronizedScyllaQueue(ScyllaQueue<T> inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaQueue<T> | inner | The unsynchronized queue to wrap. Must not be |
| object | syncRoot | The lock object to use for all synchronized operations. When |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Capabilities
Gets the capability flags supported by the wrapped queue.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities | The same ScyllaCollectionCapabilities flags reported by the inner ScyllaQueue<T>. This value is cached at construction and does not require the lock. |
Capacity
Gets the current capacity of the backing circular buffer.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int | The number of elements the internal buffer can currently hold without growing. In fixed-capacity mode this is the permanent maximum. |
Remarks
This property acquires the internal lock on every read.
Count
Gets the number of elements currently in the queue.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | A non-negative integer representing the current element count. Returns |
Remarks
This property acquires the internal lock on every read.
IsEmpty
Gets a value indicating whether the queue contains no elements.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Remarks
This property acquires the internal lock on every read.
IsFixedCapacity
Gets a value indicating whether this queue operates in fixed-capacity mode.
Declaration
public bool IsFixedCapacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Remarks
This value is cached at wrapper creation time and is read without acquiring the lock.
IsFull
Gets a value indicating whether the queue is at full capacity.
Declaration
public bool IsFull { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Remarks
This property acquires the internal lock on every read.
SyncRoot
Gets the lock object used to serialize all operations on this wrapper.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object | A non-null object that can be used with |
ThreadSafety
Gets the thread-safety level of this wrapper.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety | Always Synchronized, indicating that all operations are protected by an internal lock. |
Methods
Clear()
Removes all elements from the queue and resets it to an empty state.
Declaration
public void Clear()
Remarks
For reference types, internal slots are cleared to default to release object
references. This operation acquires the internal lock.
Contains(T, IEqualityComparer<T>)
Determines whether the queue contains the specified item using a linear search.
Declaration
public bool Contains(T item, IEqualityComparer<T> comparer = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to locate in the queue. |
| IEqualityComparer<T> | comparer | Optional equality comparer to use when comparing elements. When |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This is an O(n) operation. This operation acquires the internal lock.
CopyTo(Span<T>)
Copies elements from the queue into the provided span in FIFO order (oldest element first).
Declaration
public int CopyTo(Span<T> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | destination | The caller-owned span to copy elements into. If smaller than Count,
only the first |
Returns
| Type | Description |
|---|---|
| int | The number of elements copied, which is |
Remarks
This operation acquires the internal lock and produces a consistent snapshot.
CopyTo(T[], int)
Copies elements from the queue into the provided array starting at the specified index, in FIFO order (oldest element first).
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 copied. Returns |
Remarks
This operation acquires the internal lock and produces a consistent snapshot.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
TryAdd(T)
Attempts to add an item to the back of the queue. Equivalent to TryEnqueue(T); provided for polymorphic IScyllaCollection<T> usage.
Declaration
public bool TryAdd(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to enqueue. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This operation acquires the internal lock.
TryDequeue(out T)
Attempts to remove and return the oldest (front) element from the queue.
Declaration
public bool TryDequeue(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This operation acquires the internal lock.
TryEnqueue(T)
Attempts to add an item to the back of the queue.
Declaration
public bool TryEnqueue(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to enqueue. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This operation acquires the internal lock.
TryPeek(out T)
Attempts to inspect the front element without removing it. Equivalent to TryPeekFront(out T); provided for polymorphic IScyllaCollection<T> usage.
Declaration
public bool TryPeek(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This operation acquires the internal lock.
TryPeekFront(out T)
Attempts to inspect the oldest (front) element without removing it from the queue.
Declaration
public bool TryPeekFront(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This operation acquires the internal lock.
TryRemove(out T)
Attempts to remove the front element from the queue. Equivalent to TryDequeue(out T); provided for polymorphic IScyllaCollection<T> usage.
Declaration
public bool TryRemove(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This operation acquires the internal lock.