shmem.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*-------------------------------------------------------------------------
  2. *
  3. * shmem.h
  4. * shared memory management structures
  5. *
  6. * Historical note:
  7. * A long time ago, Postgres' shared memory region was allowed to be mapped
  8. * at a different address in each process, and shared memory "pointers" were
  9. * passed around as offsets relative to the start of the shared memory region.
  10. * That is no longer the case: each process must map the shared memory region
  11. * at the same address. This means shared memory pointers can be passed
  12. * around directly between different processes.
  13. *
  14. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  15. * Portions Copyright (c) 1994, Regents of the University of California
  16. *
  17. * src/include/storage/shmem.h
  18. *
  19. *-------------------------------------------------------------------------
  20. */
  21. #ifndef SHMEM_H
  22. #define SHMEM_H
  23. #include "utils/hsearch.h"
  24. /* shmqueue.c */
  25. typedef struct SHM_QUEUE
  26. {
  27. struct SHM_QUEUE *prev;
  28. struct SHM_QUEUE *next;
  29. } SHM_QUEUE;
  30. /* shmem.c */
  31. extern void InitShmemAccess(void *seghdr);
  32. extern void InitShmemAllocation(void);
  33. extern void *ShmemAlloc(Size size);
  34. extern bool ShmemAddrIsValid(const void *addr);
  35. extern void InitShmemIndex(void);
  36. extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
  37. HASHCTL *infoP, int hash_flags);
  38. extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
  39. extern Size add_size(Size s1, Size s2);
  40. extern Size mul_size(Size s1, Size s2);
  41. /* ipci.c */
  42. extern void RequestAddinShmemSpace(Size size);
  43. /* size constants for the shmem index table */
  44. /* max size of data structure string name */
  45. #define SHMEM_INDEX_KEYSIZE (48)
  46. /* estimated size of the shmem index table (not a hard limit) */
  47. #define SHMEM_INDEX_SIZE (64)
  48. /* this is a hash bucket in the shmem index table */
  49. typedef struct
  50. {
  51. char key[SHMEM_INDEX_KEYSIZE]; /* string name */
  52. void *location; /* location in shared mem */
  53. Size size; /* # bytes allocated for the structure */
  54. } ShmemIndexEnt;
  55. /*
  56. * prototypes for functions in shmqueue.c
  57. */
  58. extern void SHMQueueInit(SHM_QUEUE *queue);
  59. extern void SHMQueueElemInit(SHM_QUEUE *queue);
  60. extern void SHMQueueDelete(SHM_QUEUE *queue);
  61. extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
  62. extern void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem);
  63. extern Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
  64. Size linkOffset);
  65. extern Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
  66. Size linkOffset);
  67. extern bool SHMQueueEmpty(const SHM_QUEUE *queue);
  68. extern bool SHMQueueIsDetached(const SHM_QUEUE *queue);
  69. #endif /* SHMEM_H */