diff options
author | Robert Haas <rhaas@postgresql.org> | 2014-10-08 14:35:43 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2014-10-08 14:38:31 -0400 |
commit | 7bb0e97407c32cbf7245ef91fcc27d120c81e872 (patch) | |
tree | 37c8d610272196ed5081c3343cbd7c159568da98 /src/include/storage/shm_mq.h | |
parent | df630b0dd5ea2de52972d456f5978a012436115e (diff) | |
download | postgresql-7bb0e97407c32cbf7245ef91fcc27d120c81e872.tar.gz postgresql-7bb0e97407c32cbf7245ef91fcc27d120c81e872.zip |
Extend shm_mq API with new functions shm_mq_sendv, shm_mq_set_handle.
shm_mq_sendv sends a message to the queue assembled from multiple
locations. This is expected to be used by forthcoming patches to
allow frontend/backend protocol messages to be sent via shm_mq, but
might be useful for other purposes as well.
shm_mq_set_handle associates a BackgroundWorkerHandle with an
already-existing shm_mq_handle. This solves a timing problem when
creating a shm_mq to communicate with a newly-launched background
worker: if you attach to the queue first, and the background worker
fails to start, you might block forever trying to do I/O on the queue;
but if you start the background worker first, but then die before
attaching to the queue, the background worrker might block forever
trying to do I/O on the queue. This lets you attach before starting
the worker (so that the worker is protected) and then associate the
BackgroundWorkerHandle later (so that you are also protected).
Patch by me, reviewed by Stephen Frost.
Diffstat (limited to 'src/include/storage/shm_mq.h')
-rw-r--r-- | src/include/storage/shm_mq.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/include/storage/shm_mq.h b/src/include/storage/shm_mq.h index 5bae3807afb..063400ae286 100644 --- a/src/include/storage/shm_mq.h +++ b/src/include/storage/shm_mq.h @@ -25,6 +25,13 @@ typedef struct shm_mq shm_mq; struct shm_mq_handle; typedef struct shm_mq_handle shm_mq_handle; +/* Descriptors for a single write spanning multiple locations. */ +typedef struct +{ + const char *data; + Size len; +} shm_mq_iovec; + /* Possible results of a send or receive operation. */ typedef enum { @@ -52,12 +59,17 @@ extern PGPROC *shm_mq_get_sender(shm_mq *); extern shm_mq_handle *shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle); +/* Associate worker handle with shm_mq. */ +extern void shm_mq_set_handle(shm_mq_handle *, BackgroundWorkerHandle *); + /* Break connection. */ extern void shm_mq_detach(shm_mq *); /* Send or receive messages. */ extern shm_mq_result shm_mq_send(shm_mq_handle *mqh, - Size nbytes, void *data, bool nowait); + Size nbytes, const void *data, bool nowait); +extern shm_mq_result shm_mq_sendv(shm_mq_handle *mqh, + shm_mq_iovec *iov, int iovcnt, bool nowait); extern shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait); |