mirror of
https://github.com/postgres/postgres.git
synced 2025-08-17 01:02:17 +03:00
Remove the last vestiges of the MAKE_PTR/MAKE_OFFSET mechanism. We haven't
allowed different processes to have different addresses for the shmem segment in quite a long time, but there were still a few places left that used the old coding convention. Clean them up to reduce confusion and improve the compiler's ability to detect pointer type mismatches. Kris Jurka
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.100 2008/01/01 19:45:51 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.101 2008/11/02 21:24:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -77,9 +77,9 @@
|
||||
|
||||
static PGShmemHeader *ShmemSegHdr; /* shared mem segment header */
|
||||
|
||||
SHMEM_OFFSET ShmemBase; /* start address of shared memory */
|
||||
static void *ShmemBase; /* start address of shared memory */
|
||||
|
||||
static SHMEM_OFFSET ShmemEnd; /* end+1 address of shared memory */
|
||||
static void *ShmemEnd; /* end+1 address of shared memory */
|
||||
|
||||
slock_t *ShmemLock; /* spinlock for shared memory and LWLock
|
||||
* allocation */
|
||||
@@ -99,8 +99,8 @@ InitShmemAccess(void *seghdr)
|
||||
PGShmemHeader *shmhdr = (PGShmemHeader *) seghdr;
|
||||
|
||||
ShmemSegHdr = shmhdr;
|
||||
ShmemBase = (SHMEM_OFFSET) shmhdr;
|
||||
ShmemEnd = ShmemBase + shmhdr->totalsize;
|
||||
ShmemBase = (void *) shmhdr;
|
||||
ShmemEnd = (char *) ShmemBase + shmhdr->totalsize;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -127,7 +127,7 @@ InitShmemAllocation(void)
|
||||
SpinLockInit(ShmemLock);
|
||||
|
||||
/* ShmemIndex can't be set up yet (need LWLocks first) */
|
||||
shmhdr->indexoffset = 0;
|
||||
shmhdr->index = NULL;
|
||||
ShmemIndex = (HTAB *) NULL;
|
||||
|
||||
/*
|
||||
@@ -176,7 +176,7 @@ ShmemAlloc(Size size)
|
||||
newFree = newStart + size;
|
||||
if (newFree <= shmemseghdr->totalsize)
|
||||
{
|
||||
newSpace = (void *) MAKE_PTR(newStart);
|
||||
newSpace = (void *) ((char *) ShmemBase + newStart);
|
||||
shmemseghdr->freeoffset = newFree;
|
||||
}
|
||||
else
|
||||
@@ -193,14 +193,14 @@ ShmemAlloc(Size size)
|
||||
}
|
||||
|
||||
/*
|
||||
* ShmemIsValid -- test if an offset refers to valid shared memory
|
||||
* ShmemAddrIsValid -- test if an address refers to shared memory
|
||||
*
|
||||
* Returns TRUE if the pointer is valid.
|
||||
* Returns TRUE if the pointer points within the shared memory segment.
|
||||
*/
|
||||
bool
|
||||
ShmemIsValid(unsigned long addr)
|
||||
ShmemAddrIsValid(void *addr)
|
||||
{
|
||||
return (addr < ShmemEnd) && (addr >= ShmemBase);
|
||||
return (addr >= ShmemBase) && (addr < ShmemEnd);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -324,8 +324,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
if (IsUnderPostmaster)
|
||||
{
|
||||
/* Must be initializing a (non-standalone) backend */
|
||||
Assert(shmemseghdr->indexoffset != 0);
|
||||
structPtr = (void *) MAKE_PTR(shmemseghdr->indexoffset);
|
||||
Assert(shmemseghdr->index != NULL);
|
||||
structPtr = shmemseghdr->index;
|
||||
*foundPtr = TRUE;
|
||||
}
|
||||
else
|
||||
@@ -338,9 +338,9 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
* index has been initialized. This should be OK because no other
|
||||
* process can be accessing shared memory yet.
|
||||
*/
|
||||
Assert(shmemseghdr->indexoffset == 0);
|
||||
Assert(shmemseghdr->index == NULL);
|
||||
structPtr = ShmemAlloc(size);
|
||||
shmemseghdr->indexoffset = MAKE_OFFSET(structPtr);
|
||||
shmemseghdr->index = structPtr;
|
||||
*foundPtr = FALSE;
|
||||
}
|
||||
LWLockRelease(ShmemIndexLock);
|
||||
@@ -374,7 +374,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
/* let caller print its message too */
|
||||
return NULL;
|
||||
}
|
||||
structPtr = (void *) MAKE_PTR(result->location);
|
||||
structPtr = result->location;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -395,9 +395,9 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
return NULL;
|
||||
}
|
||||
result->size = size;
|
||||
result->location = MAKE_OFFSET(structPtr);
|
||||
result->location = structPtr;
|
||||
}
|
||||
Assert(ShmemIsValid((unsigned long) structPtr));
|
||||
Assert(ShmemAddrIsValid(structPtr));
|
||||
|
||||
LWLockRelease(ShmemIndexLock);
|
||||
return structPtr;
|
||||
|
Reference in New Issue
Block a user