Commit 3cd3be92 authored by Bruce Momjian's avatar Bruce Momjian

Fix deadlock so it only checks once.

parent bb76dd85
/* A lexical scanner generated by flex */ /* A lexical scanner generated by flex */
/* Scanner skeleton version: /* Scanner skeleton version:
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.31 1998/10/13 17:26:50 scrappy Exp $ * /master/usr.bin/lex/skel.c,v 1.3 1997/09/25 00:10:23 jch Exp
*/ */
#define FLEX_SCANNER #define FLEX_SCANNER
...@@ -556,7 +556,7 @@ char *yytext; ...@@ -556,7 +556,7 @@ char *yytext;
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.31 1998/10/13 17:26:50 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.32 1998/12/18 19:45:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.43 1998/09/01 04:32:02 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.44 1998/12/18 19:45:37 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore * This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95 * sets run out pretty fast.) -ay 4/95
* *
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.43 1998/09/01 04:32:02 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.44 1998/12/18 19:45:37 momjian Exp $
*/ */
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
#include "storage/proc.h" #include "storage/proc.h"
#include "utils/trace.h" #include "utils/trace.h"
static void HandleDeadLock(int sig); static void HandleDeadLock(void);
static PROC *ProcWakeup(PROC *proc, int errType); static PROC *ProcWakeup(PROC *proc, int errType);
#define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT] #define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
...@@ -154,8 +154,6 @@ InitProcess(IPCKey key) ...@@ -154,8 +154,6 @@ InitProcess(IPCKey key)
* Routine called if deadlock timer goes off. See ProcSleep() * Routine called if deadlock timer goes off. See ProcSleep()
* ------------------ * ------------------
*/ */
pqsignal(SIGALRM, HandleDeadLock);
SpinAcquire(ProcStructLock); SpinAcquire(ProcStructLock);
/* attach to the free list */ /* attach to the free list */
...@@ -449,9 +447,9 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */ ...@@ -449,9 +447,9 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
TransactionId xid) /* needed by user locks, see below */ TransactionId xid) /* needed by user locks, see below */
{ {
int i; int i;
bool deadlock_checked = false;
PROC *proc; PROC *proc;
struct itimerval timeval, struct timeval timeval;
dummy;
/* /*
* If the first entries in the waitQueue have a greater priority than * If the first entries in the waitQueue have a greater priority than
...@@ -523,17 +521,26 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */ ...@@ -523,17 +521,26 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
* to 0. * to 0.
* -------------- * --------------
*/ */
MemSet(&timeval, 0, sizeof(struct itimerval)); MemSet(&timeval, 0, sizeof(struct timeval));
timeval.it_value.tv_sec = \ timeval.tv_sec = \
(DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER); (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);
do do
{ {
int expire;
MyProc->errType = NO_ERROR; /* reset flag after deadlock check */ MyProc->errType = NO_ERROR; /* reset flag after deadlock check */
if (setitimer(ITIMER_REAL, &timeval, &dummy)) if ((expire = select(0, NULL, NULL, NULL,
(deadlock_checked == false) ? &timeval : NULL)) == -1)
elog(FATAL, "ProcSleep: Unable to set timer for process wakeup"); elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");
if (expire == 0 /* timeout reached */ && deadlock_checked == false)
{
HandleDeadLock();
deadlock_checked = true;
}
/* -------------- /* --------------
* if someone wakes us between SpinRelease and IpcSemaphoreLock, * if someone wakes us between SpinRelease and IpcSemaphoreLock,
* IpcSemaphoreLock will not block. The wakeup is "saved" by * IpcSemaphoreLock will not block. The wakeup is "saved" by
...@@ -545,14 +552,6 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */ ...@@ -545,14 +552,6 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
} while (MyProc->errType == STATUS_NOT_FOUND); /* sleep after deadlock } while (MyProc->errType == STATUS_NOT_FOUND); /* sleep after deadlock
* check */ * check */
/* ---------------
* We were awoken before a timeout - now disable the timer
* ---------------
*/
timeval.it_value.tv_sec = 0;
if (setitimer(ITIMER_REAL, &timeval, &dummy))
elog(FATAL, "ProcSleep: Unable to diable timer for process wakeup");
/* ---------------- /* ----------------
* We were assumed to be in a critical section when we went * We were assumed to be in a critical section when we went
* to sleep. * to sleep.
...@@ -695,7 +694,7 @@ ProcAddLock(SHM_QUEUE *elem) ...@@ -695,7 +694,7 @@ ProcAddLock(SHM_QUEUE *elem)
* -------------------- * --------------------
*/ */
static void static void
HandleDeadLock(int sig) HandleDeadLock()
{ {
LOCK *mywaitlock; LOCK *mywaitlock;
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/gram.c,v 1.1 1998/10/28 17:07:17 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/gram.c,v 1.2 1998/12/18 19:45:38 momjian Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
......
...@@ -635,7 +635,7 @@ char *yytext_ptr; ...@@ -635,7 +635,7 @@ char *yytext_ptr;
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.c,v 1.1 1998/10/28 17:07:17 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.c,v 1.2 1998/12/18 19:45:38 momjian Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment