shmem.h 2.86 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * shmem.h
4
 *	  shared memory management structures
5 6
 *
 *
7
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $Id: shmem.h,v 1.32 2001/10/01 05:36:17 tgl Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14
#ifndef SHMEM_H
15 16
#define SHMEM_H

Bruce Momjian's avatar
Bruce Momjian committed
17
#include "utils/hsearch.h"
18

19

20 21
/*
 * The shared memory region can start at a different address
22 23
 * in every process.  Shared memory "pointers" are actually
 * offsets relative to the start of the shared memory region(s).
24 25 26
 *
 * In current usage, this is not actually a problem, but we keep
 * the code that used to handle it...
27 28
 */
typedef unsigned long SHMEM_OFFSET;
29

30 31
#define INVALID_OFFSET	(-1)
#define BAD_LOCATION	(-1)
32

33 34 35 36
/*
 * Start of the primary shared memory region, in this process' address space.
 * The macros in this header file can only cope with offsets into this
 * shared memory region!
37
 */
38
extern DLLIMPORT SHMEM_OFFSET ShmemBase;
39 40 41 42 43 44 45 46


/* coerce an offset into a pointer in this process's address space */
#define MAKE_PTR(xx_offs)\
  (ShmemBase+((unsigned long)(xx_offs)))

/* coerce a pointer into a shmem offset */
#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 53

/* cannot have an offset to ShmemFreeStart (offset 0) */
#define SHM_OFFSET_VALID(xx_offs)\
54
  (((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET))
55 56 57


/* shmemqueue.c */
58 59
typedef struct SHM_QUEUE
{
60 61
	SHMEM_OFFSET prev;
	SHMEM_OFFSET next;
62
} SHM_QUEUE;
63 64

/* shmem.c */
65
extern void InitShmemAllocation(void *seghdr);
66
extern void *ShmemAlloc(Size size);
67
extern bool ShmemIsValid(unsigned long addr);
68
extern void InitShmemIndex(void);
69
extern HTAB *ShmemInitHash(char *name, long init_size, long max_size,
70
			  HASHCTL *infoP, int hash_flags);
71
extern void *ShmemInitStruct(char *name, Size size, bool *foundPtr);
72 73


74
/* size constants for the shmem index table */
75
 /* max size of data structure string name */
76
#define SHMEM_INDEX_KEYSIZE		 (48)
77 78
 /* maximum size of the shmem index table */
#define SHMEM_INDEX_SIZE		 (100)
79

80
/* this is a hash bucket in the shmem index table */
81 82
typedef struct
{
83
	char		key[SHMEM_INDEX_KEYSIZE];		/* string name */
84 85
	unsigned long location;		/* location in shared mem */
	unsigned long size;			/* numbytes allocated for the structure */
86
} ShmemIndexEnt;
87 88 89 90

/*
 * prototypes for functions in shmqueue.c
 */
91 92 93
extern void SHMQueueInit(SHM_QUEUE *queue);
extern void SHMQueueElemInit(SHM_QUEUE *queue);
extern void SHMQueueDelete(SHM_QUEUE *queue);
94 95
extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
extern Pointer SHMQueueNext(SHM_QUEUE *queue, SHM_QUEUE *curElem,
96
			 Size linkOffset);
97
extern bool SHMQueueEmpty(SHM_QUEUE *queue);
98

99
#endif	 /* SHMEM_H */