Minor improvements for waitlsn.c
authorAlexander Korotkov <akorotkov@postgresql.org>
Wed, 3 Apr 2024 08:23:21 +0000 (11:23 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Wed, 3 Apr 2024 08:32:39 +0000 (11:32 +0300)
 * Remove extra includes
 * Fill 'cur' in addLSNWaiter() before taking the spinlock
 * Initialize 'endtime' with zero in WaitForLSN() to avoid compiler warning

Reported-by: Alvaro Herrera, Masahiko Sawada, Daniel Gustafsson
Discussion: https://postgr.es/m/202404030658.hhj3vfxeyhft%40alvherre.pgsql
Discussion: https://postgr.es/m/CAD21AoAx7irptnPH1OkkkNh9E0M6X-phfX7sYZfwoMsc1qV1sQ%40mail.gmail.com

src/backend/commands/waitlsn.c

index 6679378156cb57e32550b04de1651399e4b5ff56..63e9ebf1730c2ee5ce726d6d197bc9e7a631a24e 100644 (file)
 #include <math.h>
 
 #include "pgstat.h"
-#include "fmgr.h"
-#include "access/transam.h"
-#include "access/xact.h"
 #include "access/xlog.h"
-#include "access/xlogdefs.h"
 #include "access/xlogrecovery.h"
-#include "catalog/pg_type.h"
 #include "commands/waitlsn.h"
-#include "executor/spi.h"
 #include "funcapi.h"
 #include "miscadmin.h"
-#include "storage/ipc.h"
 #include "storage/latch.h"
-#include "storage/pmsignal.h"
 #include "storage/proc.h"
 #include "storage/shmem.h"
-#include "storage/sinvaladt.h"
-#include "utils/builtins.h"
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
-#include "utils/timestamp.h"
 #include "utils/fmgrprotos.h"
+#include "utils/wait_event_types.h"
 
 /* Add to / delete from shared memory array */
 static void addLSNWaiter(XLogRecPtr lsn);
@@ -88,11 +78,11 @@ addLSNWaiter(XLogRecPtr lsn)
        WaitLSNProcInfo cur;
        int                     i;
 
-       SpinLockAcquire(&waitLSN->mutex);
-
        cur.procnum = MyProcNumber;
        cur.waitLSN = lsn;
 
+       SpinLockAcquire(&waitLSN->mutex);
+
        for (i = 0; i < waitLSN->numWaitedProcs; i++)
        {
                if (waitLSN->procInfos[i].waitLSN >= cur.waitLSN)
@@ -226,7 +216,7 @@ void
 WaitForLSN(XLogRecPtr targetLSN, int64 timeout)
 {
        XLogRecPtr      currentLSN;
-       TimestampTz endtime;
+       TimestampTz endtime = 0;
 
        /* Shouldn't be called when shmem isn't initialized */
        Assert(waitLSN);