]> granicus.if.org Git - postgresql/blob - src/include/storage/shmem.h
First phase of project to use fixed OIDs for all system catalogs and
[postgresql] / src / include / storage / shmem.h
1 /*-------------------------------------------------------------------------
2  *
3  * shmem.h
4  *        shared memory management structures
5  *
6  *
7  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.44 2004/12/31 22:03:42 pgsql Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef SHMEM_H
15 #define SHMEM_H
16
17 #include "utils/hsearch.h"
18
19
20 /*
21  * The shared memory region can start at a different address
22  * in every process.  Shared memory "pointers" are actually
23  * offsets relative to the start of the shared memory region(s).
24  *
25  * In current usage, this is not actually a problem, but we keep
26  * the code that used to handle it...
27  */
28 typedef unsigned long SHMEM_OFFSET;
29
30 #define INVALID_OFFSET  (-1)
31 #define BAD_LOCATION    (-1)
32
33 /*
34  * Start of the primary shared memory region, in this process' address space.
35  * The macros in this header file can only cope with offsets into this
36  * shared memory region!
37  */
38 extern DLLIMPORT SHMEM_OFFSET ShmemBase;
39
40
41 /* coerce an offset into a pointer in this process's address space */
42 #define MAKE_PTR(xx_offs)\
43   (ShmemBase+((unsigned long)(xx_offs)))
44
45 /* coerce a pointer into a shmem offset */
46 #define MAKE_OFFSET(xx_ptr)\
47   ((SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase))
48
49 #define SHM_PTR_VALID(xx_ptr)\
50   (((unsigned long)(xx_ptr)) > ShmemBase)
51
52 /* cannot have an offset to ShmemFreeStart (offset 0) */
53 #define SHM_OFFSET_VALID(xx_offs)\
54   (((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET))
55
56 /* shmqueue.c */
57 typedef struct SHM_QUEUE
58 {
59         SHMEM_OFFSET prev;
60         SHMEM_OFFSET next;
61 } SHM_QUEUE;
62
63 /* shmem.c */
64 extern void InitShmemAllocation(void *seghdr, bool init);
65 extern void *ShmemAlloc(Size size);
66 extern bool ShmemIsValid(unsigned long addr);
67 extern void InitShmemIndex(void);
68 extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
69                           HASHCTL *infoP, int hash_flags);
70 extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
71
72
73 /* size constants for the shmem index table */
74  /* max size of data structure string name */
75 #define SHMEM_INDEX_KEYSIZE              (48)
76  /* max size of the shmem index table (not a hard limit) */
77 #define SHMEM_INDEX_SIZE                 (32)
78
79 /* this is a hash bucket in the shmem index table */
80 typedef struct
81 {
82         char            key[SHMEM_INDEX_KEYSIZE];               /* string name */
83         unsigned long location;         /* location in shared mem */
84         unsigned long size;                     /* numbytes allocated for the structure */
85 } ShmemIndexEnt;
86
87 /*
88  * prototypes for functions in shmqueue.c
89  */
90 extern void SHMQueueInit(SHM_QUEUE *queue);
91 extern void SHMQueueElemInit(SHM_QUEUE *queue);
92 extern void SHMQueueDelete(SHM_QUEUE *queue);
93 extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
94 extern Pointer SHMQueueNext(SHM_QUEUE *queue, SHM_QUEUE *curElem,
95                          Size linkOffset);
96 extern bool SHMQueueEmpty(SHM_QUEUE *queue);
97
98 #endif   /* SHMEM_H */