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