aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-01-25 11:48:38 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-01-25 11:48:38 -0500
commit3b4ac33254e1291f0b3c94f1cb770137c418ce2e (patch)
tree9219e24682a484c34c4d2af241db9300be5727cd /src/backend
parentd7c4830abb1867ca4fb83add2a5fac558f778b6a (diff)
downloadpostgresql-3b4ac33254e1291f0b3c94f1cb770137c418ce2e.tar.gz
postgresql-3b4ac33254e1291f0b3c94f1cb770137c418ce2e.zip
Avoid type cheats for invalid dsa_handles and dshash_table_handles.
Invent separate macros for "invalid" values of these types, so that we needn't embed knowledge of their representations into calling code. These are all zeroes anyway ATM, so this is not fixing any live bug, but it makes the code cleaner and more future-proof. I (tgl) also chose to move DSM_HANDLE_INVALID into dsm_impl.h, since it seems like it should live beside the typedef for dsm_handle. Hou Zhijie, Nathan Bossart, Kyotaro Horiguchi, Tom Lane Discussion: https://postgr.es/m/OS0PR01MB5716860B1454C34E5B179B6694C99@OS0PR01MB5716.jpnprd01.prod.outlook.com
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/replication/logical/launcher.c8
-rw-r--r--src/backend/storage/ipc/dsm.c5
-rw-r--r--src/backend/utils/mmgr/dsa.c4
3 files changed, 8 insertions, 9 deletions
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 564bffe5caf..970d170e73a 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -922,8 +922,8 @@ ApplyLauncherShmemInit(void)
memset(LogicalRepCtx, 0, ApplyLauncherShmemSize());
- LogicalRepCtx->last_start_dsa = DSM_HANDLE_INVALID;
- LogicalRepCtx->last_start_dsh = DSM_HANDLE_INVALID;
+ LogicalRepCtx->last_start_dsa = DSA_HANDLE_INVALID;
+ LogicalRepCtx->last_start_dsh = DSHASH_HANDLE_INVALID;
/* Initialize memory and spin locks for each worker slot. */
for (slot = 0; slot < max_logical_replication_workers; slot++)
@@ -947,7 +947,7 @@ logicalrep_launcher_attach_dshmem(void)
MemoryContext oldcontext;
/* Quick exit if we already did this. */
- if (LogicalRepCtx->last_start_dsh != DSM_HANDLE_INVALID &&
+ if (LogicalRepCtx->last_start_dsh != DSHASH_HANDLE_INVALID &&
last_start_times != NULL)
return;
@@ -957,7 +957,7 @@ logicalrep_launcher_attach_dshmem(void)
/* Be sure any local memory allocated by DSA routines is persistent. */
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
- if (LogicalRepCtx->last_start_dsh == DSM_HANDLE_INVALID)
+ if (LogicalRepCtx->last_start_dsh == DSHASH_HANDLE_INVALID)
{
/* Initialize dynamic shared hash table for last-start times. */
last_start_times_dsa = dsa_create(LWTRANCHE_LAUNCHER_DSA);
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index ba3ceb8153e..10b029bb162 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -173,9 +173,8 @@ dsm_postmaster_startup(PGShmemHeader *shim)
/*
* Loop until we find an unused identifier for the new control segment. We
- * sometimes use 0 as a sentinel value indicating that no control segment
- * is known to exist, so avoid using that value for a real control
- * segment.
+ * sometimes use DSM_HANDLE_INVALID as a sentinel value indicating "no
+ * control segment", so avoid generating that value for a real handle.
*/
for (;;)
{
diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c
index 604b702a91f..f5a62061a3e 100644
--- a/src/backend/utils/mmgr/dsa.c
+++ b/src/backend/utils/mmgr/dsa.c
@@ -505,7 +505,7 @@ dsa_create_in_place(void *place, size_t size,
dsa_handle
dsa_get_handle(dsa_area *area)
{
- Assert(area->control->handle != DSM_HANDLE_INVALID);
+ Assert(area->control->handle != DSA_HANDLE_INVALID);
return area->control->handle;
}
@@ -554,7 +554,7 @@ dsa_attach_in_place(void *place, dsm_segment *segment)
{
dsa_area *area;
- area = attach_internal(place, NULL, DSM_HANDLE_INVALID);
+ area = attach_internal(place, NULL, DSA_HANDLE_INVALID);
/*
* Clean up when the control segment detaches, if a containing DSM segment