PostgreSQL Source Code  git master
tqueue.h File Reference
#include "storage/shm_mq.h"
#include "tcop/dest.h"
Include dependency graph for tqueue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct TupleQueueReader TupleQueueReader
 

Functions

DestReceiverCreateTupleQueueDestReceiver (shm_mq_handle *handle)
 
TupleQueueReaderCreateTupleQueueReader (shm_mq_handle *handle)
 
void DestroyTupleQueueReader (TupleQueueReader *reader)
 
HeapTuple TupleQueueReaderNext (TupleQueueReader *reader, bool nowait, bool *done)
 

Typedef Documentation

◆ TupleQueueReader

Definition at line 21 of file tqueue.h.

Function Documentation

◆ CreateTupleQueueDestReceiver()

DestReceiver* CreateTupleQueueDestReceiver ( shm_mq_handle handle)

Definition at line 115 of file tqueue.c.

References DestTupleQueue, palloc0(), tqueueDestroyReceiver(), tqueueReceiveSlot(), tqueueShutdownReceiver(), and tqueueStartupReceiver().

Referenced by CreateDestReceiver(), and ExecParallelGetReceiver().

116 {
117  TQueueDestReceiver *self;
118 
119  self = (TQueueDestReceiver *) palloc0(sizeof(TQueueDestReceiver));
120 
121  self->pub.receiveSlot = tqueueReceiveSlot;
122  self->pub.rStartup = tqueueStartupReceiver;
123  self->pub.rShutdown = tqueueShutdownReceiver;
124  self->pub.rDestroy = tqueueDestroyReceiver;
125  self->pub.mydest = DestTupleQueue;
126  self->queue = handle;
127 
128  return (DestReceiver *) self;
129 }
static void tqueueDestroyReceiver(DestReceiver *self)
Definition: tqueue.c:101
static void tqueueStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: tqueue.c:79
static bool tqueueReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
Definition: tqueue.c:54
void * palloc0(Size size)
Definition: mcxt.c:864
static void tqueueShutdownReceiver(DestReceiver *self)
Definition: tqueue.c:88

◆ CreateTupleQueueReader()

TupleQueueReader* CreateTupleQueueReader ( shm_mq_handle handle)

Definition at line 135 of file tqueue.c.

References palloc0(), and TupleQueueReader::queue.

Referenced by ExecParallelCreateReaders().

136 {
137  TupleQueueReader *reader = palloc0(sizeof(TupleQueueReader));
138 
139  reader->queue = handle;
140 
141  return reader;
142 }
shm_mq_handle * queue
Definition: tqueue.c:45
void * palloc0(Size size)
Definition: mcxt.c:864

◆ DestroyTupleQueueReader()

void DestroyTupleQueueReader ( TupleQueueReader reader)

Definition at line 151 of file tqueue.c.

References pfree().

Referenced by ExecParallelFinish().

152 {
153  pfree(reader);
154 }
void pfree(void *pointer)
Definition: mcxt.c:936

◆ TupleQueueReaderNext()

HeapTuple TupleQueueReaderNext ( TupleQueueReader reader,
bool  nowait,
bool done 
)

Definition at line 172 of file tqueue.c.

References Assert, heap_copytuple(), InvalidOid, ItemPointerSetInvalid, TupleQueueReader::queue, SHM_MQ_DETACHED, shm_mq_receive(), SHM_MQ_SUCCESS, SHM_MQ_WOULD_BLOCK, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, and HeapTupleData::t_tableOid.

Referenced by gather_readnext(), and gm_readnext_tuple().

173 {
174  HeapTupleData htup;
175  shm_mq_result result;
176  Size nbytes;
177  void *data;
178 
179  if (done != NULL)
180  *done = false;
181 
182  /* Attempt to read a message. */
183  result = shm_mq_receive(reader->queue, &nbytes, &data, nowait);
184 
185  /* If queue is detached, set *done and return NULL. */
186  if (result == SHM_MQ_DETACHED)
187  {
188  if (done != NULL)
189  *done = true;
190  return NULL;
191  }
192 
193  /* In non-blocking mode, bail out if no message ready yet. */
194  if (result == SHM_MQ_WOULD_BLOCK)
195  return NULL;
196  Assert(result == SHM_MQ_SUCCESS);
197 
198  /*
199  * Set up a dummy HeapTupleData pointing to the data from the shm_mq
200  * (which had better be sufficiently aligned).
201  */
203  htup.t_tableOid = InvalidOid;
204  htup.t_len = nbytes;
205  htup.t_data = data;
206 
207  return heap_copytuple(&htup);
208 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:611
shm_mq_handle * queue
Definition: tqueue.c:45
HeapTupleHeader t_data
Definition: htup.h:67
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
Oid t_tableOid
Definition: htup.h:66
#define InvalidOid
Definition: postgres_ext.h:36
shm_mq_result
Definition: shm_mq.h:36
#define Assert(condition)
Definition: c.h:680
size_t Size
Definition: c.h:414
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:150
shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
Definition: shm_mq.c:522