bgworker_internals.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*--------------------------------------------------------------------
  2. * bgworker_internals.h
  3. * POSTGRES pluggable background workers internals
  4. *
  5. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  6. * Portions Copyright (c) 1994, Regents of the University of California
  7. *
  8. * IDENTIFICATION
  9. * src/include/postmaster/bgworker_internals.h
  10. *--------------------------------------------------------------------
  11. */
  12. #ifndef BGWORKER_INTERNALS_H
  13. #define BGWORKER_INTERNALS_H
  14. #include "datatype/timestamp.h"
  15. #include "lib/ilist.h"
  16. #include "postmaster/bgworker.h"
  17. /* GUC options */
  18. /*
  19. * Maximum possible value of parallel workers.
  20. */
  21. #define MAX_PARALLEL_WORKER_LIMIT 1024
  22. /*
  23. * List of background workers, private to postmaster.
  24. *
  25. * A worker that requests a database connection during registration will have
  26. * rw_backend set, and will be present in BackendList. Note: do not rely on
  27. * rw_backend being non-NULL for shmem-connected workers!
  28. */
  29. typedef struct RegisteredBgWorker
  30. {
  31. BackgroundWorker rw_worker; /* its registry entry */
  32. struct bkend *rw_backend; /* its BackendList entry, or NULL */
  33. pid_t rw_pid; /* 0 if not running */
  34. int rw_child_slot;
  35. TimestampTz rw_crashed_at; /* if not 0, time it last crashed */
  36. int rw_shmem_slot;
  37. bool rw_terminate;
  38. slist_node rw_lnode; /* list link */
  39. } RegisteredBgWorker;
  40. extern PGDLLIMPORT slist_head BackgroundWorkerList;
  41. extern Size BackgroundWorkerShmemSize(void);
  42. extern void BackgroundWorkerShmemInit(void);
  43. extern void BackgroundWorkerStateChange(bool allow_new_workers);
  44. extern void ForgetBackgroundWorker(slist_mutable_iter *cur);
  45. extern void ReportBackgroundWorkerPID(RegisteredBgWorker *);
  46. extern void ReportBackgroundWorkerExit(slist_mutable_iter *cur);
  47. extern void BackgroundWorkerStopNotifications(pid_t pid);
  48. extern void ForgetUnstartedBackgroundWorkers(void);
  49. extern void ResetBackgroundWorkerCrashTimes(void);
  50. /* Function to start a background worker, called from postmaster.c */
  51. extern void StartBackgroundWorker(void) pg_attribute_noreturn();
  52. #ifdef EXEC_BACKEND
  53. extern BackgroundWorker *BackgroundWorkerEntry(int slotno);
  54. #endif
  55. #endif /* BGWORKER_INTERNALS_H */