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-2008, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
16 *-------------------------------------------------------------------------
21 typedef void (*pg_on_exit_callback
) (int code
, Datum arg
);
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);
30 * ... code that might throw ereport(ERROR) or ereport(FATAL) ...
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
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.
46 #define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
48 on_shmem_exit(cleanup_function, arg); \
51 #define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
52 cancel_shmem_exit(cleanup_function, arg); \
55 cancel_shmem_exit(cleanup_function, arg); \
56 cleanup_function (0, arg); \
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);
74 extern void CreateSharedMemoryAndSemaphores(bool makePrivate
, int port
);