From 3f47518ddc6ad730599943780acbaee6212c7954 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 5 Sep 2007 21:11:19 +0000 Subject: [PATCH] Volatile-qualify the ProcArray PGPROC pointer in a bunch of routines that examine fields that could change under them. This is just to make really sure that when we are fetching a value 'only once', that's what actually happens. Possibly this is a bug that should be back-patched, but in the absence of solid evidence that it's needed, I won't bother. --- src/backend/storage/ipc/procarray.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 52b31b16b5..821bdf4ca2 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -233,7 +233,7 @@ TransactionIdIsInProgress(TransactionId xid) for (i = 0; i < arrayP->numProcs; i++) { - PGPROC *proc = arrayP->procs[i]; + volatile PGPROC *proc = arrayP->procs[i]; /* Fetch xid just once - see GetNewTransactionId */ TransactionId pxid = proc->xid; @@ -361,7 +361,7 @@ TransactionIdIsActive(TransactionId xid) for (i = 0; i < arrayP->numProcs; i++) { - PGPROC *proc = arrayP->procs[i]; + volatile PGPROC *proc = arrayP->procs[i]; /* Fetch xid just once - see GetNewTransactionId */ TransactionId pxid = proc->xid; @@ -434,7 +434,7 @@ GetOldestXmin(bool allDbs, bool ignoreVacuum) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; if (ignoreVacuum && proc->inVacuum) continue; @@ -613,7 +613,7 @@ GetSnapshotData(Snapshot snapshot, bool serializable) */ for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; TransactionId xid; /* Ignore procs running LAZY VACUUM */ @@ -672,7 +672,7 @@ GetSnapshotData(Snapshot snapshot, bool serializable) if (nxids > 0) { memcpy(snapshot->subxip + subcount, - proc->subxids.xids, + (void *) proc->subxids.xids, nxids * sizeof(TransactionId)); subcount += nxids; } @@ -739,7 +739,7 @@ GetTransactionsInCommit(TransactionId **xids_p) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; /* Fetch xid just once - see GetNewTransactionId */ TransactionId pxid = proc->xid; @@ -773,7 +773,7 @@ HaveTransactionsInCommit(TransactionId *xids, int nxids) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; /* Fetch xid just once - see GetNewTransactionId */ TransactionId pxid = proc->xid; @@ -861,7 +861,7 @@ BackendXidGetPid(TransactionId xid) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; if (proc->xid == xid) { @@ -909,7 +909,7 @@ GetCurrentVirtualXIDs(TransactionId limitXmin) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; /* Fetch xmin just once - might change on us? */ TransactionId pxmin = proc->xmin; @@ -963,7 +963,7 @@ CountActiveBackends(void) */ for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; if (proc == MyProc) continue; /* do not count myself */ @@ -993,7 +993,7 @@ CountDBBackends(Oid databaseid) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; if (proc->pid == 0) continue; /* do not count prepared xacts */ @@ -1020,7 +1020,7 @@ CountUserBackends(Oid roleid) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; if (proc->pid == 0) continue; /* do not count prepared xacts */ @@ -1072,7 +1072,7 @@ CheckOtherDBBackends(Oid databaseId) for (index = 0; index < arrayP->numProcs; index++) { - PGPROC *proc = arrayP->procs[index]; + volatile PGPROC *proc = arrayP->procs[index]; if (proc->databaseId != databaseId) continue; -- 2.39.5