mirror of
https://github.com/postgres/postgres.git
synced 2026-04-15 22:10:45 -04:00
Introduce a registry of built-in shmem subsystems
To add a new built-in subsystem, add it to subsystemslist.h. That hooks up its shmem callbacks so that they get called at the right times during postmaster startup. For now this is unused, but will replace the current SubsystemShmemSize() and SubsystemShmemInit() calls in the next commits. Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://www.postgresql.org/message-id/CAExHW5vM1bneLYfg0wGeAa=52UiJ3z4vKd3AJ72X8Fw6k3KKrg@mail.gmail.com
This commit is contained in:
parent
d4885af3d6
commit
1fc2e9fbc0
10 changed files with 92 additions and 2 deletions
|
|
@ -363,6 +363,8 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
|
|||
SetProcessingMode(BootstrapProcessing);
|
||||
IgnoreSystemIndexes = true;
|
||||
|
||||
RegisterBuiltinShmemCallbacks();
|
||||
|
||||
InitializeMaxBackends();
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -664,6 +664,8 @@ SubPostmasterMain(int argc, char *argv[])
|
|||
*/
|
||||
LocalProcessControlFile(false);
|
||||
|
||||
RegisterBuiltinShmemCallbacks();
|
||||
|
||||
/*
|
||||
* Reload any libraries that were preloaded by the postmaster. Since we
|
||||
* exec'd this process, those libraries didn't come along with us; but we
|
||||
|
|
|
|||
|
|
@ -922,6 +922,11 @@ PostmasterMain(int argc, char *argv[])
|
|||
*/
|
||||
ApplyLauncherRegister();
|
||||
|
||||
/*
|
||||
* Register the shared memory needs of all core subsystems.
|
||||
*/
|
||||
RegisterBuiltinShmemCallbacks();
|
||||
|
||||
/*
|
||||
* process any libraries that should be preloaded at postmaster start
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#include "storage/procsignal.h"
|
||||
#include "storage/shmem_internal.h"
|
||||
#include "storage/sinvaladt.h"
|
||||
#include "storage/subsystems.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/injection_point.h"
|
||||
#include "utils/wait_event.h"
|
||||
|
|
@ -252,6 +253,26 @@ CreateSharedMemoryAndSemaphores(void)
|
|||
shmem_startup_hook();
|
||||
}
|
||||
|
||||
/*
|
||||
* Early initialization of various subsystems, giving them a chance to
|
||||
* register their shared memory needs before the shared memory segment is
|
||||
* allocated.
|
||||
*/
|
||||
void
|
||||
RegisterBuiltinShmemCallbacks(void)
|
||||
{
|
||||
/*
|
||||
* Call RegisterShmemCallbacks(...) on each subsystem listed in
|
||||
* subsystemslist.h
|
||||
*/
|
||||
#define PG_SHMEM_SUBSYSTEM(subsystem_callbacks) \
|
||||
RegisterShmemCallbacks(&(subsystem_callbacks));
|
||||
|
||||
#include "storage/subsystemlist.h"
|
||||
|
||||
#undef PG_SHMEM_SUBSYSTEM
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize various subsystems, setting up their data structures in
|
||||
* shared memory.
|
||||
|
|
|
|||
|
|
@ -77,8 +77,10 @@
|
|||
* );
|
||||
* }
|
||||
*
|
||||
* Register the callbacks by calling RegisterShmemCallbacks(&MyShmemCallbacks)
|
||||
* in the extension's _PG_init() function.
|
||||
* In builtin PostgreSQL code, add the callbacks to the list in
|
||||
* src/include/storage/subsystemlist.h. In an add-in module, you can register
|
||||
* the callbacks by calling RegisterShmemCallbacks(&MyShmemCallbacks) in the
|
||||
* extension's _PG_init() function.
|
||||
*
|
||||
* Lifecycle
|
||||
* ---------
|
||||
|
|
|
|||
|
|
@ -4138,6 +4138,9 @@ PostgresSingleUserMain(int argc, char *argv[],
|
|||
/* read control file (error checking and contains config ) */
|
||||
LocalProcessControlFile(false);
|
||||
|
||||
/* Register the shared memory needs of all core subsystems. */
|
||||
RegisterBuiltinShmemCallbacks();
|
||||
|
||||
/*
|
||||
* process any libraries that should be preloaded at postmaster start
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ extern void check_on_shmem_exit_lists_are_empty(void);
|
|||
/* ipci.c */
|
||||
extern PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook;
|
||||
|
||||
extern void RegisterBuiltinShmemCallbacks(void);
|
||||
extern Size CalculateShmemSize(void);
|
||||
extern void CreateSharedMemoryAndSemaphores(void);
|
||||
#ifdef EXEC_BACKEND
|
||||
|
|
|
|||
23
src/include/storage/subsystemlist.h
Normal file
23
src/include/storage/subsystemlist.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* subsystemlist.h
|
||||
*
|
||||
* List of initialization callbacks of built-in subsystems. This is kept in
|
||||
* its own source file for possible use by automatic tools.
|
||||
* PG_SHMEM_SUBSYSTEM is defined in the callers depending on how the list is
|
||||
* used.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/storage/subsystemlist.h
|
||||
*---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* there is deliberately not an #ifndef SUBSYSTEMLIST_H here */
|
||||
|
||||
/*
|
||||
* Note: there are some inter-dependencies between these, so the order of some
|
||||
* of these matter.
|
||||
*/
|
||||
|
||||
/* TODO: empty for now */
|
||||
30
src/include/storage/subsystems.h
Normal file
30
src/include/storage/subsystems.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* subsystems.h
|
||||
* Provide extern declarations for all the built-in subsystem callbacks
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/storage/subsystems.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef SUBSYSTEMS_H
|
||||
#define SUBSYSTEMS_H
|
||||
|
||||
#include "storage/shmem.h"
|
||||
|
||||
/*
|
||||
* Extern declarations of all the built-in subsystem callbacks
|
||||
*
|
||||
* The actual list is in subsystemlist.h, so that the same list can be used
|
||||
* for other purposes.
|
||||
*/
|
||||
#define PG_SHMEM_SUBSYSTEM(callbacks) \
|
||||
extern const ShmemCallbacks callbacks;
|
||||
#include "storage/subsystemlist.h"
|
||||
#undef PG_SHMEM_SUBSYSTEM
|
||||
|
||||
#endif /* SUBSYSTEMS_H */
|
||||
|
|
@ -131,6 +131,7 @@ do
|
|||
test "$f" = src/include/postmaster/proctypelist.h && continue
|
||||
test "$f" = src/include/regex/regerrs.h && continue
|
||||
test "$f" = src/include/storage/lwlocklist.h && continue
|
||||
test "$f" = src/include/storage/subsystemlist.h && continue
|
||||
test "$f" = src/include/tcop/cmdtaglist.h && continue
|
||||
test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue
|
||||
test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue
|
||||
|
|
|
|||
Loading…
Reference in a new issue