Fix obsolete comment regarding FSM truncation.
[PostgreSQL.git] / src / include / storage / ipc.h
blob243c141bfa4fe65c38c1e0818e90a5639a4c1783
1 /*-------------------------------------------------------------------------
3 * ipc.h
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-2008, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
14 * $PostgreSQL$
16 *-------------------------------------------------------------------------
18 #ifndef IPC_H
19 #define IPC_H
21 typedef void (*pg_on_exit_callback) (int code, Datum arg);
23 /*----------
24 * API for handling cleanup that must occur during either ereport(ERROR)
25 * or ereport(FATAL) exits from a block of code. (Typical examples are
26 * undoing transient changes to shared-memory state.)
28 * PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
29 * {
30 * ... code that might throw ereport(ERROR) or ereport(FATAL) ...
31 * }
32 * PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
34 * where the cleanup code is in a function declared per pg_on_exit_callback.
35 * The Datum value "arg" can carry any information the cleanup function
36 * needs.
38 * This construct ensures that cleanup_function() will be called during
39 * either ERROR or FATAL exits. It will not be called on successful
40 * exit from the controlled code. (If you want it to happen then too,
41 * call the function yourself from just after the construct.)
43 * Note: the macro arguments are multiply evaluated, so avoid side-effects.
44 *----------
46 #define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
47 do { \
48 on_shmem_exit(cleanup_function, arg); \
49 PG_TRY()
51 #define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
52 cancel_shmem_exit(cleanup_function, arg); \
53 PG_CATCH(); \
54 { \
55 cancel_shmem_exit(cleanup_function, arg); \
56 cleanup_function (0, arg); \
57 PG_RE_THROW(); \
58 } \
59 PG_END_TRY(); \
60 } while (0)
63 /* ipc.c */
64 extern bool proc_exit_inprogress;
66 extern void proc_exit(int code);
67 extern void shmem_exit(int code);
68 extern void on_proc_exit(pg_on_exit_callback function, Datum arg);
69 extern void on_shmem_exit(pg_on_exit_callback function, Datum arg);
70 extern void cancel_shmem_exit(pg_on_exit_callback function, Datum arg);
71 extern void on_exit_reset(void);
73 /* ipci.c */
74 extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int port);
76 #endif /* IPC_H */