PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
shmem.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * shmem.h
4  * shared memory management structures
5  *
6  * Historical note:
7  * A long time ago, Postgres' shared memory region was allowed to be mapped
8  * at a different address in each process, and shared memory "pointers" were
9  * passed around as offsets relative to the start of the shared memory region.
10  * That is no longer the case: each process must map the shared memory region
11  * at the same address. This means shared memory pointers can be passed
12  * around directly between different processes.
13  *
14  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * src/include/storage/shmem.h
18  *
19  *-------------------------------------------------------------------------
20  */
21 #ifndef SHMEM_H
22 #define SHMEM_H
23 
24 #include "utils/hsearch.h"
25 
26 
27 /* shmqueue.c */
28 typedef struct SHM_QUEUE
29 {
30  struct SHM_QUEUE *prev;
31  struct SHM_QUEUE *next;
32 } SHM_QUEUE;
33 
34 /* shmem.c */
35 extern void InitShmemAccess(void *seghdr);
36 extern void InitShmemAllocation(void);
37 extern void *ShmemAlloc(Size size);
38 extern void *ShmemAllocNoError(Size size);
39 extern void *ShmemAllocUnlocked(Size size);
40 extern bool ShmemAddrIsValid(const void *addr);
41 extern void InitShmemIndex(void);
42 extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
43  HASHCTL *infoP, int hash_flags);
44 extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
45 extern Size add_size(Size s1, Size s2);
46 extern Size mul_size(Size s1, Size s2);
47 
48 /* ipci.c */
49 extern void RequestAddinShmemSpace(Size size);
50 
51 /* size constants for the shmem index table */
52  /* max size of data structure string name */
53 #define SHMEM_INDEX_KEYSIZE (48)
54  /* estimated size of the shmem index table (not a hard limit) */
55 #define SHMEM_INDEX_SIZE (64)
56 
57 /* this is a hash bucket in the shmem index table */
58 typedef struct
59 {
60  char key[SHMEM_INDEX_KEYSIZE]; /* string name */
61  void *location; /* location in shared mem */
62  Size size; /* # bytes allocated for the structure */
64 
65 /*
66  * prototypes for functions in shmqueue.c
67  */
68 extern void SHMQueueInit(SHM_QUEUE *queue);
69 extern void SHMQueueElemInit(SHM_QUEUE *queue);
70 extern void SHMQueueDelete(SHM_QUEUE *queue);
71 extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
72 extern void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem);
73 extern Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
74  Size linkOffset);
75 extern Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
76  Size linkOffset);
77 extern bool SHMQueueEmpty(const SHM_QUEUE *queue);
78 extern bool SHMQueueIsDetached(const SHM_QUEUE *queue);
79 
80 #endif /* SHMEM_H */
void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem)
Definition: shmqueue.c:89
struct SHM_QUEUE * next
Definition: shmem.h:31
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
Size size
Definition: shmem.h:62
void SHMQueueDelete(SHM_QUEUE *queue)
Definition: shmqueue.c:68
void InitShmemAllocation(void)
Definition: shmem.c:112
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
Definition: dynahash.c:208
void InitShmemIndex(void)
Definition: shmem.c:272
char * Pointer
Definition: c.h:245
char * s1
void * location
Definition: shmem.h:61
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
Definition: shmqueue.c:164
char * s2
struct SHM_QUEUE * prev
Definition: shmem.h:30
void * ShmemAllocNoError(Size size)
Definition: shmem.c:176
size_t Size
Definition: c.h:356
void * ShmemAlloc(Size size)
Definition: shmem.c:157
#define SHMEM_INDEX_KEYSIZE
Definition: shmem.h:53
void * ShmemAllocUnlocked(Size size)
Definition: shmem.c:227
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:317
bool SHMQueueEmpty(const SHM_QUEUE *queue)
Definition: shmqueue.c:180
void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem)
Definition: shmqueue.c:108
const char * name
Definition: encode.c:521
void InitShmemAccess(void *seghdr)
Definition: shmem.c:97
void RequestAddinShmemSpace(Size size)
Definition: ipci.c:69
struct SHM_QUEUE SHM_QUEUE
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
void SHMQueueInit(SHM_QUEUE *queue)
Definition: shmqueue.c:36
bool SHMQueueIsDetached(const SHM_QUEUE *queue)
Definition: shmqueue.c:47
void SHMQueueElemInit(SHM_QUEUE *queue)
Definition: shmqueue.c:57
Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
Definition: shmqueue.c:145