parallel_slot.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*-------------------------------------------------------------------------
  2. *
  3. * parallel_slot.h
  4. * Parallel support for bin/scripts/
  5. *
  6. * Copyright (c) 2003-2022, 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. #include "fe_utils/connect_utils.h"
  15. #include "libpq-fe.h"
  16. typedef bool (*ParallelSlotResultHandler) (PGresult *res, PGconn *conn,
  17. void *context);
  18. typedef struct ParallelSlot
  19. {
  20. PGconn *connection; /* One connection */
  21. bool inUse; /* Is the slot being used? */
  22. /*
  23. * Prior to issuing a command or query on 'connection', a handler callback
  24. * function may optionally be registered to be invoked to process the
  25. * results, and context information may optionally be registered for use
  26. * by the handler. If unset, these fields should be NULL.
  27. */
  28. ParallelSlotResultHandler handler;
  29. void *handler_context;
  30. } ParallelSlot;
  31. typedef struct ParallelSlotArray
  32. {
  33. int numslots;
  34. ConnParams *cparams;
  35. const char *progname;
  36. bool echo;
  37. const char *initcmd;
  38. ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER];
  39. } ParallelSlotArray;
  40. static inline void
  41. ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler,
  42. void *context)
  43. {
  44. slot->handler = handler;
  45. slot->handler_context = context;
  46. }
  47. static inline void
  48. ParallelSlotClearHandler(ParallelSlot *slot)
  49. {
  50. slot->handler = NULL;
  51. slot->handler_context = NULL;
  52. }
  53. extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlotArray *slots,
  54. const char *dbname);
  55. extern ParallelSlotArray *ParallelSlotsSetup(int numslots, ConnParams *cparams,
  56. const char *progname, bool echo,
  57. const char *initcmd);
  58. extern void ParallelSlotsAdoptConn(ParallelSlotArray *sa, PGconn *conn);
  59. extern void ParallelSlotsTerminate(ParallelSlotArray *sa);
  60. extern bool ParallelSlotsWaitCompletion(ParallelSlotArray *sa);
  61. extern bool TableCommandResultHandler(PGresult *res, PGconn *conn,
  62. void *context);
  63. #endif /* PARALLEL_SLOT_H */