2
0

shmem.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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-2022, 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 void *ShmemAllocNoError(Size size);
  35. extern void *ShmemAllocUnlocked(Size size);
  36. extern bool ShmemAddrIsValid(const void *addr);
  37. extern void InitShmemIndex(void);
  38. extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
  39. HASHCTL *infoP, int hash_flags);
  40. extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
  41. extern Size add_size(Size s1, Size s2);
  42. extern Size mul_size(Size s1, Size s2);
  43. /* ipci.c */
  44. extern void RequestAddinShmemSpace(Size size);
  45. /* size constants for the shmem index table */
  46. /* max size of data structure string name */
  47. #define SHMEM_INDEX_KEYSIZE (48)
  48. /* estimated size of the shmem index table (not a hard limit) */
  49. #define SHMEM_INDEX_SIZE (64)
  50. /* this is a hash bucket in the shmem index table */
  51. typedef struct
  52. {
  53. char key[SHMEM_INDEX_KEYSIZE]; /* string name */
  54. void *location; /* location in shared mem */
  55. Size size; /* # bytes requested for the structure */
  56. Size allocated_size; /* # bytes actually allocated */
  57. } ShmemIndexEnt;
  58. /*
  59. * prototypes for functions in shmqueue.c
  60. */
  61. extern void SHMQueueInit(SHM_QUEUE *queue);
  62. extern void SHMQueueElemInit(SHM_QUEUE *queue);
  63. extern void SHMQueueDelete(SHM_QUEUE *queue);
  64. extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
  65. extern void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem);
  66. extern Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
  67. Size linkOffset);
  68. extern Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
  69. Size linkOffset);
  70. extern bool SHMQueueEmpty(const SHM_QUEUE *queue);
  71. extern bool SHMQueueIsDetached(const SHM_QUEUE *queue);
  72. #endif /* SHMEM_H */