summaryrefslogtreecommitdiffstats
path: root/src/include/fe_utils/parallel_slot.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/include/fe_utils/parallel_slot.h
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/include/fe_utils/parallel_slot.h')
-rw-r--r--src/include/fe_utils/parallel_slot.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/include/fe_utils/parallel_slot.h b/src/include/fe_utils/parallel_slot.h
new file mode 100644
index 0000000..8ce63c9
--- /dev/null
+++ b/src/include/fe_utils/parallel_slot.h
@@ -0,0 +1,77 @@
+/*-------------------------------------------------------------------------
+ *
+ * parallel_slot.h
+ * Parallel support for bin/scripts/
+ *
+ * Copyright (c) 2003-2022, 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 *slots,
+ 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 */