PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_shmem.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_shmem.h
4  * Platform-independent API for shared memory support.
5  *
6  * Every port is expected to support shared memory with approximately
7  * SysV-ish semantics; in particular, a memory block is not anonymous
8  * but has an ID, and we must be able to tell whether there are any
9  * remaining processes attached to a block of a specified ID.
10  *
11  * To simplify life for the SysV implementation, the ID is assumed to
12  * consist of two unsigned long values (these are key and ID in SysV
13  * terms). Other platforms may ignore the second value if they need
14  * only one ID number.
15  *
16  *
17  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
18  * Portions Copyright (c) 1994, Regents of the University of California
19  *
20  * src/include/storage/pg_shmem.h
21  *
22  *-------------------------------------------------------------------------
23  */
24 #ifndef PG_SHMEM_H
25 #define PG_SHMEM_H
26 
27 #include "storage/dsm_impl.h"
28 
29 typedef struct PGShmemHeader /* standard header for all Postgres shmem */
30 {
31  int32 magic; /* magic # to identify Postgres segments */
32 #define PGShmemMagic 679834894
33  pid_t creatorPID; /* PID of creating process */
34  Size totalsize; /* total size of segment */
35  Size freeoffset; /* offset to first free space */
36  dsm_handle dsm_control; /* ID of dynamic shared memory control seg */
37  void *index; /* pointer to ShmemIndex table */
38 #ifndef WIN32 /* Windows doesn't have useful inode#s */
39  dev_t device; /* device data directory is on */
40  ino_t inode; /* inode number of data directory */
41 #endif
43 
44 /* GUC variable */
45 extern int huge_pages;
46 
47 /* Possible values for huge_pages */
48 typedef enum
49 {
54 
55 #ifndef WIN32
56 extern unsigned long UsedShmemSegID;
57 #else
58 extern HANDLE UsedShmemSegID;
59 #endif
60 extern void *UsedShmemSegAddr;
61 
62 #ifdef EXEC_BACKEND
63 extern void PGSharedMemoryReAttach(void);
64 extern void PGSharedMemoryNoReAttach(void);
65 #endif
66 
67 extern PGShmemHeader *PGSharedMemoryCreate(Size size, bool makePrivate,
68  int port, PGShmemHeader **shim);
69 extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
70 extern void PGSharedMemoryDetach(void);
71 
72 #endif /* PG_SHMEM_H */
HugePagesType
Definition: pg_shmem.h:48
pid_t creatorPID
Definition: pg_shmem.h:33
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:789
uint32 dsm_handle
Definition: dsm_impl.h:55
dsm_handle dsm_control
Definition: pg_shmem.h:36
struct PGShmemHeader PGShmemHeader
void PGSharedMemoryNoReAttach(void)
Definition: win32_shmem.c:315
unsigned long UsedShmemSegID
Definition: sysv_shmem.c:74
signed int int32
Definition: c.h:256
PGShmemHeader * PGSharedMemoryCreate(Size size, bool makePrivate, int port, PGShmemHeader **shim)
Definition: sysv_shmem.c:557
int huge_pages
Definition: guc.c:487
void PGSharedMemoryReAttach(void)
Definition: win32_shmem.c:271
static int port
Definition: pg_regress.c:89
int32 magic
Definition: pg_shmem.h:31
Size totalsize
Definition: pg_shmem.h:34
bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
Definition: sysv_shmem.c:288
void * UsedShmemSegAddr
Definition: sysv_shmem.c:75
ino_t inode
Definition: pg_shmem.h:40
dev_t device
Definition: pg_shmem.h:39
Size freeoffset
Definition: pg_shmem.h:35
size_t Size
Definition: c.h:356
void * index
Definition: pg_shmem.h:37