Remove volatile qualifiers from proc.c and procarray.c

Prior to commit 0709b7ee72, access to
variables within a spinlock-protected critical section had to be done
through a volatile pointer, but that should no longer be necessary.

Michael Paquier
This commit is contained in:
Robert Haas 2015-10-16 14:20:36 -04:00
parent 430008b5a7
commit d53e3d5fe0
2 changed files with 19 additions and 36 deletions

View File

@ -3718,8 +3718,6 @@ static int
KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin, KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin,
TransactionId xmax) TransactionId xmax)
{ {
/* use volatile pointer to prevent code rearrangement */
volatile ProcArrayStruct *pArray = procArray;
int count = 0; int count = 0;
int head, int head,
tail; tail;
@ -3734,10 +3732,10 @@ KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin,
* *
* Must take spinlock to ensure we see up-to-date array contents. * Must take spinlock to ensure we see up-to-date array contents.
*/ */
SpinLockAcquire(&pArray->known_assigned_xids_lck); SpinLockAcquire(&procArray->known_assigned_xids_lck);
tail = pArray->tailKnownAssignedXids; tail = procArray->tailKnownAssignedXids;
head = pArray->headKnownAssignedXids; head = procArray->headKnownAssignedXids;
SpinLockRelease(&pArray->known_assigned_xids_lck); SpinLockRelease(&procArray->known_assigned_xids_lck);
for (i = tail; i < head; i++) for (i = tail; i < head; i++)
{ {
@ -3777,8 +3775,6 @@ KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin,
static TransactionId static TransactionId
KnownAssignedXidsGetOldestXmin(void) KnownAssignedXidsGetOldestXmin(void)
{ {
/* use volatile pointer to prevent code rearrangement */
volatile ProcArrayStruct *pArray = procArray;
int head, int head,
tail; tail;
int i; int i;
@ -3786,10 +3782,10 @@ KnownAssignedXidsGetOldestXmin(void)
/* /*
* Fetch head just once, since it may change while we loop. * Fetch head just once, since it may change while we loop.
*/ */
SpinLockAcquire(&pArray->known_assigned_xids_lck); SpinLockAcquire(&procArray->known_assigned_xids_lck);
tail = pArray->tailKnownAssignedXids; tail = procArray->tailKnownAssignedXids;
head = pArray->headKnownAssignedXids; head = procArray->headKnownAssignedXids;
SpinLockRelease(&pArray->known_assigned_xids_lck); SpinLockRelease(&procArray->known_assigned_xids_lck);
for (i = tail; i < head; i++) for (i = tail; i < head; i++)
{ {

View File

@ -283,15 +283,13 @@ InitProcGlobal(void)
void void
InitProcess(void) InitProcess(void)
{ {
/* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal;
PGPROC * volatile * procgloballist; PGPROC * volatile * procgloballist;
/* /*
* ProcGlobal should be set up already (if we are a backend, we inherit * ProcGlobal should be set up already (if we are a backend, we inherit
* this by fork() or EXEC_BACKEND mechanism from the postmaster). * this by fork() or EXEC_BACKEND mechanism from the postmaster).
*/ */
if (procglobal == NULL) if (ProcGlobal == NULL)
elog(PANIC, "proc header uninitialized"); elog(PANIC, "proc header uninitialized");
if (MyProc != NULL) if (MyProc != NULL)
@ -299,11 +297,11 @@ InitProcess(void)
/* Decide which list should supply our PGPROC. */ /* Decide which list should supply our PGPROC. */
if (IsAnyAutoVacuumProcess()) if (IsAnyAutoVacuumProcess())
procgloballist = &procglobal->autovacFreeProcs; procgloballist = &ProcGlobal->autovacFreeProcs;
else if (IsBackgroundWorker) else if (IsBackgroundWorker)
procgloballist = &procglobal->bgworkerFreeProcs; procgloballist = &ProcGlobal->bgworkerFreeProcs;
else else
procgloballist = &procglobal->freeProcs; procgloballist = &ProcGlobal->freeProcs;
/* /*
* Try to get a proc struct from the appropriate free list. If this * Try to get a proc struct from the appropriate free list. If this
@ -314,7 +312,7 @@ InitProcess(void)
*/ */
SpinLockAcquire(ProcStructLock); SpinLockAcquire(ProcStructLock);
set_spins_per_delay(procglobal->spins_per_delay); set_spins_per_delay(ProcGlobal->spins_per_delay);
MyProc = *procgloballist; MyProc = *procgloballist;
@ -578,13 +576,10 @@ InitAuxiliaryProcess(void)
void void
PublishStartupProcessInformation(void) PublishStartupProcessInformation(void)
{ {
/* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal;
SpinLockAcquire(ProcStructLock); SpinLockAcquire(ProcStructLock);
procglobal->startupProc = MyProc; ProcGlobal->startupProc = MyProc;
procglobal->startupProcPid = MyProcPid; ProcGlobal->startupProcPid = MyProcPid;
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
} }
@ -627,12 +622,9 @@ HaveNFreeProcs(int n)
{ {
PGPROC *proc; PGPROC *proc;
/* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal;
SpinLockAcquire(ProcStructLock); SpinLockAcquire(ProcStructLock);
proc = procglobal->freeProcs; proc = ProcGlobal->freeProcs;
while (n > 0 && proc != NULL) while (n > 0 && proc != NULL)
{ {
@ -772,8 +764,6 @@ RemoveProcFromArray(int code, Datum arg)
static void static void
ProcKill(int code, Datum arg) ProcKill(int code, Datum arg)
{ {
/* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal;
PGPROC *proc; PGPROC *proc;
PGPROC * volatile * procgloballist; PGPROC * volatile * procgloballist;
@ -822,7 +812,7 @@ ProcKill(int code, Datum arg)
*procgloballist = proc; *procgloballist = proc;
/* Update shared estimate of spins_per_delay */ /* Update shared estimate of spins_per_delay */
procglobal->spins_per_delay = update_spins_per_delay(procglobal->spins_per_delay); ProcGlobal->spins_per_delay = update_spins_per_delay(ProcGlobal->spins_per_delay);
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
@ -1644,9 +1634,6 @@ ProcSendSignal(int pid)
if (RecoveryInProgress()) if (RecoveryInProgress())
{ {
/* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal;
SpinLockAcquire(ProcStructLock); SpinLockAcquire(ProcStructLock);
/* /*
@ -1657,8 +1644,8 @@ ProcSendSignal(int pid)
* backend, so BackendPidGetProc() will not return any pid at all. So * backend, so BackendPidGetProc() will not return any pid at all. So
* we remember the information for this special case. * we remember the information for this special case.
*/ */
if (pid == procglobal->startupProcPid) if (pid == ProcGlobal->startupProcPid)
proc = procglobal->startupProc; proc = ProcGlobal->startupProc;
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
} }