summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc/spin.c
diff options
context:
space:
mode:
authorTom Lane2001-01-14 05:08:17 +0000
committerTom Lane2001-01-14 05:08:17 +0000
commit36839c192706f5abd75bdcb02b6a7cace14ce108 (patch)
tree3022631b1208e1227684db86c12cbba7da15f611 /src/backend/storage/ipc/spin.c
parent027f144e390afa6f189270e8c2a2a56c0a88f646 (diff)
Restructure backend SIGINT/SIGTERM handling so that 'die' interrupts
are treated more like 'cancel' interrupts: the signal handler sets a flag that is examined at well-defined spots, rather than trying to cope with an interrupt that might happen anywhere. See pghackers discussion of 1/12/01.
Diffstat (limited to 'src/backend/storage/ipc/spin.c')
-rw-r--r--src/backend/storage/ipc/spin.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/backend/storage/ipc/spin.c b/src/backend/storage/ipc/spin.c
index ed71d79ad9f..b27c1810020 100644
--- a/src/backend/storage/ipc/spin.c
+++ b/src/backend/storage/ipc/spin.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.28 2001/01/12 21:53:59 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.29 2001/01/14 05:08:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -25,9 +25,11 @@
#include <sys/sem.h>
#endif
+#include "miscadmin.h"
#include "storage/proc.h"
#include "storage/s_lock.h"
+
/* Probably should move these to an appropriate header file */
extern SPINLOCK ShmemLock;
extern SPINLOCK ShmemIndexLock;
@@ -145,19 +147,20 @@ SpinAcquire(SPINLOCK lockid)
PRINT_SLDEBUG("SpinAcquire", lockid, slckP);
/*
- * Lock out die() until we exit the critical section protected by the
- * spinlock. This ensures that die() will not interrupt manipulations
- * of data structures in shared memory. We don't want die() to
- * interrupt this routine between S_LOCK and PROC_INCR_SLOCK, either,
- * so must do it before acquiring the lock, not after.
- */
- START_CRIT_SECTION();
- /*
* Acquire the lock, then record that we have done so (for recovery
- * in case of elog(ERROR) during the critical section).
+ * in case of elog(ERROR) during the critical section). 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.
*/
S_LOCK(&(slckP->shlock));
PROC_INCR_SLOCK(lockid);
+ /*
+ * Lock out cancel/die interrupts until we exit the critical section
+ * protected by the spinlock. This ensures that interrupts will not
+ * interfere with manipulations of data structures in shared memory.
+ */
+ START_CRIT_SECTION();
PRINT_SLDEBUG("SpinAcquire/done", lockid, slckP);
}
@@ -317,10 +320,16 @@ SpinFreeAllSemaphores(void)
void
SpinAcquire(SPINLOCK lock)
{
- /* See the TAS() version of this routine for commentary */
- START_CRIT_SECTION();
- IpcSemaphoreLock(SpinLockIds[0], lock);
+ /*
+ * See the TAS() version of this routine for primary commentary.
+ *
+ * NOTE we must pass interruptOK = false to IpcSemaphoreLock, to ensure
+ * that a cancel/die interrupt cannot prevent us from recording ownership
+ * of a lock we have just acquired.
+ */
+ IpcSemaphoreLock(SpinLockIds[0], lock, false);
PROC_INCR_SLOCK(lock);
+ START_CRIT_SECTION();
}
/*
@@ -338,8 +347,8 @@ SpinRelease(SPINLOCK lock)
semval = IpcSemaphoreGetValue(SpinLockIds[0], lock);
Assert(semval < 1);
- Assert(!MyProc || MyProc->sLocks[lockid] > 0);
#endif
+ Assert(!MyProc || MyProc->sLocks[lockid] > 0);
PROC_DECR_SLOCK(lock);
IpcSemaphoreUnlock(SpinLockIds[0], lock);
END_CRIT_SECTION();