]> granicus.if.org Git - postgresql/blob - src/include/storage/shmem.h
The attached patch enables the contrib subtree to build cleanly under
[postgresql] / src / include / storage / shmem.h
1 /*-------------------------------------------------------------------------
2  *
3  * shmem.h
4  *        shared memory management structures
5  *
6  *
7  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: shmem.h,v 1.29 2001/06/18 21:38:02 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef SHMEM_H
15 #define SHMEM_H
16
17 #include "storage/spin.h"
18 #include "utils/hsearch.h"
19
20
21 /*
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).
25  *
26  * In current usage, this is not actually a problem, but we keep
27  * the code that used to handle it...
28  */
29 typedef unsigned long SHMEM_OFFSET;
30
31 #define INVALID_OFFSET  (-1)
32 #define BAD_LOCATION    (-1)
33
34 /*
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!
38  */
39 extern DLLIMPORT SHMEM_OFFSET ShmemBase;
40
41
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)))
45
46 /* coerce a pointer into a shmem offset */
47 #define MAKE_OFFSET(xx_ptr)\
48   ((SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase))
49
50 #define SHM_PTR_VALID(xx_ptr)\
51   (((unsigned long)(xx_ptr)) > ShmemBase)
52
53 /* cannot have an offset to ShmemFreeStart (offset 0) */
54 #define SHM_OFFSET_VALID(xx_offs)\
55   (((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET))
56
57
58 extern SPINLOCK ShmemLock;
59 extern SPINLOCK ShmemIndexLock;
60
61 /* shmemqueue.c */
62 typedef struct SHM_QUEUE
63 {
64         SHMEM_OFFSET prev;
65         SHMEM_OFFSET next;
66 } SHM_QUEUE;
67
68 /* shmem.c */
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);
77
78
79 typedef int TableID;
80
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)
88
89 /* this is a hash bucket in the shmem index table */
90 typedef struct
91 {
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 */
95 } ShmemIndexEnt;
96
97 /*
98  * prototypes for functions in shmqueue.c
99  */
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,
105                          Size linkOffset);
106 extern bool SHMQueueEmpty(SHM_QUEUE *queue);
107
108 #endif   /* SHMEM_H */