PostgreSQL Source Code git master
shm_mq.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * shm_mq.h
4 * single-reader, single-writer shared memory message queue
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/storage/shm_mq.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef SHM_MQ_H
14#define SHM_MQ_H
15
16#include "postmaster/bgworker.h"
17#include "storage/dsm.h"
18#include "storage/proc.h"
19
20/* The queue itself, in shared memory. */
21struct shm_mq;
22typedef struct shm_mq shm_mq;
23
24/* Backend-private state. */
25struct shm_mq_handle;
27
28/* Descriptors for a single write spanning multiple locations. */
29typedef struct
30{
31 const char *data;
34
35/* Possible results of a send or receive operation. */
36typedef enum
37{
38 SHM_MQ_SUCCESS, /* Sent or received a message. */
39 SHM_MQ_WOULD_BLOCK, /* Not completed; retry later. */
40 SHM_MQ_DETACHED, /* Other process has detached queue. */
42
43/*
44 * Primitives to create a queue and set the sender and receiver.
45 *
46 * Both the sender and the receiver must be set before any messages are read
47 * or written, but they need not be set by the same process. Each must be
48 * set exactly once.
49 */
50extern shm_mq *shm_mq_create(void *address, Size size);
51extern void shm_mq_set_receiver(shm_mq *mq, PGPROC *);
52extern void shm_mq_set_sender(shm_mq *mq, PGPROC *);
53
54/* Accessor methods for sender and receiver. */
57
58/* Set up backend-local queue state. */
61
62/* Associate worker handle with shm_mq. */
64
65/* Break connection, release handle resources. */
66extern void shm_mq_detach(shm_mq_handle *mqh);
67
68/* Get the shm_mq from handle. */
70
71/* Send or receive messages. */
73 Size nbytes, const void *data, bool nowait,
74 bool force_flush);
76 int iovcnt, bool nowait, bool force_flush);
78 Size *nbytesp, void **datap, bool nowait);
79
80/* Wait for our counterparty to attach to the queue. */
82
83/* Smallest possible queue. */
85
86#endif /* SHM_MQ_H */
#define PGDLLIMPORT
Definition: c.h:1277
size_t Size
Definition: c.h:562
const void * data
PGPROC * shm_mq_get_receiver(shm_mq *)
Definition: shm_mq.c:242
PGPROC * shm_mq_get_sender(shm_mq *)
Definition: shm_mq.c:257
void shm_mq_set_receiver(shm_mq *mq, PGPROC *)
Definition: shm_mq.c:206
shm_mq * shm_mq_get_queue(shm_mq_handle *mqh)
Definition: shm_mq.c:905
void shm_mq_set_handle(shm_mq_handle *, BackgroundWorkerHandle *)
Definition: shm_mq.c:319
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:177
void shm_mq_set_sender(shm_mq *mq, PGPROC *)
Definition: shm_mq.c:224
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:843
shm_mq_result shm_mq_sendv(shm_mq_handle *mqh, shm_mq_iovec *iov, int iovcnt, bool nowait, bool force_flush)
Definition: shm_mq.c:361
shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
Definition: shm_mq.c:572
shm_mq_result shm_mq_send(shm_mq_handle *mqh, Size nbytes, const void *data, bool nowait, bool force_flush)
Definition: shm_mq.c:329
shm_mq_result shm_mq_wait_for_attach(shm_mq_handle *mqh)
Definition: shm_mq.c:820
shm_mq_result
Definition: shm_mq.h:37
@ SHM_MQ_SUCCESS
Definition: shm_mq.h:38
@ SHM_MQ_WOULD_BLOCK
Definition: shm_mq.h:39
@ SHM_MQ_DETACHED
Definition: shm_mq.h:40
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:290
PGDLLIMPORT const Size shm_mq_minimum_size
Definition: shm_mq.c:168
static pg_noinline void Size size
Definition: slab.c:607
Definition: proc.h:162
const char * data
Definition: shm_mq.h:31
Size len
Definition: shm_mq.h:32
Definition: shm_mq.c:72