PostgreSQL Source Code  git master
parallel_slot.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * parallel_slot.h
4  * Parallel support for bin/scripts/
5  *
6  * Copyright (c) 2003-2021, PostgreSQL Global Development Group
7  *
8  * src/include/fe_utils/parallel_slot.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef PARALLEL_SLOT_H
13 #define PARALLEL_SLOT_H
14 
15 #include "fe_utils/connect_utils.h"
16 #include "libpq-fe.h"
17 
19  void *context);
20 
21 typedef struct ParallelSlot
22 {
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 callback
28  * function may optionally be registered to be invoked to process the
29  * results, and context information may optionally be registered for use
30  * by the handler. If unset, these fields should be NULL.
31  */
35 
36 typedef struct ParallelSlotArray
37 {
38  int numslots;
40  const char *progname;
41  bool echo;
42  const char *initcmd;
45 
46 static inline void
48  void *context)
49 {
50  slot->handler = handler;
51  slot->handler_context = context;
52 }
53 
54 static inline void
56 {
57  slot->handler = NULL;
58  slot->handler_context = NULL;
59 }
60 
62  const char *dbname);
63 
64 extern ParallelSlotArray *ParallelSlotsSetup(int numslots, ConnParams *cparams,
65  const char *progname, bool echo,
66  const char *initcmd);
67 
69 
71 
73 
75  void *context);
76 
77 #endif /* PARALLEL_SLOT_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
unsigned char bool
Definition: c.h:391
const char * progname
Definition: main.c:46
bool ParallelSlotsWaitCompletion(ParallelSlotArray *sa)
bool(* ParallelSlotResultHandler)(PGresult *res, PGconn *conn, void *context)
Definition: parallel_slot.h:18
ParallelSlotArray * ParallelSlotsSetup(int numslots, ConnParams *cparams, const char *progname, bool echo, const char *initcmd)
bool TableCommandResultHandler(PGresult *res, PGconn *conn, void *context)
struct ParallelSlotArray ParallelSlotArray
static void ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler, void *context)
Definition: parallel_slot.h:47
static void ParallelSlotClearHandler(ParallelSlot *slot)
Definition: parallel_slot.h:55
void ParallelSlotsTerminate(ParallelSlotArray *sa)
void ParallelSlotsAdoptConn(ParallelSlotArray *sa, PGconn *conn)
struct ParallelSlot ParallelSlot
ParallelSlot * ParallelSlotsGetIdle(ParallelSlotArray *slots, const char *dbname)
char * dbname
Definition: streamutil.c:51
PGconn * conn
Definition: streamutil.c:54
ConnParams * cparams
Definition: parallel_slot.h:39
const char * initcmd
Definition: parallel_slot.h:42
ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER]
Definition: parallel_slot.h:43
const char * progname
Definition: parallel_slot.h:40
ParallelSlotResultHandler handler
Definition: parallel_slot.h:32
PGconn * connection
Definition: parallel_slot.h:23
void * handler_context
Definition: parallel_slot.h:33