2
0

ipc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*-------------------------------------------------------------------------
  2. *
  3. * ipc.h
  4. * POSTGRES inter-process communication definitions.
  5. *
  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.
  9. *
  10. *
  11. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  12. * Portions Copyright (c) 1994, Regents of the University of California
  13. *
  14. * src/include/storage/ipc.h
  15. *
  16. *-------------------------------------------------------------------------
  17. */
  18. #ifndef IPC_H
  19. #define IPC_H
  20. typedef void (*pg_on_exit_callback) (int code, Datum arg);
  21. typedef void (*shmem_startup_hook_type) (void);
  22. /*----------
  23. * API for handling cleanup that must occur during either ereport(ERROR)
  24. * or ereport(FATAL) exits from a block of code. (Typical examples are
  25. * undoing transient changes to shared-memory state.)
  26. *
  27. * PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
  28. * {
  29. * ... code that might throw ereport(ERROR) or ereport(FATAL) ...
  30. * }
  31. * PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg);
  32. *
  33. * where the cleanup code is in a function declared per pg_on_exit_callback.
  34. * The Datum value "arg" can carry any information the cleanup function
  35. * needs.
  36. *
  37. * This construct ensures that cleanup_function() will be called during
  38. * either ERROR or FATAL exits. It will not be called on successful
  39. * exit from the controlled code. (If you want it to happen then too,
  40. * call the function yourself from just after the construct.)
  41. *
  42. * Note: the macro arguments are multiply evaluated, so avoid side-effects.
  43. *----------
  44. */
  45. #define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
  46. do { \
  47. before_shmem_exit(cleanup_function, arg); \
  48. PG_TRY()
  49. #define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \
  50. cancel_before_shmem_exit(cleanup_function, arg); \
  51. PG_CATCH(); \
  52. { \
  53. cancel_before_shmem_exit(cleanup_function, arg); \
  54. cleanup_function (0, arg); \
  55. PG_RE_THROW(); \
  56. } \
  57. PG_END_TRY(); \
  58. } while (0)
  59. /* ipc.c */
  60. extern PGDLLIMPORT bool proc_exit_inprogress;
  61. extern PGDLLIMPORT bool shmem_exit_inprogress;
  62. extern void proc_exit(int code) pg_attribute_noreturn();
  63. extern void shmem_exit(int code);
  64. extern void on_proc_exit(pg_on_exit_callback function, Datum arg);
  65. extern void on_shmem_exit(pg_on_exit_callback function, Datum arg);
  66. extern void before_shmem_exit(pg_on_exit_callback function, Datum arg);
  67. extern void cancel_before_shmem_exit(pg_on_exit_callback function, Datum arg);
  68. extern void on_exit_reset(void);
  69. extern void check_on_shmem_exit_lists_are_empty(void);
  70. /* ipci.c */
  71. extern PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook;
  72. extern Size CalculateShmemSize(int *num_semaphores);
  73. extern void CreateSharedMemoryAndSemaphores(void);
  74. extern void InitializeShmemGUCs(void);
  75. #endif /* IPC_H */