1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Make critical sections (elog->crash) and interrupt holdoff sections

into distinct concepts, per recent discussion on pghackers.
This commit is contained in:
Tom Lane
2001-01-19 22:08:47 +00:00
parent 75815c3100
commit 6ce0ed2813
9 changed files with 104 additions and 72 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.104 2001/01/14 05:08:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.105 2001/01/19 22:08:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -873,10 +873,10 @@ WaitIO(BufferDesc *buf, SPINLOCK spinlock)
while ((buf->flags & BM_IO_IN_PROGRESS) != 0)
{
SpinRelease(spinlock);
START_CRIT_SECTION(); /* don't want to die() holding the lock... */
HOLD_INTERRUPTS(); /* don't want to die() holding the lock... */
S_LOCK(&(buf->io_in_progress_lock));
S_UNLOCK(&(buf->io_in_progress_lock));
END_CRIT_SECTION();
RESUME_INTERRUPTS();
SpinAcquire(spinlock);
}
}
@@ -1027,14 +1027,14 @@ BufmgrCommit(void)
* Returns the block number associated with a buffer.
*
* Note:
* Assumes that the buffer is valid.
* Assumes that the buffer is valid and pinned, else the
* value may be obsolete immediately...
*/
BlockNumber
BufferGetBlockNumber(Buffer buffer)
{
Assert(BufferIsValid(buffer));
/* XXX should be a critical section */
if (BufferIsLocal(buffer))
return LocalBufferDescriptors[-buffer - 1].tag.blockNum;
else
@@ -1956,7 +1956,7 @@ UnlockBuffers(void)
Assert(BufferIsValid(i + 1));
buf = &(BufferDescriptors[i]);
START_CRIT_SECTION(); /* don't want to die() holding the lock... */
HOLD_INTERRUPTS(); /* don't want to die() holding the lock... */
S_LOCK(&(buf->cntx_lock));
@@ -1986,7 +1986,7 @@ UnlockBuffers(void)
BufferLocks[i] = 0;
END_CRIT_SECTION();
RESUME_INTERRUPTS();
}
}
@@ -2003,7 +2003,7 @@ LockBuffer(Buffer buffer, int mode)
buf = &(BufferDescriptors[buffer - 1]);
buflock = &(BufferLocks[buffer - 1]);
START_CRIT_SECTION(); /* don't want to die() holding the lock... */
HOLD_INTERRUPTS(); /* don't want to die() holding the lock... */
S_LOCK(&(buf->cntx_lock));
@@ -2028,7 +2028,7 @@ LockBuffer(Buffer buffer, int mode)
else
{
S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
RESUME_INTERRUPTS();
elog(ERROR, "UNLockBuffer: buffer %lu is not locked", buffer);
}
}
@@ -2040,9 +2040,9 @@ LockBuffer(Buffer buffer, int mode)
while (buf->ri_lock || buf->w_lock)
{
S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
RESUME_INTERRUPTS();
S_LOCK_SLEEP(&(buf->cntx_lock), i++);
START_CRIT_SECTION();
HOLD_INTERRUPTS();
S_LOCK(&(buf->cntx_lock));
}
(buf->r_locks)++;
@@ -2068,9 +2068,9 @@ LockBuffer(Buffer buffer, int mode)
buf->ri_lock = true;
}
S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
RESUME_INTERRUPTS();
S_LOCK_SLEEP(&(buf->cntx_lock), i++);
START_CRIT_SECTION();
HOLD_INTERRUPTS();
S_LOCK(&(buf->cntx_lock));
}
buf->w_lock = true;
@@ -2092,12 +2092,12 @@ LockBuffer(Buffer buffer, int mode)
else
{
S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
RESUME_INTERRUPTS();
elog(ERROR, "LockBuffer: unknown lock mode %d", mode);
}
S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
RESUME_INTERRUPTS();
}
/*
@@ -2118,7 +2118,7 @@ static bool IsForInput;
* BM_IO_IN_PROGRESS mask is not set for the buffer
* The buffer is Pinned
*
* Because BufMgrLock is held, we are already in a CRIT_SECTION here,
* Because BufMgrLock is held, we are already in an interrupt holdoff here,
* and do not need another.
*/
static void
@@ -2152,7 +2152,7 @@ StartBufferIO(BufferDesc *buf, bool forInput)
* BufMgrLock is held
* The buffer is Pinned
*
* Because BufMgrLock is held, we are already in a CRIT_SECTION here,
* Because BufMgrLock is held, we are already in an interrupt holdoff here,
* and do not need another.
*/
static void
@@ -2170,7 +2170,7 @@ TerminateBufferIO(BufferDesc *buf)
* BufMgrLock is held
* The buffer is Pinned
*
* Because BufMgrLock is held, we are already in a CRIT_SECTION here,
* Because BufMgrLock is held, we are already in an interrupt holdoff here,
* and do not need another.
*/
static void

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.60 2001/01/14 05:08:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.61 2001/01/19 22:08:46 tgl Exp $
*
* NOTES
*
@@ -136,7 +136,8 @@ proc_exit(int code)
QueryCancelPending = false;
/* And let's just make *sure* we're not interrupted ... */
ImmediateInterruptOK = false;
CritSectionCount = 1;
InterruptHoldoffCount = 1;
CritSectionCount = 0;
if (DebugLvl > 1)
elog(DEBUG, "proc_exit(%d)", code);

View File

@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.29 2001/01/14 05:08:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.30 2001/01/19 22:08:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -148,19 +148,19 @@ SpinAcquire(SPINLOCK lockid)
PRINT_SLDEBUG("SpinAcquire", lockid, slckP);
/*
* Acquire the lock, then record that we have done so (for recovery
* in case of elog(ERROR) during the critical section). Note we assume
* in case of elog(ERROR) while holding the lock). Note we assume
* here that S_LOCK will not accept cancel/die interrupts once it has
* acquired the lock. However, interrupts should be accepted while
* waiting, if CritSectionCount is zero.
* waiting, if InterruptHoldoffCount is zero.
*/
S_LOCK(&(slckP->shlock));
PROC_INCR_SLOCK(lockid);
/*
* Lock out cancel/die interrupts until we exit the critical section
* Lock out cancel/die interrupts until we exit the code section
* protected by the spinlock. This ensures that interrupts will not
* interfere with manipulations of data structures in shared memory.
*/
START_CRIT_SECTION();
HOLD_INTERRUPTS();
PRINT_SLDEBUG("SpinAcquire/done", lockid, slckP);
}
@@ -182,9 +182,9 @@ SpinRelease(SPINLOCK lockid)
PROC_DECR_SLOCK(lockid);
S_UNLOCK(&(slckP->shlock));
/*
* Exit the critical section entered in SpinAcquire().
* Exit the interrupt holdoff entered in SpinAcquire().
*/
END_CRIT_SECTION();
RESUME_INTERRUPTS();
PRINT_SLDEBUG("SpinRelease/done", lockid, slckP);
}
@@ -329,7 +329,7 @@ SpinAcquire(SPINLOCK lock)
*/
IpcSemaphoreLock(SpinLockIds[0], lock, false);
PROC_INCR_SLOCK(lock);
START_CRIT_SECTION();
HOLD_INTERRUPTS();
}
/*
@@ -351,7 +351,7 @@ SpinRelease(SPINLOCK lock)
Assert(!MyProc || MyProc->sLocks[lockid] > 0);
PROC_DECR_SLOCK(lock);
IpcSemaphoreUnlock(SpinLockIds[0], lock);
END_CRIT_SECTION();
RESUME_INTERRUPTS();
}
/*