Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 430008b

Browse files
committed
Remove volatile qualifiers from dynahash.c, shmem.c, and sinvaladt.c
Prior to commit 0709b7e, access to variables within a spinlock-protected critical section had to be done through a volatile pointer, but that should no longer be necessary. Thomas Munro
1 parent 78652a3 commit 430008b

File tree

3 files changed

+37
-55
lines changed

3 files changed

+37
-55
lines changed

src/backend/storage/ipc/shmem.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -170,29 +170,26 @@ ShmemAlloc(Size size)
170170
Size newFree;
171171
void *newSpace;
172172

173-
/* use volatile pointer to prevent code rearrangement */
174-
volatile PGShmemHeader *shmemseghdr = ShmemSegHdr;
175-
176173
/*
177174
* ensure all space is adequately aligned.
178175
*/
179176
size = MAXALIGN(size);
180177

181-
Assert(shmemseghdr != NULL);
178+
Assert(ShmemSegHdr != NULL);
182179

183180
SpinLockAcquire(ShmemLock);
184181

185-
newStart = shmemseghdr->freeoffset;
182+
newStart = ShmemSegHdr->freeoffset;
186183

187184
/* extra alignment for large requests, since they are probably buffers */
188185
if (size >= BLCKSZ)
189186
newStart = BUFFERALIGN(newStart);
190187

191188
newFree = newStart + size;
192-
if (newFree <= shmemseghdr->totalsize)
189+
if (newFree <= ShmemSegHdr->totalsize)
193190
{
194191
newSpace = (void *) ((char *) ShmemBase + newStart);
195-
shmemseghdr->freeoffset = newFree;
192+
ShmemSegHdr->freeoffset = newFree;
196193
}
197194
else
198195
newSpace = NULL;

src/backend/storage/ipc/sinvaladt.c

+6-16
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,9 @@ SIInsertDataEntries(const SharedInvalidationMessage *data, int n)
485485
}
486486

487487
/* Update current value of maxMsgNum using spinlock */
488-
{
489-
/* use volatile pointer to prevent code rearrangement */
490-
volatile SISeg *vsegP = segP;
491-
492-
SpinLockAcquire(&vsegP->msgnumLock);
493-
vsegP->maxMsgNum = max;
494-
SpinLockRelease(&vsegP->msgnumLock);
495-
}
488+
SpinLockAcquire(&segP->msgnumLock);
489+
segP->maxMsgNum = max;
490+
SpinLockRelease(&segP->msgnumLock);
496491

497492
/*
498493
* Now that the maxMsgNum change is globally visible, we give everyone
@@ -579,14 +574,9 @@ SIGetDataEntries(SharedInvalidationMessage *data, int datasize)
579574
stateP->hasMessages = false;
580575

581576
/* Fetch current value of maxMsgNum using spinlock */
582-
{
583-
/* use volatile pointer to prevent code rearrangement */
584-
volatile SISeg *vsegP = segP;
585-
586-
SpinLockAcquire(&vsegP->msgnumLock);
587-
max = vsegP->maxMsgNum;
588-
SpinLockRelease(&vsegP->msgnumLock);
589-
}
577+
SpinLockAcquire(&segP->msgnumLock);
578+
max = segP->maxMsgNum;
579+
SpinLockRelease(&segP->msgnumLock);
590580

