1 /*-------------------------------------------------------------------------
4 * shared memory management structures
7 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: shmem.h,v 1.29 2001/06/18 21:38:02 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "storage/spin.h"
18 #include "utils/hsearch.h"
22 * The shared memory region can start at a different address
23 * in every process. Shared memory "pointers" are actually
24 * offsets relative to the start of the shared memory region(s).
26 * In current usage, this is not actually a problem, but we keep
27 * the code that used to handle it...
29 typedef unsigned long SHMEM_OFFSET;
31 #define INVALID_OFFSET (-1)
32 #define BAD_LOCATION (-1)
35 * Start of the primary shared memory region, in this process' address space.
36 * The macros in this header file can only cope with offsets into this
37 * shared memory region!
39 extern DLLIMPORT SHMEM_OFFSET ShmemBase;
42 /* coerce an offset into a pointer in this process's address space */
43 #define MAKE_PTR(xx_offs)\
44 (ShmemBase+((unsigned long)(xx_offs)))
46 /* coerce a pointer into a shmem offset */
47 #define MAKE_OFFSET(xx_ptr)\
48 ((SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase))
50 #define SHM_PTR_VALID(xx_ptr)\
51 (((unsigned long)(xx_ptr)) > ShmemBase)
53 /* cannot have an offset to ShmemFreeStart (offset 0) */
54 #define SHM_OFFSET_VALID(xx_offs)\
55 (((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET))
58 extern SPINLOCK ShmemLock;
59 extern SPINLOCK ShmemIndexLock;
62 typedef struct SHM_QUEUE
69 extern void InitShmemAllocation(PGShmemHeader *seghdr);
70 extern void *ShmemAlloc(Size size);
71 extern bool ShmemIsValid(unsigned long addr);
72 extern HTAB *ShmemInitHash(char *name, long init_size, long max_size,
73 HASHCTL *infoP, int hash_flags);
74 extern bool ShmemPIDLookup(int pid, SHMEM_OFFSET *locationPtr);
75 extern SHMEM_OFFSET ShmemPIDDestroy(int pid);
76 extern void *ShmemInitStruct(char *name, Size size, bool *foundPtr);
81 /* size constants for the shmem index table */
82 /* max size of data structure string name */
83 #define SHMEM_INDEX_KEYSIZE (50)
84 /* data in shmem index table hash bucket */
85 #define SHMEM_INDEX_DATASIZE (sizeof(ShmemIndexEnt) - SHMEM_INDEX_KEYSIZE)
86 /* maximum size of the shmem index table */
87 #define SHMEM_INDEX_SIZE (100)
89 /* this is a hash bucket in the shmem index table */
92 char key[SHMEM_INDEX_KEYSIZE]; /* string name */
93 unsigned long location; /* location in shared mem */
94 unsigned long size; /* numbytes allocated for the structure */
98 * prototypes for functions in shmqueue.c
100 extern void SHMQueueInit(SHM_QUEUE *queue);
101 extern void SHMQueueElemInit(SHM_QUEUE *queue);
102 extern void SHMQueueDelete(SHM_QUEUE *queue);
103 extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
104 extern Pointer SHMQueueNext(SHM_QUEUE *queue, SHM_QUEUE *curElem,
106 extern bool SHMQueueEmpty(SHM_QUEUE *queue);