File size: 2,126 Bytes
e0ee642 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | /*-------------------------------------------------------------------------
*
* parallel_slot.h
* Parallel support for bin/scripts/
*
* Copyright (c) 2003-2023, PostgreSQL Global Development Group
*
* src/include/fe_utils/parallel_slot.h
*
*-------------------------------------------------------------------------
*/
#ifndef PARALLEL_SLOT_H
#define PARALLEL_SLOT_H
#include "fe_utils/connect_utils.h"
#include "libpq-fe.h"
typedef bool (*ParallelSlotResultHandler) (PGresult *res, PGconn *conn,
void *context);
typedef struct ParallelSlot
{
PGconn *connection; /* One connection */
bool inUse; /* Is the slot being used? */
/*
* Prior to issuing a command or query on 'connection', a handler callback
* function may optionally be registered to be invoked to process the
* results, and context information may optionally be registered for use
* by the handler. If unset, these fields should be NULL.
*/
ParallelSlotResultHandler handler;
void *handler_context;
} ParallelSlot;
typedef struct ParallelSlotArray
{
int numslots;
ConnParams *cparams;
const char *progname;
bool echo;
const char *initcmd;
ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER];
} ParallelSlotArray;
static inline void
ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler,
void *context)
{
slot->handler = handler;
slot->handler_context = context;
}
static inline void
ParallelSlotClearHandler(ParallelSlot *slot)
{
slot->handler = NULL;
slot->handler_context = NULL;
}
extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlotArray *sa,
const char *dbname);
extern ParallelSlotArray *ParallelSlotsSetup(int numslots, ConnParams *cparams,
const char *progname, bool echo,
const char *initcmd);
extern void ParallelSlotsAdoptConn(ParallelSlotArray *sa, PGconn *conn);
extern void ParallelSlotsTerminate(ParallelSlotArray *sa);
extern bool ParallelSlotsWaitCompletion(ParallelSlotArray *sa);
extern bool TableCommandResultHandler(PGresult *res, PGconn *conn,
void *context);
#endif /* PARALLEL_SLOT_H */
|