Class ScyllaDeque<T>.SynchronizedScyllaDeque
Thread-safe decorator that wraps a ScyllaDeque<T> and serializes all operations
through a single lock statement, making every individual operation atomic.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaDeque<T>.SynchronizedScyllaDeque : IScyllaCollection<T>, IScyllaCollection
Remarks
Obtain an instance by calling AsSynchronized(object) on an existing deque, or by configuring the fluent ScyllaDeque<T>.Builder with Synchronized(object). Both return an IScyllaCollection<T> whose ThreadSafety property reports Synchronized.
Compound operations: while each individual operation is atomic, multi-step sequences such as peek-then-remove are not atomic as a unit unless the caller holds the lock for the entire sequence:
lock (syncedDeque.SyncRoot)
{
if (syncedDeque.TryPeekFront(out var item))
syncedDeque.TryPopFront(out _);
}
The IsFixedCapacity and Capabilities properties are cached at construction time and are safe to read without acquiring the lock.
Constructors
SynchronizedScyllaDeque(ScyllaDeque<T>, object)
Initializes a new synchronized wrapper around the specified ScyllaDeque<T>.
Declaration
public SynchronizedScyllaDeque(ScyllaDeque<T> inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaDeque<T> | inner | The deque to wrap. Must not be |
| object | syncRoot | The lock object to use for synchronization. If |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Capabilities
Gets the capability flags of the wrapped deque. This value is cached at construction time and is safe to read without acquiring the lock.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities | The same ScyllaCollectionCapabilities bitmask reported by the inner deque. Includes HasCapacity, SupportsPeek, SupportsCopyTo, and SupportsContains. |
Capacity
Gets the current capacity of the backing circular buffer. Acquires the internal lock to read a consistent value from the inner deque.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int | The number of elements the backing buffer can hold before it would need to grow. For a fixed-capacity deque this value never changes after construction. |
Count
Gets the number of elements currently stored in the deque. Acquires the internal lock to read a consistent value.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | A non-negative integer in the range |
IsEmpty
Gets a value indicating whether the deque contains no elements. Acquires the internal lock to read a consistent value.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsFixedCapacity
Gets a value indicating whether the inner deque was created with a fixed capacity. This property is safe to read without acquiring the lock because it is cached at construction.
Declaration
public bool IsFixedCapacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsFull
Gets a value indicating whether the deque is currently full. Acquires the internal lock to read a consistent value.
Declaration
public bool IsFull { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
SyncRoot
Gets the synchronization root object used to coordinate all operations on this wrapper. Callers can lock on this object to make multi-step compound operations atomic.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object | A non- |
ThreadSafety
Gets the thread-safety level of this wrapper, which is always Synchronized.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Methods
Clear()
Removes all elements from the deque. For reference-type elements, clears the backing array slots to release managed references. Acquires the internal lock.
Declaration
public void Clear()
Contains(T, IEqualityComparer<T>)
Determines whether the deque contains the specified item using a linear scan (O(n)). Acquires the internal lock before delegating to the inner deque.
Declaration
public bool Contains(T item, IEqualityComparer<T> comparer = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to locate. |
| IEqualityComparer<T> | comparer | Optional equality comparer. If |
Returns
| Type | Description |
|---|---|
| bool |
|
CopyTo(Span<T>)
Copies elements from the deque into the provided span in front-to-back order. Acquires the internal lock so the snapshot is consistent.
Declaration
public int CopyTo(Span<T> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | destination | The span to copy into. At most |
Returns
| Type | Description |
|---|---|
| int | The number of elements actually copied. |
CopyTo(T[], int)
Copies elements from the deque into the provided array starting at the specified index, in front-to-back order. Acquires the internal lock so the snapshot is consistent.
Declaration
public int CopyTo(T[] destination, int destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | destination | The array to copy into. Must not be |
| int | destinationIndex | The zero-based index in |
Returns
| Type | Description |
|---|---|
| int | The number of elements actually copied. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
TryAdd(T)
Attempts to add an item to the back of the deque (FIFO convention). Acquires the internal lock before delegating to the inner deque's TryPushBack(T).
Declaration
public bool TryAdd(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to push onto the back of the deque. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPeek(out T)
Attempts to inspect the front element without removing it. Acquires the internal lock before delegating to the inner deque's TryPeekFront(out T).
Declaration
public bool TryPeek(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPeekBack(out T)
Attempts to inspect the back element without removing it. Acquires the internal lock before delegating to the inner deque.
Declaration
public bool TryPeekBack(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPeekFront(out T)
Attempts to inspect the front element without removing it. Acquires the internal lock before delegating to the inner deque.
Declaration
public bool TryPeekFront(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPopBack(out T)
Attempts to remove and return the back element of the deque. Acquires the internal lock before delegating to the inner deque.
Declaration
public bool TryPopBack(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPopFront(out T)
Attempts to remove and return the front element of the deque. Acquires the internal lock before delegating to the inner deque.
Declaration
public bool TryPopFront(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPushBack(T)
Attempts to push an item onto the back of the deque. Acquires the internal lock before delegating to the inner deque.
Declaration
public bool TryPushBack(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to place at the back of the deque. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPushFront(T)
Attempts to push an item onto the front of the deque. Acquires the internal lock before delegating to the inner deque.
Declaration
public bool TryPushFront(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to place at the front of the deque. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryRemove(out T)
Attempts to remove and return the front element of the deque (FIFO convention). Acquires the internal lock before delegating to the inner deque's TryPopFront(out T).
Declaration
public bool TryRemove(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|