![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Shared-memory segment lifecycle and LWLock management. More...
#include <unistd.h>#include "postgres.h"#include "storage/shmem.h"#include "provsql_shmem.h"#include "provsql_mmap.h"
Go to the source code of this file.
Functions | |
| void | provsql_shmem_startup (void) |
| Initialise the ProvSQL shared-memory segment. | |
| Size | provsql_memsize (void) |
| Return the number of bytes required for the shared-memory segment. | |
| void | provsql_shmem_request (void) |
| Request shared memory from PostgreSQL (PG ≥ 15). | |
| void | provsql_shmem_lock_exclusive (void) |
| Acquire the ProvSQL LWLock in exclusive mode. | |
| void | provsql_shmem_lock_shared (void) |
| Acquire the ProvSQL LWLock in shared mode. | |
| void | provsql_shmem_unlock (void) |
| Release the ProvSQL LWLock. | |
Variables | |
| shmem_startup_hook_type | prev_shmem_startup = NULL |
Saved pointer to the previous shmem_startup_hook, for chaining. | |
| provsqlSharedState * | provsql_shared_state = NULL |
Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup). | |
Shared-memory segment lifecycle and LWLock management.
Implements the functions declared in provsql_shmem.h:
provsql_shmem_startup(): allocates (or attaches to) the provsqlSharedState segment, initialises the LWLock, and calls pipe(2) to create the two inter-process pipes. Chains to prev_shmem_startup if set.provsql_memsize(): returns the size of the shared segment.provsql_shmem_request(): requests shared memory on PG ≥ 15.provsql_shmem_lock_exclusive() / provsql_shmem_lock_shared() / provsql_shmem_unlock(): thin wrappers around LWLockAcquire() / LWLockRelease(). Definition in file provsql_shmem.c.
| Size provsql_memsize | ( | void | ) |
Return the number of bytes required for the shared-memory segment.
Used by PostgreSQL's shared-memory allocator during startup.
provsqlSharedState structure. Definition at line 69 of file provsql_shmem.c.

| void provsql_shmem_lock_exclusive | ( | void | ) |
Acquire the ProvSQL LWLock in exclusive mode.
Callers must pair this with provsql_shmem_unlock().
Definition at line 86 of file provsql_shmem.c.

| void provsql_shmem_lock_shared | ( | void | ) |
Acquire the ProvSQL LWLock in shared mode.
Multiple backends may hold the shared lock simultaneously. Callers must pair this with provsql_shmem_unlock().
Definition at line 91 of file provsql_shmem.c.

| void provsql_shmem_request | ( | void | ) |
Request shared memory from PostgreSQL (PG ≥ 15).
Called from the shmem_request_hook (introduced in PostgreSQL 15) to reserve the segment before shared memory is finalised. Chains to prev_shmem_request if set. On older PostgreSQL versions this is a no-op because memory reservation happened in _PG_init().
Definition at line 74 of file provsql_shmem.c.


| void provsql_shmem_startup | ( | void | ) |
Initialise the ProvSQL shared-memory segment.
Called from the shmem_startup_hook. Creates (or attaches to) the provsqlSharedState segment and initialises the embedded LWLock and pipe file descriptors. Chains to prev_shmem_startup if set.
Definition at line 31 of file provsql_shmem.c.

| void provsql_shmem_unlock | ( | void | ) |
Release the ProvSQL LWLock.
Must be called after provsql_shmem_lock_exclusive() or provsql_shmem_lock_shared().
Definition at line 96 of file provsql_shmem.c.

| shmem_startup_hook_type prev_shmem_startup = NULL |
Saved pointer to the previous shmem_startup_hook, for chaining.
Definition at line 24 of file provsql_shmem.c.
| provsqlSharedState* provsql_shared_state = NULL |
Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).
Definition at line 29 of file provsql_shmem.c.