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