1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* shmem.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* shared memory management structures
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2006-01-04 22:06:32 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.46 2006/01/04 21:06:32 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef SHMEM_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define SHMEM_H
|
|
|
|
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "utils/hsearch.h"
|
1996-11-05 07:11:08 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-29 00:27:57 +01:00
|
|
|
/*
|
|
|
|
* The shared memory region can start at a different address
|
1996-08-28 03:59:28 +02:00
|
|
|
* in every process. Shared memory "pointers" are actually
|
|
|
|
* offsets relative to the start of the shared memory region(s).
|
2000-11-29 00:27:57 +01:00
|
|
|
*
|
|
|
|
* In current usage, this is not actually a problem, but we keep
|
|
|
|
* the code that used to handle it...
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
typedef unsigned long SHMEM_OFFSET;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define INVALID_OFFSET (-1)
|
|
|
|
#define BAD_LOCATION (-1)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-29 00:27:57 +01:00
|
|
|
/*
|
|
|
|
* 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!
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2001-06-18 23:38:02 +02:00
|
|
|
extern DLLIMPORT SHMEM_OFFSET ShmemBase;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* 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)\
|
2000-11-29 00:27:57 +01:00
|
|
|
((SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define SHM_PTR_VALID(xx_ptr)\
|
2000-11-29 00:27:57 +01:00
|
|
|
(((unsigned long)(xx_ptr)) > ShmemBase)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* cannot have an offset to ShmemFreeStart (offset 0) */
|
|
|
|
#define SHM_OFFSET_VALID(xx_offs)\
|
2000-11-29 00:27:57 +01:00
|
|
|
(((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-08-17 15:04:19 +02:00
|
|
|
/* shmqueue.c */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct SHM_QUEUE
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
SHMEM_OFFSET prev;
|
|
|
|
SHMEM_OFFSET next;
|
1997-09-08 23:56:23 +02:00
|
|
|
} SHM_QUEUE;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* shmem.c */
|
2006-01-04 22:06:32 +01:00
|
|
|
extern void InitShmemAccess(void *seghdr);
|
|
|
|
extern void InitShmemAllocation(void);
|
2000-06-28 05:33:33 +02:00
|
|
|
extern void *ShmemAlloc(Size size);
|
2000-11-29 00:27:57 +01:00
|
|
|
extern bool ShmemIsValid(unsigned long addr);
|
2001-09-29 06:02:27 +02:00
|
|
|
extern void InitShmemIndex(void);
|
2001-10-05 19:28:13 +02:00
|
|
|
extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
|
1997-09-08 23:56:23 +02:00
|
|
|
HASHCTL *infoP, int hash_flags);
|
2001-10-05 19:28:13 +02:00
|
|
|
extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
|
2005-08-21 01:26:37 +02:00
|
|
|
extern Size add_size(Size s1, Size s2);
|
|
|
|
extern Size mul_size(Size s1, Size s2);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-06-27 17:47:48 +02:00
|
|
|
/* size constants for the shmem index table */
|
1997-09-07 07:04:48 +02:00
|
|
|
/* max size of data structure string name */
|
2001-10-01 07:36:17 +02:00
|
|
|
#define SHMEM_INDEX_KEYSIZE (48)
|
2004-09-28 22:46:37 +02:00
|
|
|
/* max size of the shmem index table (not a hard limit) */
|
|
|
|
#define SHMEM_INDEX_SIZE (32)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-06-27 17:47:48 +02:00
|
|
|
/* this is a hash bucket in the shmem index table */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
char key[SHMEM_INDEX_KEYSIZE]; /* string name */
|
1997-09-08 04:41:22 +02:00
|
|
|
unsigned long location; /* location in shared mem */
|
|
|
|
unsigned long size; /* numbytes allocated for the structure */
|
1999-05-26 00:43:53 +02:00
|
|
|
} ShmemIndexEnt;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions in shmqueue.c
|
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void SHMQueueInit(SHM_QUEUE *queue);
|
|
|
|
extern void SHMQueueElemInit(SHM_QUEUE *queue);
|
|
|
|
extern void SHMQueueDelete(SHM_QUEUE *queue);
|
2001-01-22 23:30:06 +01:00
|
|
|
extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
|
|
|
|
extern Pointer SHMQueueNext(SHM_QUEUE *queue, SHM_QUEUE *curElem,
|
2001-03-22 05:01:46 +01:00
|
|
|
Size linkOffset);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern bool SHMQueueEmpty(SHM_QUEUE *queue);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* SHMEM_H */
|