1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

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
This commit is contained in:
Tom Lane
2023-01-25 11:48:38 -05:00
parent d7c4830abb
commit 3b4ac33254
7 changed files with 18 additions and 12 deletions

View File

@@ -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);