Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3cd3be9

Browse files
committed
Fix deadlock so it only checks once.
1 parent bb76dd8 commit 3cd3be9

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

src/backend/parser/scan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* A lexical scanner generated by flex */
22

33
/* Scanner skeleton version:
4-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.31 1998/10/13 17:26:50 scrappy Exp $
4+
* /master/usr.bin/lex/skel.c,v 1.3 1997/09/25 00:10:23 jch Exp
55
*/
66

77
#define FLEX_SCANNER
@@ -556,7 +556,7 @@ char *yytext;
556556
*
557557
*
558558
* IDENTIFICATION
559-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.31 1998/10/13 17:26:50 scrappy Exp $
559+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.32 1998/12/18 19:45:36 momjian Exp $
560560
*
561561
*-------------------------------------------------------------------------
562562
*/

src/backend/storage/lmgr/proc.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.43 1998/09/01 04:32:02 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.44 1998/12/18 19:45:37 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -46,7 +46,7 @@
4646
* This is so that we can support more backends. (system-wide semaphore
4747
* sets run out pretty fast.) -ay 4/95
4848
*
49-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.43 1998/09/01 04:32:02 momjian Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.44 1998/12/18 19:45:37 momjian Exp $
5050
*/
5151
#include <sys/time.h>
5252
#include <unistd.h>
@@ -77,7 +77,7 @@
7777
#include "storage/proc.h"
7878
#include "utils/trace.h"
7979

80-
static void HandleDeadLock(int sig);
80+
static void HandleDeadLock(void);
8181
static PROC *ProcWakeup(PROC *proc, int errType);
8282

8383
#define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
@@ -154,8 +154,6 @@ InitProcess(IPCKey key)
154154
* Routine called if deadlock timer goes off. See ProcSleep()
155155
* ------------------
156156
*/
157-
pqsignal(SIGALRM, HandleDeadLock);
158-
159157
SpinAcquire(ProcStructLock);
160158

161159
/* attach to the free list */
@@ -449,9 +447,9 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
449447
TransactionId xid) /* needed by user locks, see below */
450448
{
451449
int i;
450+
bool deadlock_checked = false;
452451
PROC *proc;
453-
struct itimerval timeval,
454-
dummy;
452+
struct timeval timeval;
455453

456454
/*
457455
* If the first entries in the waitQueue have a greater priority than
@@ -523,17 +521,26 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
523521
* to 0.
524522
* --------------
525523
*/
526-
MemSet(&timeval, 0, sizeof(struct itimerval));
527-
timeval.it_value.tv_sec = \
524+
MemSet(&timeval, 0, sizeof(struct timeval));
525+
timeval.tv_sec = \
528526
(DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);
529527

530528
do
531529
{
530+
int expire;
531+
532532
MyProc->errType = NO_ERROR; /* reset flag after deadlock check */
533533

534-
if (setitimer(ITIMER_REAL, &timeval, &dummy))
534+
if ((expire = select(0, NULL, NULL, NULL,
535+
(deadlock_checked == false) ? &timeval : NULL)) == -1)
535536
elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");
536537

538+
if (expire == 0 /* timeout reached */ && deadlock_checked == false)
539+
{
540+
HandleDeadLock();
541+
deadlock_checked = true;
542+
}
543+
537544
/* --------------
538545
* if someone wakes us between SpinRelease and IpcSemaphoreLock,
539546
* IpcSemaphoreLock will not block. The wakeup is "saved" by
@@ -545,14 +552,6 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
545552
} while (MyProc->errType == STATUS_NOT_FOUND); /* sleep after deadlock
546553
* check */
547554

548-
/* ---------------
549-
* We were awoken before a timeout - now disable the timer
550-
* ---------------
551-
*/
552-
timeval.it_value.tv_sec = 0;
553-
if (setitimer(ITIMER_REAL, &timeval, &dummy))
554-
elog(FATAL, "ProcSleep: Unable to diable timer for process wakeup");
555-
556555
/* ----------------
557556
* We were assumed to be in a critical section when we went
558557
* to sleep.
@@ -695,7 +694,7 @@ ProcAddLock(SHM_QUEUE *elem)
695694
* --------------------
696695
*/
697696
static void
698-
HandleDeadLock(int sig)
697+
HandleDeadLock()
699698
{
700699
LOCK *mywaitlock;
701700

src/pl/plpgsql/src/gram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
* procedural language
6666
*
6767
* IDENTIFICATION
68-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/gram.c,v 1.1 1998/10/28 17:07:17 momjian Exp $
68+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/gram.c,v 1.2 1998/12/18 19:45:38 momjian Exp $
6969
*
7070
* This software is copyrighted by Jan Wieck - Hamburg.
7171
*

src/pl/plpgsql/src/scan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ char *yytext_ptr;
635635
* procedural language
636636
*
637637
* IDENTIFICATION
638-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.c,v 1.1 1998/10/28 17:07:17 momjian Exp $
638+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.c,v 1.2 1998/12/18 19:45:38 momjian Exp $
639639
*
640640
* This software is copyrighted by Jan Wieck - Hamburg.
641641
*

0 commit comments

Comments
 (0)