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

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"
Include dependency graph for provsql_shmem.c:

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.
 
provsqlSharedStateprovsql_shared_state = NULL
 Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).
 

Detailed Description

Shared-memory segment lifecycle and LWLock management.

Implements the functions declared in provsql_shmem.h:

Definition in file provsql_shmem.c.

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 = NULL

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 = NULL

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

Definition at line 29 of file provsql_shmem.c.