591581
if (stateP->resetState)
592582
{

src/backend/utils/hash/dynahash.c

+27-32
Original file line numberDiff line numberDiff line change
@@ -941,25 +941,22 @@ hash_search_with_hash_value(HTAB *hashp,
941941
case HASH_REMOVE:
942942
if (currBucket != NULL)
943943
{
944-
/* use volatile pointer to prevent code rearrangement */
945-
volatile HASHHDR *hctlv = hctl;
946-
947944
/* if partitioned, must lock to touch nentries and freeList */
948-
if (IS_PARTITIONED(hctlv))
949-
SpinLockAcquire(&hctlv->mutex);
945+
if (IS_PARTITIONED(hctl))
946+
SpinLockAcquire(&hctl->mutex);
950947

951-
Assert(hctlv->nentries > 0);
952-
hctlv->nentries--;
948+
Assert(hctl->nentries > 0);
949+
hctl->nentries--;
953950

954951
/* remove record from hash bucket's chain. */
955952
*prevBucketPtr = currBucket->link;
956953

957954
/* add the record to the freelist for this table. */
958-
currBucket->link = hctlv->freeList;
959-
hctlv->freeList = currBucket;
955+
currBucket->link = hctl->freeList;
956+
hctl->freeList = currBucket;
960957

961-
if (IS_PARTITIONED(hctlv))
962-
SpinLockRelease(&hctlv->mutex);
958+
if (IS_PARTITIONED(hctl))
959+
SpinLockRelease(&hctl->mutex);
963960

964961
/*
965962
* better hope the caller is synchronizing access to this
@@ -1180,38 +1177,37 @@ hash_update_hash_key(HTAB *hashp,
11801177
static HASHBUCKET
11811178
get_hash_entry(HTAB *hashp)
11821179
{
1183-
/* use volatile pointer to prevent code rearrangement */
1184-
volatile HASHHDR *hctlv = hashp->hctl;
1180+
HASHHDR *hctl = hashp->hctl;
11851181
HASHBUCKET newElement;
11861182

11871183
for (;;)
11881184
{
11891185
/* if partitioned, must lock to touch nentries and freeList */
1190-
if (IS_PARTITIONED(hctlv))
1191-
SpinLockAcquire(&hctlv->mutex);
1186+
if (IS_PARTITIONED(hctl))
1187+
SpinLockAcquire(&hctl->mutex);
11921188

11931189
/* try to get an entry from the freelist */
1194-
newElement = hctlv->freeList;
1190+
newElement = hctl->freeList;
11951191
if (newElement != NULL)
11961192
break;
11971193

11981194
/* no free elements. allocate another chunk of buckets */
1199-
if (IS_PARTITIONED(hctlv))
1200-
SpinLockRelease(&hctlv->mutex);
1195+
if (IS_PARTITIONED(hctl))
1196+
SpinLockRelease(&hctl->mutex);
12011197

1202-
if (!element_alloc(hashp, hctlv->nelem_alloc))
1198+
if (!element_alloc(hashp, hctl->nelem_alloc))
12031199
{
12041200
/* out of memory */
12051201
return NULL;
12061202
}
12071203
}
12081204

12091205
/* remove entry from freelist, bump nentries */
1210-
hctlv->freeList = newElement->link;
1211-
hctlv->nentries++;
1206+
hctl->freeList = newElement->link;
1207+
hctl->nentries++;
12121208

1213-
if (IS_PARTITIONED(hctlv))
1214-
SpinLockRelease(&hctlv->mutex);
1209+
if (IS_PARTITIONED(hctl))
1210+
SpinLockRelease(&hctl->mutex);
12151211

12161212
return newElement;
12171213
}
@@ -1536,8 +1532,7 @@ seg_alloc(HTAB *hashp)
15361532
static bool
15371533
element_alloc(HTAB *hashp, int nelem)
15381534
{
1539-
/* use volatile pointer to prevent code rearrangement */
1540-
volatile HASHHDR *hctlv = hashp->hctl;
1535+
HASHHDR *hctl = hashp->hctl;
15411536
Size elementSize;
15421537
HASHELEMENT *firstElement;
15431538
HASHELEMENT *tmpElement;
@@ -1548,7 +1543,7 @@ element_alloc(HTAB *hashp, int nelem)
15481543
return false;
15491544

15501545
/* Each element has a HASHELEMENT header plus user data. */
1551-
elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(hctlv->entrysize);
1546+
elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(hctl->entrysize);
15521547

15531548
CurrentDynaHashCxt = hashp->hcxt;
15541549
firstElement = (HASHELEMENT *) hashp->alloc(nelem * elementSize);
@@ -1567,15 +1562,15 @@ element_alloc(HTAB *hashp, int nelem)
15671562
}
15681563

15691564
/* if partitioned, must lock to touch freeList */
1570-
if (IS_PARTITIONED(hctlv))
1571-
SpinLockAcquire(&hctlv->mutex);
1565+
if (IS_PARTITIONED(hctl))
1566+
SpinLockAcquire(&hctl->mutex);
15721567

15731568
/* freelist could be nonempty if two backends did this concurrently */
1574-
firstElement->link = hctlv->freeList;
1575-
hctlv->freeList = prevElement;
1569+
firstElement->link = hctl->freeList;
1570+
hctl->freeList = prevElement;
15761571

1577-
if (IS_PARTITIONED(hctlv))
1578-
SpinLockRelease(&hctlv->mutex);
1572+
if (IS_PARTITIONED(hctl))
1573+
SpinLockRelease(&hctl->mutex);
15791574

15801575
return true;
15811576
}

0 commit comments

Comments
 (0)