Oops, I had managed to break query-cancel-while-waiting-for-lock.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Jan 2001 20:59:34 +0000 (20:59 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Jan 2001 20:59:34 +0000 (20:59 +0000)
src/backend/storage/lmgr/proc.c
src/backend/tcop/postgres.c
src/include/storage/proc.h

index 83f8beeaa68e541253939e063495f0b861051bdc..3c2e55d8b113bcc8f9e710a3b082f43f720e2853 100644 (file)
@@ -353,16 +353,19 @@ RemoveFromWaitQueue(PROC *proc)
 /*
  * Cancel any pending wait for lock, when aborting a transaction.
  *
+ * Returns true if we had been waiting for a lock, else false.
+ *
  * (Normally, this would only happen if we accept a cancel/die
  * interrupt while waiting; but an elog(ERROR) while waiting is
  * within the realm of possibility, too.)
  */
-void
+bool
 LockWaitCancel(void)
 {
        /* Nothing to do if we weren't waiting for a lock */
        if (!waitingForLock)
-               return;
+               return false;
+
        waitingForLock = false;
 
        /* Turn off the deadlock timer, if it's still running (see ProcSleep) */
@@ -395,6 +398,12 @@ LockWaitCancel(void)
         * prematurely.
         */
        ZeroProcSemaphore(MyProc);
+
+       /*
+        * Return true even if we were kicked off the lock before we were
+        * able to remove ourselves.
+        */
+       return true;
 }
 
 
index 4e83fc73d4063c9cd84d3282ff36d567ef793b28..26e4d25fd0dc3748521748e13499b2f0853870db 100644 (file)
@@ -940,11 +940,14 @@ die(SIGNAL_ARGS)
                InterruptPending = true;
                ProcDiePending = true;
                /*
-                * If we're waiting for input, service the interrupt immediately
+                * If it's safe to interrupt, and we're waiting for input or a lock,
+                * service the interrupt immediately
                 */
                if (ImmediateInterruptOK && CritSectionCount == 0)
                {
                        DisableNotifyInterrupt();
+                       /* Make sure HandleDeadLock won't run while shutting down... */
+                       LockWaitCancel();
                        ProcessInterrupts();
                }
        }
@@ -967,8 +970,16 @@ QueryCancelHandler(SIGNAL_ARGS)
                InterruptPending = true;
                QueryCancelPending = true;
                /*
-                * No point in raising Cancel if we are waiting for input ...
+                * If it's safe to interrupt, and we're waiting for a lock,
+                * service the interrupt immediately.  No point in interrupting
+                * if we're waiting for input, however.
                 */
+               if (ImmediateInterruptOK && CritSectionCount == 0 &&
+                       LockWaitCancel())
+               {
+                       DisableNotifyInterrupt();
+                       ProcessInterrupts();
+               }
        }
 
        errno = save_errno;
@@ -1668,7 +1679,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
        if (!IsUnderPostmaster)
        {
                puts("\nPOSTGRES backend interactive interface ");
-               puts("$Revision: 1.201 $ $Date: 2001/01/14 05:08:16 $\n");
+               puts("$Revision: 1.202 $ $Date: 2001/01/16 20:59:34 $\n");
        }
 
        /*
index ddfb773506d295a1ce3521e306a744e07b0835fa..069651434ad36427fe04d22e99bad8c9f05e2ac8 100644 (file)
@@ -140,7 +140,7 @@ extern PROC *ProcWakeup(PROC *proc, int errType);
 extern int ProcLockWakeup(LOCKMETHOD lockmethod, LOCK *lock);
 extern void ProcAddLock(SHM_QUEUE *elem);
 extern void ProcReleaseSpins(PROC *proc);
-extern void LockWaitCancel(void);
+extern bool LockWaitCancel(void);
 extern void HandleDeadLock(SIGNAL_ARGS);
 
 #endif  /* PROC_H */