pg_shmem.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_shmem.h
  4. * Platform-independent API for shared memory support.
  5. *
  6. * Every port is expected to support shared memory with approximately
  7. * SysV-ish semantics; in particular, a memory block is not anonymous
  8. * but has an ID, and we must be able to tell whether there are any
  9. * remaining processes attached to a block of a specified ID.
  10. *
  11. * To simplify life for the SysV implementation, the ID is assumed to
  12. * consist of two unsigned long values (these are key and ID in SysV
  13. * terms). Other platforms may ignore the second value if they need
  14. * only one ID number.
  15. *
  16. *
  17. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  18. * Portions Copyright (c) 1994, Regents of the University of California
  19. *
  20. * src/include/storage/pg_shmem.h
  21. *
  22. *-------------------------------------------------------------------------
  23. */
  24. #ifndef PG_SHMEM_H
  25. #define PG_SHMEM_H
  26. #include "storage/dsm_impl.h"
  27. typedef struct PGShmemHeader /* standard header for all Postgres shmem */
  28. {
  29. int32 magic; /* magic # to identify Postgres segments */
  30. #define PGShmemMagic 679834894
  31. pid_t creatorPID; /* PID of creating process */
  32. Size totalsize; /* total size of segment */
  33. Size freeoffset; /* offset to first free space */
  34. dsm_handle dsm_control; /* ID of dynamic shared memory control seg */
  35. void *index; /* pointer to ShmemIndex table */
  36. #ifndef WIN32 /* Windows doesn't have useful inode#s */
  37. dev_t device; /* device data directory is on */
  38. ino_t inode; /* inode number of data directory */
  39. #endif
  40. } PGShmemHeader;
  41. /* GUC variable */
  42. extern int huge_pages;
  43. /* Possible values for huge_pages */
  44. typedef enum
  45. {
  46. HUGE_PAGES_OFF,
  47. HUGE_PAGES_ON,
  48. HUGE_PAGES_TRY
  49. } HugePagesType;
  50. #ifndef WIN32
  51. extern unsigned long UsedShmemSegID;
  52. #else
  53. extern HANDLE UsedShmemSegID;
  54. #endif
  55. extern void *UsedShmemSegAddr;
  56. #ifdef EXEC_BACKEND
  57. extern void PGSharedMemoryReAttach(void);
  58. extern void PGSharedMemoryNoReAttach(void);
  59. #endif
  60. extern PGShmemHeader *PGSharedMemoryCreate(Size size, bool makePrivate,
  61. int port, PGShmemHeader **shim);
  62. extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
  63. extern void PGSharedMemoryDetach(void);
  64. #endif /* PG_SHMEM_H */