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

Commit 07eeb9d

Browse files
committed
Do all accesses to shared buffer headers through volatile-qualified
pointers, to ensure that compilers won't rearrange accesses to occur while we're not holding the buffer header spinlock. It's probably not necessary to mark volatile in every single place in bufmgr.c, but better safe than sorry. Per trouble report from Kevin Grittner.
1 parent 6b97e43 commit 07eeb9d

File tree

4 files changed

+64
-71
lines changed

4 files changed

+64
-71
lines changed

contrib/pg_buffercache/pg_buffercache_pages.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* pg_buffercache_pages.c
44
* display some contents of the buffer cache
55
*
6-
* $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.4 2005/05/31 00:07:47 tgl Exp $
6+
* $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.5 2005/10/12 16:45:13 tgl Exp $
77
*-------------------------------------------------------------------------
88
*/
99
#include "postgres.h"
@@ -72,10 +72,8 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
7272

7373
if (SRF_IS_FIRSTCALL())
7474
{
75-
RelFileNode rnode;
7675
uint32 i;
77-
BufferDesc *bufHdr;
78-
76+
volatile BufferDesc *bufHdr;
7977

8078
funcctx = SRF_FIRSTCALL_INIT();
8179

@@ -136,35 +134,24 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
136134
/* Lock each buffer header before inspecting. */
137135
LockBufHdr(bufHdr);
138136

139-
rnode = bufHdr->tag.rnode;
140-
141137
fctx->record[i].bufferid = BufferDescriptorGetBuffer(bufHdr);
142-
fctx->record[i].relfilenode = rnode.relNode;
143-
fctx->record[i].reltablespace = rnode.spcNode;
144-
fctx->record[i].reldatabase = rnode.dbNode;
138+
fctx->record[i].relfilenode = bufHdr->tag.rnode.relNode;
139+
fctx->record[i].reltablespace = bufHdr->tag.rnode.spcNode;
140+
fctx->record[i].reldatabase = bufHdr->tag.rnode.dbNode;
145141
fctx->record[i].blocknum = bufHdr->tag.blockNum;
146142

147-
if ( bufHdr->flags & BM_DIRTY)
148-
{
143+
if (bufHdr->flags & BM_DIRTY)
149144
fctx->record[i].isdirty = true;
150-
}
151145
else
152-
{
153146
fctx->record[i].isdirty = false;
154-
}
155147

156148
/* Note if the buffer is valid, and has storage created */
157-
if ( (bufHdr->flags & BM_VALID) && (bufHdr->flags & BM_TAG_VALID))
158-
{
149+
if ((bufHdr->flags & BM_VALID) && (bufHdr->flags & BM_TAG_VALID))
159150
fctx->record[i].isvalid = true;
160-
}
161151
else
162-
{
163152
fctx->record[i].isvalid = false;
164-
}
165153

166154
UnlockBufHdr(bufHdr);
167-
168155
}
169156

170157
/* Release Buffer map. */

0 commit comments

Comments
 (0)