mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-15 10:57:02 +08:00
The usual pattern for handling a signal is that the signal handler sets a flag and calls SetLatch(MyLatch), and CHECK_FOR_INTERRUPTS() or other code that is part of a wait loop calls another function to deal with it. The naming of the functions involved was a bit inconsistent, however. CHECK_FOR_INTERRUPTS() calls ProcessInterrupts() to do the heavy-lifting, but the analogous functions in aux processes were called HandleMainLoopInterrupts(), HandleStartupProcInterrupts(), etc. Similarly, most subroutines of ProcessInterrupts() were called Process*(), but some were called Handle*(). To make things less confusing, rename all the functions that are part of the overall signal/interrupt handling system but are not executed in a signal handler to e.g. ProcessSomething(), rather than HandleSomething(). The "Process" prefix is now consistently used in the non-signal-handler functions, and the "Handle" prefix in functions that are part of signal handlers, except for some completely unrelated functions that clearly have nothing to do with signal or interrupt handling. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://www.postgresql.org/message-id/8a384b26-1499-41f6-be33-64b801fb98b8@iki.fi
82 lines
2.6 KiB
C
82 lines
2.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* parallel.h
|
|
* Infrastructure for launching parallel workers
|
|
*
|
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/access/parallel.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef PARALLEL_H
|
|
#define PARALLEL_H
|
|
|
|
#include "access/xlogdefs.h"
|
|
#include "lib/ilist.h"
|
|
#include "postmaster/bgworker.h"
|
|
#include "storage/shm_mq.h"
|
|
#include "storage/shm_toc.h"
|
|
|
|
typedef void (*parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc);
|
|
|
|
typedef struct ParallelWorkerInfo
|
|
{
|
|
BackgroundWorkerHandle *bgwhandle;
|
|
shm_mq_handle *error_mqh;
|
|
} ParallelWorkerInfo;
|
|
|
|
typedef struct ParallelContext
|
|
{
|
|
dlist_node node;
|
|
SubTransactionId subid;
|
|
int nworkers; /* Maximum number of workers to launch */
|
|
int nworkers_to_launch; /* Actual number of workers to launch */
|
|
int nworkers_launched;
|
|
char *library_name;
|
|
char *function_name;
|
|
ErrorContextCallback *error_context_stack;
|
|
shm_toc_estimator estimator;
|
|
dsm_segment *seg;
|
|
void *private_memory;
|
|
shm_toc *toc;
|
|
ParallelWorkerInfo *worker;
|
|
int nknown_attached_workers;
|
|
bool *known_attached_workers;
|
|
} ParallelContext;
|
|
|
|
typedef struct ParallelWorkerContext
|
|
{
|
|
dsm_segment *seg;
|
|
shm_toc *toc;
|
|
} ParallelWorkerContext;
|
|
|
|
extern PGDLLIMPORT volatile sig_atomic_t ParallelMessagePending;
|
|
extern PGDLLIMPORT int ParallelWorkerNumber;
|
|
extern PGDLLIMPORT bool InitializingParallelWorker;
|
|
|
|
#define IsParallelWorker() (ParallelWorkerNumber >= 0)
|
|
|
|
extern ParallelContext *CreateParallelContext(const char *library_name,
|
|
const char *function_name, int nworkers);
|
|
extern void InitializeParallelDSM(ParallelContext *pcxt);
|
|
extern void ReinitializeParallelDSM(ParallelContext *pcxt);
|
|
extern void ReinitializeParallelWorkers(ParallelContext *pcxt, int nworkers_to_launch);
|
|
extern void LaunchParallelWorkers(ParallelContext *pcxt);
|
|
extern void WaitForParallelWorkersToAttach(ParallelContext *pcxt);
|
|
extern void WaitForParallelWorkersToFinish(ParallelContext *pcxt);
|
|
extern void DestroyParallelContext(ParallelContext *pcxt);
|
|
extern bool ParallelContextActive(void);
|
|
|
|
extern void HandleParallelMessageInterrupt(void);
|
|
extern void ProcessParallelMessages(void);
|
|
extern void AtEOXact_Parallel(bool isCommit);
|
|
extern void AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId);
|
|
extern void ParallelWorkerReportLastRecEnd(XLogRecPtr last_xlog_end);
|
|
|
|
extern void ParallelWorkerMain(Datum main_arg);
|
|
|
|
#endif /* PARALLEL_H */
|