1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +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:
Tom Lane
2001-12-28 18:16:43 +00:00
parent 774490c3db
commit d3fc362ec2
3 changed files with 75 additions and 42 deletions

View File

@@ -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;