1/*-------------------------------------------------------------------------
2 *
3 * dsm.h
4 * manage dynamic shared memory segments
5 *
6 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/storage/dsm.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef DSM_H
14#define DSM_H
15
16#include "storage/dsm_impl.h"
17
18typedef struct dsm_segment dsm_segment;
19
20#define DSM_CREATE_NULL_IF_MAXSEGMENTS 0x0001
21
22/* A sentinel value for an invalid DSM handle. */
23#define DSM_HANDLE_INVALID 0
24
25/* Startup and shutdown functions. */
26struct PGShmemHeader; /* avoid including pg_shmem.h */
27extern void dsm_cleanup_using_control_segment(dsm_handle old_control_handle);
28extern void dsm_postmaster_startup(struct PGShmemHeader *);
29extern void dsm_backend_shutdown(void);
30extern void dsm_detach_all(void);
31
32#ifdef EXEC_BACKEND
33extern void dsm_set_control_handle(dsm_handle h);
34#endif
35
36/* Functions that create or remove mappings. */
37extern dsm_segment *dsm_create(Size size, int flags);
38extern dsm_segment *dsm_attach(dsm_handle h);
39extern void dsm_detach(dsm_segment *seg);
40
41/* Resource management functions. */
42extern void dsm_pin_mapping(dsm_segment *seg);
43extern void dsm_unpin_mapping(dsm_segment *seg);
44extern void dsm_pin_segment(dsm_segment *seg);
45extern void dsm_unpin_segment(dsm_handle h);
46extern dsm_segment *dsm_find_mapping(dsm_handle h);
47
48/* Informational functions. */
49extern void *dsm_segment_address(dsm_segment *seg);
50extern Size dsm_segment_map_length(dsm_segment *seg);
51extern dsm_handle dsm_segment_handle(dsm_segment *seg);
52
53/* Cleanup hooks. */
54typedef void (*on_dsm_detach_callback) (dsm_segment *, Datum arg);
55extern void on_dsm_detach(dsm_segment *seg,
56 on_dsm_detach_callback function, Datum arg);
57extern void cancel_on_dsm_detach(dsm_segment *seg,
58 on_dsm_detach_callback function, Datum arg);
59extern void reset_on_dsm_detach(void);
60
61#endif /* DSM_H */
62