19#include "storage/shmem.h"
25#if (PG_VERSION_NUM >= 150000)
31#ifdef PROVSQL_INPROCESS_STORE
42static void provsql_inproc_atexit(
int code, Datum arg)
49void provsql_inproc_init(
void)
51 memset(&inproc_state, 0,
sizeof(inproc_state));
59bool provsql_fifo_push(provsql_fifo *f,
const void *src,
size_t n)
61 if(f->tail + n > f->cap) {
64 memmove(f->buf, f->buf + f->head, f->tail - f->head);
68 if(f->tail + n > f->cap) {
69 size_t newcap = f->cap ? f->cap * 2 : 4096;
70 while(newcap < f->tail + n)
72 f->buf = realloc(f->buf, newcap);
74 provsql_error(
"ProvSQL: out of memory growing in-process FIFO");
78 memcpy(f->buf + f->tail, src, n);
83bool provsql_fifo_pop(provsql_fifo *f,
void *dst,
size_t n)
85 if(f->tail - f->head < n)
87 memcpy(dst, f->buf + f->head, n);
89 if(f->head == f->tail)
90 f->head = f->tail = 0;
94bool provsql_inproc_send(
const char *buf,
size_t len)
96 static bool atexit_registered =
false;
102 if(!atexit_registered) {
103 on_proc_exit(provsql_inproc_atexit, (Datum) 0);
104 atexit_registered =
true;
139 LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
150 LWLockRelease(AddinShmemInitLock);
156 if(pipe(pipes_b_to_m) || pipe(pipes_m_to_b))
157 provsql_error(
"Cannot create pipe to communicate with MMap worker");
173#if (PG_VERSION_NUM >= 150000)
180 RequestNamedLWLockTranche(
"provsql", 1);
void provsql_mmap_dispatch(char c, Oid db_oid)
Handle a single IPC message: read its payload and write its reply.
void destroy_provsql_mmap()
Unmap and close the mmap files.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
Background worker and IPC primitives for mmap-backed circuit storage.
#define READM(var, type)
Read one value of type from the background-to-main pipe.
void provsql_shmem_unlock(void)
Release the ProvSQL LWLock.
void provsql_shmem_lock_exclusive(void)
Acquire the ProvSQL LWLock in exclusive mode.
provsqlSharedState * provsql_shared_state
Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).
void provsql_shmem_request(void)
Request shared memory from PostgreSQL (PG ≥ 15).
shmem_startup_hook_type prev_shmem_startup
Saved pointer to the previous shmem_startup_hook, for chaining.
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_lock_shared(void)
Acquire the ProvSQL LWLock in shared mode.
Shared-memory segment and inter-process pipe management.
shmem_request_hook_type prev_shmem_request
Saved pointer to the previous shmem_request_hook (PG ≥ 15), for chaining.
Shared state stored in the PostgreSQL shared-memory segment.