mirror of
https://github.com/postgres/postgres.git
synced 2025-09-08 00:47:37 +03:00
Ensure that all direct uses of spinlock-protected data structures use
'volatile' pointers to access those structures, so that optimizing compilers will not decide to move the structure accesses outside of the spinlock-acquire-to-spinlock-release sequence. There are no known bugs in these uses at present, but based on bad experience with lwlock.c, it seems prudent to ensure that we protect these other uses too. Per pghackers discussion around 12-Dec. (Note: it should not be necessary to worry about structures protected by LWLocks, since the LWLock acquire and release operations are not inline macros.)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.62 2001/10/25 05:49:42 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.63 2001/12/28 18:16:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -132,21 +132,23 @@ ShmemAlloc(Size size)
|
||||
{
|
||||
uint32 newFree;
|
||||
void *newSpace;
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
volatile PGShmemHeader *shmemseghdr = ShmemSegHdr;
|
||||
|
||||
/*
|
||||
* ensure all space is adequately aligned.
|
||||
*/
|
||||
size = MAXALIGN(size);
|
||||
|
||||
Assert(ShmemSegHdr != NULL);
|
||||
Assert(shmemseghdr != NULL);
|
||||
|
||||
SpinLockAcquire(ShmemLock);
|
||||
|
||||
newFree = ShmemSegHdr->freeoffset + size;
|
||||
if (newFree <= ShmemSegHdr->totalsize)
|
||||
newFree = shmemseghdr->freeoffset + size;
|
||||
if (newFree <= shmemseghdr->totalsize)
|
||||
{
|
||||
newSpace = (void *) MAKE_PTR(ShmemSegHdr->freeoffset);
|
||||
ShmemSegHdr->freeoffset = newFree;
|
||||
newSpace = (void *) MAKE_PTR(shmemseghdr->freeoffset);
|
||||
shmemseghdr->freeoffset = newFree;
|
||||
}
|
||||
else
|
||||
newSpace = NULL;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.116 2001/11/08 20:37:52 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.117 2001/12/28 18:16:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -203,12 +203,14 @@ void
|
||||
InitProcess(void)
|
||||
{
|
||||
SHMEM_OFFSET myOffset;
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
volatile PROC_HDR *procglobal = ProcGlobal;
|
||||
|
||||
/*
|
||||
* ProcGlobal should be set by a previous call to InitProcGlobal (if
|
||||
* we are a backend, we inherit this by fork() from the postmaster).
|
||||
*/
|
||||
if (ProcGlobal == NULL)
|
||||
if (procglobal == NULL)
|
||||
elog(STOP, "InitProcess: Proc Header uninitialized");
|
||||
|
||||
if (MyProc != NULL)
|
||||
@@ -219,12 +221,12 @@ InitProcess(void)
|
||||
*/
|
||||
SpinLockAcquire(ProcStructLock);
|
||||
|
||||
myOffset = ProcGlobal->freeProcs;
|
||||
myOffset = procglobal->freeProcs;
|
||||
|
||||
if (myOffset != INVALID_OFFSET)
|
||||
{
|
||||
MyProc = (PROC *) MAKE_PTR(myOffset);
|
||||
ProcGlobal->freeProcs = MyProc->links.next;
|
||||
procglobal->freeProcs = MyProc->links.next;
|
||||
SpinLockRelease(ProcStructLock);
|
||||
}
|
||||
else
|
||||
@@ -437,6 +439,9 @@ ProcReleaseLocks(bool isCommit)
|
||||
static void
|
||||
ProcKill(void)
|
||||
{
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
volatile PROC_HDR *procglobal = ProcGlobal;
|
||||
|
||||
Assert(MyProc != NULL);
|
||||
|
||||
/* Release any LW locks I am holding */
|
||||
@@ -463,8 +468,8 @@ ProcKill(void)
|
||||
ProcFreeSem(MyProc->sem.semId, MyProc->sem.semNum);
|
||||
|
||||
/* Add PROC struct to freelist so space can be recycled in future */
|
||||
MyProc->links.next = ProcGlobal->freeProcs;
|
||||
ProcGlobal->freeProcs = MAKE_OFFSET(MyProc);
|
||||
MyProc->links.next = procglobal->freeProcs;
|
||||
procglobal->freeProcs = MAKE_OFFSET(MyProc);
|
||||
|
||||
/* PROC struct isn't mine anymore */
|
||||
MyProc = NULL;
|
||||
@@ -1044,10 +1049,12 @@ disable_sigalrm_interrupt(void)
|
||||
static void
|
||||
ProcGetNewSemIdAndNum(IpcSemaphoreId *semId, int *semNum)
|
||||
{
|
||||
int i;
|
||||
int semMapEntries = ProcGlobal->semMapEntries;
|
||||
SEM_MAP_ENTRY *procSemMap = ProcGlobal->procSemMap;
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
volatile PROC_HDR *procglobal = ProcGlobal;
|
||||
int semMapEntries = procglobal->semMapEntries;
|
||||
volatile SEM_MAP_ENTRY *procSemMap = procglobal->procSemMap;
|
||||
int32 fullmask = (1 << PROC_NSEMS_PER_SET) - 1;
|
||||
int i;
|
||||
|
||||
SpinLockAcquire(ProcStructLock);
|
||||
|
||||
|
Reference in New Issue
Block a user