1/*-------------------------------------------------------------------------
4 * POSTGRES inter-process communication definitions.
6 * This file is misnamed, as it no longer has much of anything directly
7 * to do with IPC. The functionality here is concerned with managing
8 * exit-time cleanup for either a postmaster or a backend.
11 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/include/storage/ipc.h
16 *-------------------------------------------------------------------------
25 * API for handling cleanup that must occur during either ereport(ERROR)
26 * or ereport(FATAL) exits from a block of code. (Typical examples are
27 * undoing transient changes to shared-memory state.)
29 * PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
31 * ... code that might throw ereport(ERROR) or ereport(FATAL) ...
33 * PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
35 * where the cleanup code is in a function declared per pg_on_exit_callback.
36 * The Datum value "arg" can carry any information the cleanup function
39 * This construct ensures that cleanup_function() will be called during
40 * either ERROR or FATAL exits. It will not be called on successful
41 * exit from the controlled code. (If you want it to happen then too,
42 * call the function yourself from just after the construct.)
44 * Note: the macro arguments are multiply evaluated, so avoid side-effects.
47 #define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
49 before_shmem_exit(cleanup_function, arg); \
52 #define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
53 cancel_before_shmem_exit(cleanup_function, arg); \
56 cancel_before_shmem_exit(cleanup_function, arg); \
57 cleanup_function (0, arg); \
83extern void AttachSharedMemoryStructs(
void);
void check_on_shmem_exit_lists_are_empty(void)
PGDLLIMPORT bool shmem_exit_inprogress
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
void on_proc_exit(pg_on_exit_callback function, Datum arg)
void cancel_before_shmem_exit(pg_on_exit_callback function, Datum arg)
pg_noreturn void proc_exit(int code)
void(* shmem_startup_hook_type)(void)
void(* pg_on_exit_callback)(int code, Datum arg)
void shmem_exit(int code)
PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Size CalculateShmemSize(int *num_semaphores)
void InitializeShmemGUCs(void)
void CreateSharedMemoryAndSemaphores(void)
PGDLLIMPORT bool proc_exit_inprogress
on_exit_nicely_callback function