dsm_impl.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*-------------------------------------------------------------------------
  2. *
  3. * dsm_impl.h
  4. * low-level dynamic shared memory primitives
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/storage/dsm_impl.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef DSM_IMPL_H
  14. #define DSM_IMPL_H
  15. /* Dynamic shared memory implementations. */
  16. #define DSM_IMPL_POSIX 1
  17. #define DSM_IMPL_SYSV 2
  18. #define DSM_IMPL_WINDOWS 3
  19. #define DSM_IMPL_MMAP 4
  20. /*
  21. * Determine which dynamic shared memory implementations will be supported
  22. * on this platform, and which one will be the default.
  23. */
  24. #ifdef WIN32
  25. #define USE_DSM_WINDOWS
  26. #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_WINDOWS
  27. #else
  28. #ifdef HAVE_SHM_OPEN
  29. #define USE_DSM_POSIX
  30. #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_POSIX
  31. #endif
  32. #define USE_DSM_SYSV
  33. #ifndef DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE
  34. #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV
  35. #endif
  36. #define USE_DSM_MMAP
  37. #endif
  38. /* GUC. */
  39. extern PGDLLIMPORT int dynamic_shared_memory_type;
  40. extern PGDLLIMPORT int min_dynamic_shared_memory;
  41. /*
  42. * Directory for on-disk state.
  43. *
  44. * This is used by all implementations for crash recovery and by the mmap
  45. * implementation for storage.
  46. */
  47. #define PG_DYNSHMEM_DIR "pg_dynshmem"
  48. #define PG_DYNSHMEM_MMAP_FILE_PREFIX "mmap."
  49. /* A "name" for a dynamic shared memory segment. */
  50. typedef uint32 dsm_handle;
  51. /* All the shared-memory operations we know about. */
  52. typedef enum
  53. {
  54. DSM_OP_CREATE,
  55. DSM_OP_ATTACH,
  56. DSM_OP_DETACH,
  57. DSM_OP_DESTROY
  58. } dsm_op;
  59. /* Create, attach to, detach from, resize, or destroy a segment. */
  60. extern bool dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
  61. void **impl_private, void **mapped_address, Size *mapped_size,
  62. int elevel);
  63. /* Implementation-dependent actions required to keep segment until shutdown. */
  64. extern void dsm_impl_pin_segment(dsm_handle handle, void *impl_private,
  65. void **impl_private_pm_handle);
  66. extern void dsm_impl_unpin_segment(dsm_handle handle, void **impl_private);
  67. #endif /* DSM_IMPL_H */