Header And Logo

PostgreSQL
| The world's most advanced open source database.

shmem.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * shmem.h
00004  *    shared memory management structures
00005  *
00006  * Historical note:
00007  * A long time ago, Postgres' shared memory region was allowed to be mapped
00008  * at a different address in each process, and shared memory "pointers" were
00009  * passed around as offsets relative to the start of the shared memory region.
00010  * That is no longer the case: each process must map the shared memory region
00011  * at the same address.  This means shared memory pointers can be passed
00012  * around directly between different processes.
00013  *
00014  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00015  * Portions Copyright (c) 1994, Regents of the University of California
00016  *
00017  * src/include/storage/shmem.h
00018  *
00019  *-------------------------------------------------------------------------
00020  */
00021 #ifndef SHMEM_H
00022 #define SHMEM_H
00023 
00024 #include "utils/hsearch.h"
00025 
00026 
00027 /* shmqueue.c */
00028 typedef struct SHM_QUEUE
00029 {
00030     struct SHM_QUEUE *prev;
00031     struct SHM_QUEUE *next;
00032 } SHM_QUEUE;
00033 
00034 /* shmem.c */
00035 extern void InitShmemAccess(void *seghdr);
00036 extern void InitShmemAllocation(void);
00037 extern void *ShmemAlloc(Size size);
00038 extern bool ShmemAddrIsValid(const void *addr);
00039 extern void InitShmemIndex(void);
00040 extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
00041               HASHCTL *infoP, int hash_flags);
00042 extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
00043 extern Size add_size(Size s1, Size s2);
00044 extern Size mul_size(Size s1, Size s2);
00045 
00046 /* ipci.c */
00047 extern void RequestAddinShmemSpace(Size size);
00048 
00049 /* size constants for the shmem index table */
00050  /* max size of data structure string name */
00051 #define SHMEM_INDEX_KEYSIZE      (48)
00052  /* estimated size of the shmem index table (not a hard limit) */
00053 #define SHMEM_INDEX_SIZE         (64)
00054 
00055 /* this is a hash bucket in the shmem index table */
00056 typedef struct
00057 {
00058     char        key[SHMEM_INDEX_KEYSIZE];       /* string name */
00059     void       *location;       /* location in shared mem */
00060     Size        size;           /* # bytes allocated for the structure */
00061 } ShmemIndexEnt;
00062 
00063 /*
00064  * prototypes for functions in shmqueue.c
00065  */
00066 extern void SHMQueueInit(SHM_QUEUE *queue);
00067 extern void SHMQueueElemInit(SHM_QUEUE *queue);
00068 extern void SHMQueueDelete(SHM_QUEUE *queue);
00069 extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
00070 extern void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem);
00071 extern Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
00072              Size linkOffset);
00073 extern Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
00074              Size linkOffset);
00075 extern bool SHMQueueEmpty(const SHM_QUEUE *queue);
00076 extern bool SHMQueueIsDetached(const SHM_QUEUE *queue);
00077 
00078 #endif   /* SHMEM_H */