1
/*-------------------------------------------------------------------------
4
* shared memory management structures
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
10
* $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.44 2004-12-31 22:03:42 pgsql Exp $
12
*-------------------------------------------------------------------------
17
#include "utils/hsearch.h"
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).
25
* In current usage, this is not actually a problem, but we keep
26
* the code that used to handle it...
28
typedef unsigned long SHMEM_OFFSET;
30
#define INVALID_OFFSET (-1)
31
#define BAD_LOCATION (-1)
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!
38
extern DLLIMPORT SHMEM_OFFSET ShmemBase;
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)))
45
/* coerce a pointer into a shmem offset */
46
#define MAKE_OFFSET(xx_ptr)\
47
((SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase))
49
#define SHM_PTR_VALID(xx_ptr)\
50
(((unsigned long)(xx_ptr)) > ShmemBase)
52
/* cannot have an offset to ShmemFreeStart (offset 0) */
53
#define SHM_OFFSET_VALID(xx_offs)\
54
(((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET))
57
typedef struct SHM_QUEUE
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);
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)
79
/* this is a hash bucket in the shmem index table */
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 */
88
* prototypes for functions in shmqueue.c
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,
96
extern bool SHMQueueEmpty(SHM_QUEUE *queue);