ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
provsql_shmem.h File Reference

Shared-memory segment and inter-process pipe management. More...

#include "postgres.h"
#include "miscadmin.h"
#include "storage/ipc.h"
#include "storage/lwlock.h"
Include dependency graph for provsql_shmem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  provsqlSharedState
 Shared state stored in the PostgreSQL shared-memory segment. More...
 

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
 Saved pointer to the previous shmem_startup_hook, for chaining.
 
provsqlSharedStateprovsql_shared_state
 Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).
 

Detailed Description

Shared-memory segment and inter-process pipe management.

ProvSQL uses a small PostgreSQL shared-memory segment (provsqlSharedState) to hold the file descriptors of the anonymous pipes that connect normal backends to the mmap background worker, together with a lightweight lock that serialises concurrent gate-creation requests.

This header declares:

  • provsqlSharedState, the layout of the shared segment.
  • Hook functions (provsql_shmem_startup, provsql_shmem_request) that integrate with PostgreSQL's shared-memory lifecycle.
  • Convenience wrappers (provsql_shmem_lock_exclusive, etc.) around the embedded LWLock.
  • Saved pointers to the previous hook functions so that ProvSQL can chain into an existing hook chain.

Definition in file provsql_shmem.h.

Function Documentation

◆ provsql_memsize()

Size provsql_memsize ( void  )

Return the number of bytes required for the shared-memory segment.

Used by PostgreSQL's shared-memory allocator during startup.

Returns
Size in bytes of the provsqlSharedState structure.

Definition at line 69 of file provsql_shmem.c.

Here is the caller graph for this function:

◆ provsql_shmem_lock_exclusive()

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.

Here is the caller graph for this function:

◆ provsql_shmem_lock_shared()

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.

Here is the caller graph for this function:

◆ provsql_shmem_request()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ provsql_shmem_startup()

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.

Here is the caller graph for this function:

◆ provsql_shmem_unlock()

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.

Here is the caller graph for this function:

Variable Documentation

◆ prev_shmem_startup

shmem_startup_hook_type prev_shmem_startup
extern

Saved pointer to the previous shmem_startup_hook, for chaining.

Definition at line 24 of file provsql_shmem.c.

◆ provsql_shared_state

provsqlSharedState* provsql_shared_state
extern

Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).

Definition at line 29 of file provsql_shmem.c.