Skip to content

PgAtomic<T>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Stores one atomic scalar in PostgreSQL shared memory for use across processes and managed threads.

public sealed class PgAtomic<T> where T : unmanaged

Type parameters:

T

A primitive or enum type supported by Interlocked.

Keep the descriptor in a static field and register it with PgSharedMemory during shared preload. Operations use the strong ordering of .NET Interlocked and do not invoke PostgreSQL. Each operation protects its address against shared-memory retirement. Values survive transaction errors but are initialized again when PostgreSQL recreates shared memory.

Inheritance: object

Creates an unregistered atomic descriptor with a cluster-wide shared-memory name.

public PgAtomic(string name)

Parameters:

name — string

A nonempty, exact UTF-8 name without a zero byte.

Exceptions:

Atomically replaces the scalar when its bits equal the comparand and returns the previous value.

public T CompareExchange(T value, T comparand)

Parameters:

value — T

The replacement value when comparison succeeds.

comparand — T

The exact bit pattern required for replacement.

Returns: T

The value before comparison, whether or not replacement occurred.

Atomically replaces the scalar and returns its previous value.

public T Exchange(T value)

Parameters:

value — T

The replacement value.

Returns: T

The value before replacement.

Gets the exact cluster-wide shared-memory name.

public string Name { get; }

Value: string

Gets or replaces the scalar atomically, preserving its exact bits.

public T Value { get; set; }

Value: T