PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
shm_toc.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * shm_toc.h
4  * shared memory segment table of contents
5  *
6  * This is intended to provide a simple way to divide a chunk of shared
7  * memory (probably dynamic shared memory allocated via dsm_create) into
8  * a number of regions and keep track of the addresses of those regions or
9  * key data structures within those regions. This is not intended to
10  * scale to a large number of keys and will perform poorly if used that
11  * way; if you need a large number of pointers, store them within some
12  * other data structure within the segment and only put the pointer to
13  * the data structure itself in the table of contents.
14  *
15  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
16  * Portions Copyright (c) 1994, Regents of the University of California
17  *
18  * src/include/storage/shm_toc.h
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef SHM_TOC_H
23 #define SHM_TOC_H
24 
25 #include "storage/shmem.h"
26 
27 struct shm_toc;
28 typedef struct shm_toc shm_toc;
29 
30 extern shm_toc *shm_toc_create(uint64 magic, void *address, Size nbytes);
31 extern shm_toc *shm_toc_attach(uint64 magic, void *address);
32 extern void *shm_toc_allocate(shm_toc *toc, Size nbytes);
33 extern Size shm_toc_freespace(shm_toc *toc);
34 extern void shm_toc_insert(shm_toc *toc, uint64 key, void *address);
35 extern void *shm_toc_lookup(shm_toc *toc, uint64 key);
36 
37 /*
38  * Tools for estimating how large a chunk of shared memory will be needed
39  * to store a TOC and its dependent objects.
40  */
41 typedef struct
42 {
46 
47 #define shm_toc_initialize_estimator(e) \
48  ((e)->space_for_chunks = 0, (e)->number_of_keys = 0)
49 #define shm_toc_estimate_chunk(e, sz) \
50  ((e)->space_for_chunks = add_size((e)->space_for_chunks, \
51  BUFFERALIGN((sz))))
52 #define shm_toc_estimate_keys(e, cnt) \
53  ((e)->number_of_keys = add_size((e)->number_of_keys, (cnt)))
54 
56 
57 #endif /* SHM_TOC_H */
Size number_of_keys
Definition: shm_toc.h:44
Size shm_toc_freespace(shm_toc *toc)
Definition: shm_toc.c:121
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:83
shm_toc * shm_toc_create(uint64 magic, void *address, Size nbytes)
Definition: shm_toc.c:40
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:161
Size space_for_chunks
Definition: shm_toc.h:43
void * shm_toc_lookup(shm_toc *toc, uint64 key)
Definition: shm_toc.c:218
size_t Size
Definition: c.h:356
shm_toc * shm_toc_attach(uint64 magic, void *address)
Definition: shm_toc.c:59
Size shm_toc_estimate(shm_toc_estimator *)
Definition: shm_toc.c:241