parallel.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*-------------------------------------------------------------------------
  2. *
  3. * parallel.h
  4. * Infrastructure for launching parallel workers
  5. *
  6. * Portions Copyright (c) 1996-2016, 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. #ifndef PARALLEL_H
  14. #define PARALLEL_H
  15. #include "access/xlogdefs.h"
  16. #include "lib/ilist.h"
  17. #include "postmaster/bgworker.h"
  18. #include "storage/shm_mq.h"
  19. #include "storage/shm_toc.h"
  20. typedef void (*parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc);
  21. typedef struct ParallelWorkerInfo
  22. {
  23. BackgroundWorkerHandle *bgwhandle;
  24. shm_mq_handle *error_mqh;
  25. int32 pid;
  26. } ParallelWorkerInfo;
  27. typedef struct ParallelContext
  28. {
  29. dlist_node node;
  30. SubTransactionId subid;
  31. int nworkers;
  32. int nworkers_launched;
  33. parallel_worker_main_type entrypoint;
  34. char *library_name;
  35. char *function_name;
  36. ErrorContextCallback *error_context_stack;
  37. shm_toc_estimator estimator;
  38. dsm_segment *seg;
  39. void *private_memory;
  40. shm_toc *toc;
  41. ParallelWorkerInfo *worker;
  42. } ParallelContext;
  43. extern volatile bool ParallelMessagePending;
  44. extern int ParallelWorkerNumber;
  45. extern bool InitializingParallelWorker;
  46. #define IsParallelWorker() (ParallelWorkerNumber >= 0)
  47. extern ParallelContext *CreateParallelContext(parallel_worker_main_type entrypoint, int nworkers);
  48. extern ParallelContext *CreateParallelContextForExternalFunction(char *library_name, char *function_name, int nworkers);
  49. extern void InitializeParallelDSM(ParallelContext *pcxt);
  50. extern void ReinitializeParallelDSM(ParallelContext *pcxt);
  51. extern void LaunchParallelWorkers(ParallelContext *pcxt);
  52. extern void WaitForParallelWorkersToFinish(ParallelContext *pcxt);
  53. extern void DestroyParallelContext(ParallelContext *pcxt);
  54. extern bool ParallelContextActive(void);
  55. extern void HandleParallelMessageInterrupt(void);
  56. extern void HandleParallelMessages(void);
  57. extern void AtEOXact_Parallel(bool isCommit);
  58. extern void AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId);
  59. extern void ParallelWorkerReportLastRecEnd(XLogRecPtr last_xlog_end);
  60. extern void ParallelWorkerMain(Datum main_arg);
  61. #endif /* PARALLEL_H */