Class ScyllaStack<T>.SynchronizedScyllaStack
Thread-safe wrapper around ScyllaStack<T> that serializes all operations
through a single lock object.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaStack<T>.SynchronizedScyllaStack : IScyllaCollection<T>, IScyllaCollection
Remarks
Obtain an instance via AsSynchronized(object) or the Synchronized(object) builder method. Both approaches share the same underlying ScyllaStack<T>, so the wrapper and the original stack must not be used concurrently from different threads without going through the wrapper exclusively.
All state-reading properties (Count, IsFull,
Capacity) are individually locked. Because each property acquires
and releases the lock independently, a check-then-act pattern (e.g. checking
IsFull and then calling TryPush(T)) is still subject
to TOCTOU races between the two separate lock acquisitions. Use the Try*
methods atomically when correctness under contention is required.
Constructors
SynchronizedScyllaStack(ScyllaStack<T>, object)
Initializes a new ScyllaStack<T>.SynchronizedScyllaStack wrapping the specified stack.
Declaration
public SynchronizedScyllaStack(ScyllaStack<T> inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaStack<T> | inner | The unsynchronized stack to wrap. Must not be |
| object | syncRoot | The lock object used to protect all operations. If |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Capabilities
Gets the ScyllaCollectionCapabilities flags reported by the inner stack. This value is immutable and cached at construction time; reading it is lock-free.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities |
Capacity
Gets the current capacity of the inner stack's backing buffer. This value may change between reads if the stack is in variable-capacity mode and another thread has triggered a growth operation.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
Count
Gets the number of elements currently held in the inner stack.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Gets whether the inner stack contains no elements.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFixedCapacity
Gets whether the inner stack operates in fixed-capacity mode. This property is immutable after construction and does not require locking.
Declaration
public bool IsFixedCapacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFull
Gets whether the inner stack is currently full.
Only meaningful when IsFixedCapacity is true; a variable-capacity
stack is technically always growable and is never permanently full.
Declaration
public bool IsFull { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SyncRoot
Gets the synchronization root object used by this wrapper to serialize operations. External code may lock on this object to compose multiple stack operations atomically.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object |
ThreadSafety
Gets Synchronized, indicating that all operations on this wrapper are protected by a lock.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Methods
Clear()
Removes all elements from the inner stack and releases references for garbage collection. Acquires the lock before delegating to Clear().
Declaration
public void Clear()
Contains(T, IEqualityComparer<T>)
Determines whether the inner stack contains the specified item. Acquires the lock for the entire O(n) search.
Declaration
public bool Contains(T item, IEqualityComparer<T> comparer = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to search for. |
| IEqualityComparer<T> | comparer | The equality comparer used to compare elements. If |
Returns
| Type | Description |
|---|---|
| bool |
|
CopyTo(Span<T>)
Copies elements from the inner stack into destination in top-to-bottom order.
Acquires the lock for the duration of the copy.
Declaration
public int CopyTo(Span<T> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | destination | The span to write elements into. At most |
Returns
| Type | Description |
|---|---|
| int | The number of elements actually copied. |
CopyTo(T[], int)
Copies elements from the inner stack into destination starting at
destinationIndex, in top-to-bottom order.
Acquires the lock for the duration of the copy.
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. |
TryAdd(T)
Attempts to push item onto the top of the inner stack.
Acquires the lock before delegating to TryPush(T).
Declaration
public bool TryAdd(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to push onto the stack. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPeek(out T)
Attempts to inspect the top item of the inner stack without removing it. Acquires the lock before delegating to TryPeekTop(out T).
Declaration
public bool TryPeek(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns, contains the top element if the stack was non-empty,
or |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPeekTop(out T)
Attempts to inspect the top item of the inner stack without removing it. This is the stack-idiomatic equivalent of TryPeek(out T). Acquires the lock before delegating to TryPeekTop(out T).
Declaration
public bool TryPeekTop(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns, contains the top element if available,
or |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPop(out T)
Attempts to pop the top item from the inner stack. This is the stack-idiomatic equivalent of TryRemove(out T). Acquires the lock before delegating to TryPop(out T).
Declaration
public bool TryPop(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns, contains the popped element if successful,
or |
Returns
| Type | Description |
|---|---|
| bool |
|
TryPush(T)
Attempts to push item onto the top of the inner stack.
This is the stack-idiomatic equivalent of TryAdd(T).
Acquires the lock before delegating to TryPush(T).
Declaration
public bool TryPush(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to push onto the stack. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryRemove(out T)
Attempts to pop the top item from the inner stack. Acquires the lock before delegating to TryPop(out T).
Declaration
public bool TryRemove(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns, contains the removed top element if the stack was non-empty,
or |
Returns
| Type | Description |
|---|---|
| bool |
|