Header And Logo

PostgreSQL
| The world's most advanced open source database.

ipc.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * ipc.h
00004  *    POSTGRES inter-process communication definitions.
00005  *
00006  * This file is misnamed, as it no longer has much of anything directly
00007  * to do with IPC.  The functionality here is concerned with managing
00008  * exit-time cleanup for either a postmaster or a backend.
00009  *
00010  *
00011  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00012  * Portions Copyright (c) 1994, Regents of the University of California
00013  *
00014  * src/include/storage/ipc.h
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #ifndef IPC_H
00019 #define IPC_H
00020 
00021 typedef void (*pg_on_exit_callback) (int code, Datum arg);
00022 typedef void (*shmem_startup_hook_type) (void);
00023 
00024 /*----------
00025  * API for handling cleanup that must occur during either ereport(ERROR)
00026  * or ereport(FATAL) exits from a block of code.  (Typical examples are
00027  * undoing transient changes to shared-memory state.)
00028  *
00029  *      PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
00030  *      {
00031  *          ... code that might throw ereport(ERROR) or ereport(FATAL) ...
00032  *      }
00033  *      PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
00034  *
00035  * where the cleanup code is in a function declared per pg_on_exit_callback.
00036  * The Datum value "arg" can carry any information the cleanup function
00037  * needs.
00038  *
00039  * This construct ensures that cleanup_function() will be called during
00040  * either ERROR or FATAL exits.  It will not be called on successful
00041  * exit from the controlled code.  (If you want it to happen then too,
00042  * call the function yourself from just after the construct.)
00043  *
00044  * Note: the macro arguments are multiply evaluated, so avoid side-effects.
00045  *----------
00046  */
00047 #define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg)  \
00048     do { \
00049         on_shmem_exit(cleanup_function, arg); \
00050         PG_TRY()
00051 
00052 #define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg)  \
00053         cancel_shmem_exit(cleanup_function, arg); \
00054         PG_CATCH(); \
00055         { \
00056             cancel_shmem_exit(cleanup_function, arg); \
00057             cleanup_function (0, arg); \
00058             PG_RE_THROW(); \
00059         } \
00060         PG_END_TRY(); \
00061     } while (0)
00062 
00063 
00064 /* ipc.c */
00065 extern bool proc_exit_inprogress;
00066 
00067 extern void proc_exit(int code) __attribute__((noreturn));
00068 extern void shmem_exit(int code);
00069 extern void on_proc_exit(pg_on_exit_callback function, Datum arg);
00070 extern void on_shmem_exit(pg_on_exit_callback function, Datum arg);
00071 extern void cancel_shmem_exit(pg_on_exit_callback function, Datum arg);
00072 extern void on_exit_reset(void);
00073 
00074 /* ipci.c */
00075 extern PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook;
00076 
00077 extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int port);
00078 
00079 #endif   /* IPC_H */