Use the GetPGProcByNumber() macro when possible
authorDavid Rowley <drowley@postgresql.org>
Mon, 5 Jan 2026 08:19:03 +0000 (21:19 +1300)
committerDavid Rowley <drowley@postgresql.org>
Mon, 5 Jan 2026 08:19:03 +0000 (21:19 +1300)
A few places were accessing &ProcGlobal->allProcs directly, so adjust
them to use the accessor macro instead.

Author: Maksim Melnikov <m.melnikov@postgrespro.ru>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/80621c00-aba6-483c-88b1-a845461d1165@postgrespro.ru

src/backend/access/transam/clog.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/walsummarizer.c
src/backend/storage/buffer/freelist.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/proc.c

index a4b0a1d7530b0bbfea4b32b47315d419711852cb..b5c38bbb162572cff6131550752bf10c2d2234f7 100644 (file)
@@ -575,7 +575,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
    /* Walk the list and update the status of all XIDs. */
    while (nextidx != INVALID_PROC_NUMBER)
    {
-       PGPROC     *nextproc = &ProcGlobal->allProcs[nextidx];
+       PGPROC     *nextproc = GetPGProcByNumber(nextidx);
        int64       thispageno = nextproc->clogGroupMemberPage;
 
        /*
@@ -634,7 +634,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
     */
    while (wakeidx != INVALID_PROC_NUMBER)
    {
-       PGPROC     *wakeproc = &ProcGlobal->allProcs[wakeidx];
+       PGPROC     *wakeproc = GetPGProcByNumber(wakeidx);
 
        wakeidx = pg_atomic_read_u32(&wakeproc->clogGroupNext);
        pg_atomic_write_u32(&wakeproc->clogGroupNext, INVALID_PROC_NUMBER);
index 8c68f0774cf29f63601961935ad6347c41265b1d..1a20387c4bdac85f243d7d81463e9f266566848c 100644 (file)
@@ -292,7 +292,7 @@ PgArchWakeup(void)
     * be relaunched shortly and will start archiving.
     */
    if (arch_pgprocno != INVALID_PROC_NUMBER)
-       SetLatch(&ProcGlobal->allProcs[arch_pgprocno].procLatch);
+       SetLatch(&GetPGProcByNumber(arch_pgprocno)->procLatch);
 }
 
 
index 00a3a2570824f8964681d709602d7fc87387a92a..c3d56c866d3442398bf63bc209986e946f6843e9 100644 (file)
@@ -649,7 +649,7 @@ WakeupWalSummarizer(void)
    LWLockRelease(WALSummarizerLock);
 
    if (pgprocno != INVALID_PROC_NUMBER)
-       SetLatch(&ProcGlobal->allProcs[pgprocno].procLatch);
+       SetLatch(&GetPGProcByNumber(pgprocno)->procLatch);
 }
 
 /*
index 8e2210d8cd3e51fa871abe36eaeaf4f1fab9b384..9a93fb335fcb8c7a5f5e5b1edb592288b703e3c9 100644 (file)
@@ -216,7 +216,7 @@ StrategyGetBuffer(BufferAccessStrategy strategy, uint32 *buf_state, bool *from_r
         * actually fine because procLatch isn't ever freed, so we just can
         * potentially set the wrong process' (or no process') latch.
         */
-       SetLatch(&ProcGlobal->allProcs[bgwprocno].procLatch);
+       SetLatch(&GetPGProcByNumber(bgwprocno)->procLatch);
    }
 
    /*
index 3df15e20954cbfbf851cf56a65fdbbda8b6c9538..7f0cd784f797bbdebd67da06e654a69afe50407e 100644 (file)
@@ -2876,7 +2876,7 @@ FastPathTransferRelationLocks(LockMethod lockMethodTable, const LOCKTAG *locktag
     */
    for (i = 0; i < ProcGlobal->allProcCount; i++)
    {
-       PGPROC     *proc = &ProcGlobal->allProcs[i];
+       PGPROC     *proc = GetPGProcByNumber(i);
        uint32      j;
 
        LWLockAcquire(&proc->fpInfoLock, LW_EXCLUSIVE);
@@ -3133,7 +3133,7 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
         */
        for (i = 0; i < ProcGlobal->allProcCount; i++)
        {
-           PGPROC     *proc = &ProcGlobal->allProcs[i];
+           PGPROC     *proc = GetPGProcByNumber(i);
            uint32      j;
 
            /* A backend never blocks itself */
@@ -3820,7 +3820,7 @@ GetLockStatusData(void)
     */
    for (i = 0; i < ProcGlobal->allProcCount; ++i)
    {
-       PGPROC     *proc = &ProcGlobal->allProcs[i];
+       PGPROC     *proc = GetPGProcByNumber(i);
 
        /* Skip backends with pid=0, as they don't hold fast-path locks */
        if (proc->pid == 0)
index 424b16bad6ec88c368445f6d307daf05a3c6232b..66274029c74bfeaf85707eb47319927bc42dec06 100644 (file)
@@ -1998,7 +1998,7 @@ ProcSendSignal(ProcNumber procNumber)
    if (procNumber < 0 || procNumber >= ProcGlobal->allProcCount)
        elog(ERROR, "procNumber out of range");
 
-   SetLatch(&ProcGlobal->allProcs[procNumber].procLatch);
+   SetLatch(&GetPGProcByNumber(procNumber)->procLatch);
 }
 
 /*