Skip to content

PgLwLock<THeader, TElement>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Describes a header and an array of elements in shared memory, protected by one PostgreSQL lightweight lock, whose length is chosen when the extension registers it.

public sealed class PgLwLock<THeader, TElement> where THeader : unmanaged where TElement : unmanaged

Type parameters:

THeader

The unmanaged header, such as counters for the whole array.

TElement

The unmanaged element, such as one worker’s slot.

A C extension sizes such arrays from settings that are fixed at server start, such as one slot per max_worker_processes; pgrx's shared values have a size fixed at compile time. Register the descriptor from a [PgModuleLoadAttribute](/api/ankus.pgmoduleloadattribute/) method with [PgSharedMemory](/api/ankus.pgsharedmemory/) and the length. Every process must compute the same length; on Windows each backend loads the library again and attaches to the existing storage, which fails if the size differs.

Elements start at the first 8-byte boundary after the header and follow each other without padding, as a C array does. Guards follow the rules of [PgLwLock<T>](/api/ankus.pglwlock-1/): they belong to the acquiring callback and thread, and callback references cannot escape the callback.

Inheritance: object

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

public PgLwLock(string name)

Parameters:

name — string

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

Acquires exclusive read/write access, waiting for all other holders to release the lock.

public PgLwLockExclusiveGuard<THeader, TElement> Exclusive()

Returns: PgLwLockExclusiveGuard<THeader, TElement>

A callback-scoped exclusive guard.

Acquires shared read access, waiting for an exclusive writer to release the lock.

public PgLwLockShareGuard<THeader, TElement> Share()

Returns: PgLwLockShareGuard<THeader, TElement>

A callback-scoped shared guard.

Gets the number of elements, or zero before registration.

public int Length { get; }

Value: int

Gets the exact name used by PostgreSQL’s shared-memory index and named lock tranche.

public string Name { get; }

Value: string