Skip to content

PgSpinLockValue<T>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Embeds a PostgreSQL spinlock and unmanaged value inside a shared aggregate.

public readonly struct PgSpinLockValue<T> where T : unmanaged

Type parameters:

T

The unmanaged value protected by the spinlock.

Construct this field in the shared initializer and access it directly through the reference supplied by the owning shared value’s or lock guard’s Read callback. Default values and detached copies cannot be locked. Use PgSpinLock for ordinary local storage. Keep critical sections short and synchronous.

Initializes the selected PostgreSQL lock representation and the protected value.

public PgSpinLockValue(T value)

Parameters:

value — T

The initial value.

Gets whether the lock is currently held, on PostgreSQL versions before 19.

public bool IsLocked { get; }

Value: bool

This is an instantaneous observation, not permission to access the protected value. PostgreSQL 19 and later throw NotSupportedException because SpinLockFree was removed.

Acquires an exclusive guard within the current admitted shared read.

public PgSpinLockGuard<T> Lock()

Returns: PgSpinLockGuard<T>

A guard released by disposal, shared-read exit or callback exit.