7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.46 1998/12/29 18:36:29 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.47 1998/12/29 19:32:08 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
46
46
* This is so that we can support more backends. (system-wide semaphore
47
47
* sets run out pretty fast.) -ay 4/95
48
48
*
49
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.46 1998/12/29 18:36:29 momjian Exp $
49
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.47 1998/12/29 19:32:08 momjian Exp $
50
50
*/
51
51
#include <sys/time.h>
52
52
#include <unistd.h>
77
77
#include "storage/proc.h"
78
78
#include "utils/trace.h"
79
79
80
- static void HandleDeadLock (void );
80
+ static void HandleDeadLock (int sig );
81
81
static PROC * ProcWakeup (PROC * proc , int errType );
82
82
83
83
#define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
@@ -154,6 +154,8 @@ InitProcess(IPCKey key)
154
154
* Routine called if deadlock timer goes off. See ProcSleep()
155
155
* ------------------
156
156
*/
157
+ pqsignal (SIGALRM , HandleDeadLock );
158
+
157
159
SpinAcquire (ProcStructLock );
158
160
159
161
/* attach to the free list */
@@ -447,8 +449,10 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
447
449
TransactionId xid ) /* needed by user locks, see below */
448
450
{
449
451
int i ;
450
- bool deadlock_checked = false;
451
452
PROC * proc ;
453
+ bool deadlock_checked = false;
454
+ struct itimerval timeval ,
455
+ dummy ;
452
456
453
457
/*
454
458
* If the first entries in the waitQueue have a greater priority than
@@ -512,28 +516,27 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
512
516
SpinRelease (spinlock );
513
517
514
518
/* --------------
515
- * We set this so we can wake up after one second to check for a deadlock.
519
+ * We set this so we can wake up periodically and check for a deadlock.
516
520
* If a deadlock is detected, the handler releases the processes
517
521
* semaphore and aborts the current transaction.
522
+ *
523
+ * Need to zero out struct to set the interval and the micro seconds fields
524
+ * to 0.
518
525
* --------------
519
526
*/
527
+ MemSet (& timeval , 0 , sizeof (struct itimerval ));
528
+ timeval .it_value .tv_sec = \
529
+ (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER );
520
530
521
531
do
522
532
{
523
533
MyProc -> errType = NO_ERROR ; /* reset flag after deadlock check */
524
534
525
- if (deadlock_checked == false)
526
- {
527
- if (sleep (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER )
528
- == 0 /* no signal interruption */ )
529
- {
530
- HandleDeadLock ();
531
- deadlock_checked = true;
532
- }
533
- }
534
- else
535
- pause ();
536
-
535
+ if (!deadlock_checked )
536
+ if (setitimer (ITIMER_REAL , & timeval , & dummy ))
537
+ elog (FATAL , "ProcSleep: Unable to set timer for process wakeup" );
538
+ deadlock_checked = true;
539
+
537
540
/* --------------
538
541
* if someone wakes us between SpinRelease and IpcSemaphoreLock,
539
542
* IpcSemaphoreLock will not block. The wakeup is "saved" by
@@ -545,6 +548,14 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
545
548
} while (MyProc -> errType == STATUS_NOT_FOUND ); /* sleep after deadlock
546
549
* check */
547
550
551
+ /* ---------------
552
+ * We were awoken before a timeout - now disable the timer
553
+ * ---------------
554
+ */
555
+ timeval .it_value .tv_sec = 0 ;
556
+ if (setitimer (ITIMER_REAL , & timeval , & dummy ))
557
+ elog (FATAL , "ProcSleep: Unable to diable timer for process wakeup" );
558
+
548
559
/* ----------------
549
560
* We were assumed to be in a critical section when we went
550
561
* to sleep.
@@ -687,7 +698,7 @@ ProcAddLock(SHM_QUEUE *elem)
687
698
* --------------------
688
699
*/
689
700
static void
690
- HandleDeadLock ()
701
+ HandleDeadLock (int sig )
691
702
{
692
703
LOCK * mywaitlock ;
693
704
0 commit comments