Skip to content

PgSpinLockGuard<T>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Holds one PostgreSQL spinlock acquisition with copied values and scoped original-storage access.

public sealed class PgSpinLockGuard<T> : IDisposable where T : unmanaged

Type parameters:

T

The unmanaged protected value.

Inheritance: object

Implements: IDisposable

Releases the acquisition once; aliases and expired guards cannot release a later owner.

public void Dispose()

Mutate<TResult>(PgSharedMutator<T, TResult>)

Section titled “Mutate<TResult>(PgSharedMutator<T, TResult>)”

Mutates the original protected value through a reference limited to the synchronous callback.

public TResult Mutate<TResult>(PgSharedMutator<T, TResult> mutator)

Type parameters:

TResult

The owned callback result.

Parameters:

mutator — PgSharedMutator<T, TResult>

The update, whose protected reference cannot escape the callback.

Returns: TResult

The callback result.

Writes remain visible if the callback throws. Value can return a copy, but aliases cannot read the original value, start another mutation, replace Value or dispose this guard until the callback returns. Nested spinlock access is rejected during mutation; use a separate Read callback while retaining this guard. PostgreSQL calls remain forbidden while it is held.

Reads the original protected value through a reference limited to the synchronous callback.

public TResult Read<TResult>(PgSharedReader<T, TResult> reader)

Type parameters:

TResult

The owned callback result.

Parameters:

reader — PgSharedReader<T, TResult>

The reader, whose protected reference cannot escape the callback.

Returns: TResult

The callback result.

Access nested atomic values and spinlocks directly through the readonly reference. Replacing Value or disposing this guard is rejected until the reader returns. Nested spinlock guards expire before the read ends, including exceptional exits. Keep the callback short; PostgreSQL calls remain forbidden while the parent spinlock is held.

Gets or immediately replaces the protected value while this guard owns the lock.

public T Value { get; set; }

Value: T