PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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
19/* avoid including storage/proc.h */
20typedef struct PGPROC PGPROC;
21
22/* The queue itself, in shared memory. */
23struct shm_mq;
24typedef struct shm_mq shm_mq;
25
26/* Backend-private state. */
27struct shm_mq_handle;
29
30/* Descriptors for a single write spanning multiple locations. */
31typedef struct
32{
33 const char *data;
36
37/* Possible results of a send or receive operation. */
38typedef enum
39{
40 SHM_MQ_SUCCESS, /* Sent or received a message. */
41 SHM_MQ_WOULD_BLOCK, /* Not completed; retry later. */
42 SHM_MQ_DETACHED, /* Other process has detached queue. */
44
45/*
46 * Primitives to create a queue and set the sender and receiver.
47 *
48 * Both the sender and the receiver must be set before any messages are read
49 * or written, but they need not be set by the same process. Each must be
50 * set exactly once.
51 */
52extern shm_mq *shm_mq_create(void *address, Size size);
53extern void shm_mq_set_receiver(shm_mq *mq, PGPROC *);
54extern void shm_mq_set_sender(shm_mq *mq, PGPROC *);
55
56/* Accessor methods for sender and receiver. */
59
60/* Set up backend-local queue state. */
63
64/* Associate worker handle with shm_mq. */
66
67/* Break connection, release handle resources. */
68extern void shm_mq_detach(shm_mq_handle *mqh);
69
70/* Get the shm_mq from handle. */
72
73/* Send or receive messages. */
75 Size nbytes, const void *data, bool nowait,
76 bool force_flush);
78 int iovcnt, bool nowait, bool force_flush);
80 Size *nbytesp, void **datap, bool nowait);
81
82/* Wait for our counterparty to attach to the queue. */
84
85/* Smallest possible queue. */
87
88#endif /* SHM_MQ_H */
#define PGDLLIMPORT
Definition c.h:1356
size_t Size
Definition c.h:631
const void * data
static int fb(int x)
PGPROC * shm_mq_get_receiver(shm_mq *)
Definition shm_mq.c:243
PGPROC * shm_mq_get_sender(shm_mq *)
Definition shm_mq.c:258
void shm_mq_set_receiver(shm_mq *mq, PGPROC *)
Definition shm_mq.c:207
shm_mq * shm_mq_get_queue(shm_mq_handle *mqh)
Definition shm_mq.c:906
void shm_mq_set_handle(shm_mq_handle *, BackgroundWorkerHandle *)
Definition shm_mq.c:320
shm_mq * shm_mq_create(void *address, Size size)
Definition shm_mq.c:178
void shm_mq_set_sender(shm_mq *mq, PGPROC *)
Definition shm_mq.c:225
void shm_mq_detach(shm_mq_handle *mqh)
Definition shm_mq.c:844
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:362
shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
Definition shm_mq.c:573
shm_mq_result shm_mq_send(shm_mq_handle *mqh, Size nbytes, const void *data, bool nowait, bool force_flush)
Definition shm_mq.c:330
shm_mq_result shm_mq_wait_for_attach(shm_mq_handle *mqh)
Definition shm_mq.c:821
shm_mq_result
Definition shm_mq.h:39
@ SHM_MQ_SUCCESS
Definition shm_mq.h:40
@ SHM_MQ_WOULD_BLOCK
Definition shm_mq.h:41
@ SHM_MQ_DETACHED
Definition shm_mq.h:42
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition shm_mq.c:291
PGDLLIMPORT const Size shm_mq_minimum_size
Definition shm_mq.c:169
Definition proc.h:176
const char * data
Definition shm_mq.h:33
Size len
Definition shm_mq.h:34