2014-01-14 18:18:58 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* shm_toc.h
|
|
|
|
* shared memory segment table of contents
|
|
|
|
*
|
|
|
|
* This is intended to provide a simple way to divide a chunk of shared
|
|
|
|
* memory (probably dynamic shared memory allocated via dsm_create) into
|
2016-03-15 23:06:11 +01:00
|
|
|
* a number of regions and keep track of the addresses of those regions or
|
2014-01-14 18:18:58 +01:00
|
|
|
* key data structures within those regions. This is not intended to
|
|
|
|
* scale to a large number of keys and will perform poorly if used that
|
|
|
|
* way; if you need a large number of pointers, store them within some
|
|
|
|
* other data structure within the segment and only put the pointer to
|
|
|
|
* the data structure itself in the table of contents.
|
|
|
|
*
|
2022-01-08 01:04:57 +01:00
|
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2014-01-14 18:18:58 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* src/include/storage/shm_toc.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef SHM_TOC_H
|
|
|
|
#define SHM_TOC_H
|
|
|
|
|
2017-06-05 20:50:52 +02:00
|
|
|
#include "storage/shmem.h" /* for add_size() */
|
2014-01-14 18:18:58 +01:00
|
|
|
|
2017-06-05 20:50:52 +02:00
|
|
|
/* shm_toc is an opaque type known only within shm_toc.c */
|
2014-01-14 18:18:58 +01:00
|
|
|
typedef struct shm_toc shm_toc;
|
|
|
|
|
|
|
|
extern shm_toc *shm_toc_create(uint64 magic, void *address, Size nbytes);
|
|
|
|
extern shm_toc *shm_toc_attach(uint64 magic, void *address);
|
|
|
|
extern void *shm_toc_allocate(shm_toc *toc, Size nbytes);
|
|
|
|
extern Size shm_toc_freespace(shm_toc *toc);
|
|
|
|
extern void shm_toc_insert(shm_toc *toc, uint64 key, void *address);
|
2017-06-05 18:05:42 +02:00
|
|
|
extern void *shm_toc_lookup(shm_toc *toc, uint64 key, bool noError);
|
2014-01-14 18:18:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tools for estimating how large a chunk of shared memory will be needed
|
2017-06-05 20:50:52 +02:00
|
|
|
* to store a TOC and its dependent objects. Note: we don't really support
|
|
|
|
* large numbers of keys, but it's convenient to declare number_of_keys
|
|
|
|
* as a Size anyway.
|
2014-01-14 18:18:58 +01:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Size space_for_chunks;
|
|
|
|
Size number_of_keys;
|
|
|
|
} shm_toc_estimator;
|
|
|
|
|
|
|
|
#define shm_toc_initialize_estimator(e) \
|
|
|
|
((e)->space_for_chunks = 0, (e)->number_of_keys = 0)
|
|
|
|
#define shm_toc_estimate_chunk(e, sz) \
|
2017-06-05 20:50:52 +02:00
|
|
|
((e)->space_for_chunks = add_size((e)->space_for_chunks, BUFFERALIGN(sz)))
|
2014-01-14 18:18:58 +01:00
|
|
|
#define shm_toc_estimate_keys(e, cnt) \
|
2017-06-05 20:50:52 +02:00
|
|
|
((e)->number_of_keys = add_size((e)->number_of_keys, cnt))
|
2014-01-14 18:18:58 +01:00
|
|
|
|
2017-06-05 20:50:52 +02:00
|
|
|
extern Size shm_toc_estimate(shm_toc_estimator *e);
|
2014-01-14 18:18:58 +01:00
|
|
|
|
|
|
|
#endif /* SHM_TOC_H */
|