1/*-------------------------------------------------------------------------
2 *
3 * parallel.h
4 * Infrastructure for launching parallel workers
5 *
6 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/access/parallel.h
10 *
11 *-------------------------------------------------------------------------
12 */
13
14#ifndef PARALLEL_H
15#define PARALLEL_H
16
17#include "access/xlogdefs.h"
18#include "lib/ilist.h"
19#include "postmaster/bgworker.h"
20#include "storage/shm_mq.h"
21#include "storage/shm_toc.h"
22
23typedef void (*parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc);
24
25typedef struct ParallelWorkerInfo
26{
27 BackgroundWorkerHandle *bgwhandle;
28 shm_mq_handle *error_mqh;
29 int32 pid;
30} ParallelWorkerInfo;
31
32typedef struct ParallelContext
33{
34 dlist_node node;
35 SubTransactionId subid;
36 int nworkers;
37 int nworkers_launched;
38 char *library_name;
39 char *function_name;
40 ErrorContextCallback *error_context_stack;
41 shm_toc_estimator estimator;
42 dsm_segment *seg;
43 void *private_memory;
44 shm_toc *toc;
45 ParallelWorkerInfo *worker;
46 int nknown_attached_workers;
47 bool *known_attached_workers;
48} ParallelContext;
49
50typedef struct ParallelWorkerContext
51{
52 dsm_segment *seg;
53 shm_toc *toc;
54} ParallelWorkerContext;
55
56extern volatile bool ParallelMessagePending;
57extern PGDLLIMPORT int ParallelWorkerNumber;
58extern PGDLLIMPORT bool InitializingParallelWorker;
59
60#define IsParallelWorker() (ParallelWorkerNumber >= 0)
61
62extern ParallelContext *CreateParallelContext(const char *library_name,
63 const char *function_name, int nworkers);
64extern void InitializeParallelDSM(ParallelContext *pcxt);
65extern void ReinitializeParallelDSM(ParallelContext *pcxt);
66extern void LaunchParallelWorkers(ParallelContext *pcxt);
67extern void WaitForParallelWorkersToAttach(ParallelContext *pcxt);
68extern void WaitForParallelWorkersToFinish(ParallelContext *pcxt);
69extern void DestroyParallelContext(ParallelContext *pcxt);
70extern bool ParallelContextActive(void);
71
72extern void HandleParallelMessageInterrupt(void);
73extern void HandleParallelMessages(void);
74extern void AtEOXact_Parallel(bool isCommit);
75extern void AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId);
76extern void ParallelWorkerReportLastRecEnd(XLogRecPtr last_xlog_end);
77
78extern void ParallelWorkerMain(Datum main_arg);
79
80#endif /* PARALLEL_H */
81