diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-02-22 01:21:34 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-02-22 01:21:34 +0200 |
commit | 28f3915b73f75bd1b50ba070f56b34241fe53fd1 (patch) | |
tree | 10d305f3f98af6cfae7d683ce9b13c449d8e8796 /src/backend/storage/lmgr/proc.c | |
parent | 4989ce72644b9d636b9b23c7a1719a405e62670b (diff) | |
download | postgresql-28f3915b73f75bd1b50ba070f56b34241fe53fd1.tar.gz postgresql-28f3915b73f75bd1b50ba070f56b34241fe53fd1.zip |
Remove superfluous 'pgprocno' field from PGPROC
It was always just the index of the PGPROC entry from the beginning of
the proc array. Introduce a macro to compute it from the pointer
instead.
Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
Diffstat (limited to 'src/backend/storage/lmgr/proc.c')
-rw-r--r-- | src/backend/storage/lmgr/proc.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 1afcbfc052c..4aec4a3c5f4 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -65,6 +65,7 @@ bool log_lock_waits = false; /* Pointer to this process's PGPROC struct, if any */ PGPROC *MyProc = NULL; +int MyProcNumber = INVALID_PGPROCNO; /* * This spinlock protects the freelist of recycled PGPROC structures. @@ -228,7 +229,6 @@ InitProcGlobal(void) InitSharedLatch(&(proc->procLatch)); LWLockInitialize(&(proc->fpInfoLock), LWTRANCHE_LOCK_FASTPATH); } - proc->pgprocno = i; /* * Newly created PGPROCs for normal backends, autovacuum and bgworkers @@ -353,6 +353,7 @@ InitProcess(void) (errcode(ERRCODE_TOO_MANY_CONNECTIONS), errmsg("sorry, too many clients already"))); } + MyProcNumber = GetNumberFromPGProc(MyProc); /* * Cross-check that the PGPROC is of the type we expect; if this were not @@ -566,6 +567,8 @@ InitAuxiliaryProcess(void) SpinLockRelease(ProcStructLock); + MyProcNumber = GetNumberFromPGProc(MyProc); + /* * Initialize all fields of MyProc, except for those previously * initialized by InitProcGlobal. @@ -907,6 +910,7 @@ ProcKill(int code, Datum arg) proc = MyProc; MyProc = NULL; + MyProcNumber = INVALID_PGPROCNO; DisownLatch(&proc->procLatch); procgloballist = proc->procgloballist; @@ -978,6 +982,7 @@ AuxiliaryProcKill(int code, Datum arg) proc = MyProc; MyProc = NULL; + MyProcNumber = INVALID_PGPROCNO; DisownLatch(&proc->procLatch); SpinLockAcquire(ProcStructLock); @@ -1903,10 +1908,9 @@ BecomeLockGroupMember(PGPROC *leader, int pid) /* * Get lock protecting the group fields. Note LockHashPartitionLockByProc - * accesses leader->pgprocno in a PGPROC that might be free. This is safe - * because all PGPROCs' pgprocno fields are set during shared memory - * initialization and never change thereafter; so we will acquire the - * correct lock even if the leader PGPROC is in process of being recycled. + * calculates the proc number based on the PGPROC slot without looking at + * its contents, so we will acquire the correct lock even if the leader + * PGPROC is in process of being recycled. */ leader_lwlock = LockHashPartitionLockByProc(leader); LWLockAcquire(leader_lwlock, LW_EXCLUSIVE); |