*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.195 2005/08/12 23:13:54 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.196 2005/10/12 16:45:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* local state for StartBufferIO and related functions */
-static BufferDesc *InProgressBuf = NULL;
+static volatile BufferDesc *InProgressBuf = NULL;
static bool IsForInput;
/* local state for LockBufferForCleanup */
-static BufferDesc *PinCountWaitBuf = NULL;
+static volatile BufferDesc *PinCountWaitBuf = NULL;
-static bool PinBuffer(BufferDesc *buf);
-static void PinBuffer_Locked(BufferDesc *buf);
-static void UnpinBuffer(BufferDesc *buf, bool fixOwner, bool trashOK);
+static bool PinBuffer(volatile BufferDesc *buf);
+static void PinBuffer_Locked(volatile BufferDesc *buf);
+static void UnpinBuffer(volatile BufferDesc *buf, bool fixOwner, bool trashOK);
static bool SyncOneBuffer(int buf_id, bool skip_pinned);
-static void WaitIO(BufferDesc *buf);
-static bool StartBufferIO(BufferDesc *buf, bool forInput);
-static void TerminateBufferIO(BufferDesc *buf, bool clear_dirty,
+static void WaitIO(volatile BufferDesc *buf);
+static bool StartBufferIO(volatile BufferDesc *buf, bool forInput);
+static void TerminateBufferIO(volatile BufferDesc *buf, bool clear_dirty,
int set_flag_bits);
static void buffer_write_error_callback(void *arg);
-static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
+static volatile BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
bool *foundPtr);
-static void FlushBuffer(BufferDesc *buf, SMgrRelation reln);
+static void FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln);
static void AtProcExit_Buffers(int code, Datum arg);
static void write_buffer(Buffer buffer, bool unpin);
Buffer
ReadBuffer(Relation reln, BlockNumber blockNum)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
Block bufBlock;
bool found;
bool isExtend;
*
* No locks are held either at entry or exit.
*/
-static BufferDesc *
+static volatile BufferDesc *
BufferAlloc(Relation reln,
BlockNumber blockNum,
bool *foundPtr)
BufferTag oldTag;
BufFlags oldFlags;
int buf_id;
- BufferDesc *buf;
+ volatile BufferDesc *buf;
bool valid;
/* create a tag so we can lookup the buffer */
* to acquire the necessary locks; if so, don't mess it up.
*/
static void
-InvalidateBuffer(BufferDesc *buf)
+InvalidateBuffer(volatile BufferDesc *buf)
{
BufferTag oldTag;
BufFlags oldFlags;
static void
write_buffer(Buffer buffer, bool unpin)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
if (!BufferIsValid(buffer))
elog(ERROR, "bad buffer id: %d", buffer);
Relation relation,
BlockNumber blockNum)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
if (BufferIsValid(buffer))
{
* some callers to avoid an extra spinlock cycle.
*/
static bool
-PinBuffer(BufferDesc *buf)
+PinBuffer(volatile BufferDesc *buf)
{
int b = buf->buf_id;
bool result;
* its state can change under us.
*/
static void
-PinBuffer_Locked(BufferDesc *buf)
+PinBuffer_Locked(volatile BufferDesc *buf)
{
int b = buf->buf_id;
* used recently, and trashOK is true, send the buffer to the freelist.
*/
static void
-UnpinBuffer(BufferDesc *buf, bool fixOwner, bool trashOK)
+UnpinBuffer(volatile BufferDesc *buf, bool fixOwner, bool trashOK)
{
int b = buf->buf_id;
static bool
SyncOneBuffer(int buf_id, bool skip_pinned)
{
- BufferDesc *bufHdr = &BufferDescriptors[buf_id];
+ volatile BufferDesc *bufHdr = &BufferDescriptors[buf_id];
/*
* Check whether buffer needs writing.
{
if (PrivateRefCount[i] != 0)
{
- BufferDesc *buf = &(BufferDescriptors[i]);
+ volatile BufferDesc *buf = &(BufferDescriptors[i]);
/*
* We don't worry about updating ResourceOwner; if we even got
void
PrintBufferLeakWarning(Buffer buffer)
{
- BufferDesc *buf;
+ volatile BufferDesc *buf;
int32 loccount;
Assert(BufferIsValid(buffer));
BlockNumber
BufferGetBlockNumber(Buffer buffer)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
Assert(BufferIsPinned(buffer));
RelFileNode
BufferGetFileNode(Buffer buffer)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
if (BufferIsLocal(buffer))
bufHdr = &(LocalBufferDescriptors[-buffer - 1]);
* as the second parameter. If not, pass NULL.
*/
static void
-FlushBuffer(BufferDesc *buf, SMgrRelation reln)
+FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
{
XLogRecPtr recptr;
ErrorContextCallback errcontext;
/* Setup error traceback support for ereport() */
errcontext.callback = buffer_write_error_callback;
- errcontext.arg = buf;
+ errcontext.arg = (void *) buf;
errcontext.previous = error_context_stack;
error_context_stack = &errcontext;
BlockNumber firstDelBlock)
{
int i;
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
if (istemp)
{
DropBuffers(Oid dbid)
{
int i;
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
/*
* We needn't consider local buffers, since by assumption the target
PrintBufferDescs(void)
{
int i;
- BufferDesc *buf = BufferDescriptors;
+ volatile BufferDesc *buf = BufferDescriptors;
for (i = 0; i < NBuffers; ++i, ++buf)
{
PrintPinnedBufs(void)
{
int i;
- BufferDesc *buf = BufferDescriptors;
+ volatile BufferDesc *buf = BufferDescriptors;
for (i = 0; i < NBuffers; ++i, ++buf)
{
FlushRelationBuffers(Relation rel)
{
int i;
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
/* Open rel at the smgr level if not already done */
RelationOpenSmgr(rel);
/* Setup error traceback support for ereport() */
errcontext.callback = buffer_write_error_callback;
- errcontext.arg = bufHdr;
+ errcontext.arg = (void *) bufHdr;
errcontext.previous = error_context_stack;
error_context_stack = &errcontext;
void
ReleaseBuffer(Buffer buffer)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
if (!BufferIsValid(buffer))
elog(ERROR, "bad buffer id: %d", buffer);
void
SetBufferCommitInfoNeedsSave(Buffer buffer)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
if (!BufferIsValid(buffer))
elog(ERROR, "bad buffer id: %d", buffer);
void
UnlockBuffers(void)
{
- BufferDesc *buf = PinCountWaitBuf;
+ volatile BufferDesc *buf = PinCountWaitBuf;
if (buf)
{
void
LockBuffer(Buffer buffer, int mode)
{
- BufferDesc *buf;
+ volatile BufferDesc *buf;
Assert(BufferIsValid(buffer));
if (BufferIsLocal(buffer))
bool
ConditionalLockBuffer(Buffer buffer)
{
- BufferDesc *buf;
+ volatile BufferDesc *buf;
Assert(BufferIsValid(buffer));
if (BufferIsLocal(buffer))
void
LockBufferForCleanup(Buffer buffer)
{
- BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
Assert(BufferIsValid(buffer));
Assert(PinCountWaitBuf == NULL);
* WaitIO -- Block until the IO_IN_PROGRESS flag on 'buf' is cleared.
*/
static void
-WaitIO(BufferDesc *buf)
+WaitIO(volatile BufferDesc *buf)
{
/*
* Changed to wait until there's no IO - Inoue 01/13/2000
* FALSE if someone else already did the work.
*/
static bool
-StartBufferIO(BufferDesc *buf, bool forInput)
+StartBufferIO(volatile BufferDesc *buf, bool forInput)
{
Assert(!InProgressBuf);
* be 0, or BM_VALID if we just finished reading in the page.
*/
static void
-TerminateBufferIO(BufferDesc *buf, bool clear_dirty, int set_flag_bits)
+TerminateBufferIO(volatile BufferDesc *buf, bool clear_dirty,
+ int set_flag_bits)
{
Assert(buf == InProgressBuf);
void
AbortBufferIO(void)
{
- BufferDesc *buf = InProgressBuf;
+ volatile BufferDesc *buf = InProgressBuf;
if (buf)
{
static void
buffer_write_error_callback(void *arg)
{
- BufferDesc *bufHdr = (BufferDesc *) arg;
+ volatile BufferDesc *bufHdr = (volatile BufferDesc *) arg;
/* Buffer is pinned, so we can read the tag without locking the spinlock */
if (bufHdr != NULL)