7
7
*
8
8
*
9
9
* 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 $
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.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 $
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 (int sig );
80
+ static void HandleDeadLock (void );
81
81
static PROC * ProcWakeup (PROC * proc , int errType );
82
82
83
83
#define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
@@ -154,8 +154,6 @@ InitProcess(IPCKey key)
154
154
* Routine called if deadlock timer goes off. See ProcSleep()
155
155
* ------------------
156
156
*/
157
- pqsignal (SIGALRM , HandleDeadLock );
158
-
159
157
SpinAcquire (ProcStructLock );
160
158
161
159
/* attach to the free list */
@@ -449,9 +447,9 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
449
447
TransactionId xid ) /* needed by user locks, see below */
450
448
{
451
449
int i ;
450
+ bool deadlock_checked = false;
452
451
PROC * proc ;
453
- struct itimerval timeval ,
454
- dummy ;
452
+ struct timeval timeval ;
455
453
456
454
/*
457
455
* If the first entries in the waitQueue have a greater priority than
@@ -523,17 +521,26 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
523
521
* to 0.
524
522
* --------------
525
523
*/
526
- MemSet (& timeval , 0 , sizeof (struct itimerval ));
527
- timeval .it_value . tv_sec = \
524
+ MemSet (& timeval , 0 , sizeof (struct timeval ));
525
+ timeval .tv_sec = \
528
526
(DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER );
529
527
530
528
do
531
529
{
530
+ int expire ;
531
+
532
532
MyProc -> errType = NO_ERROR ; /* reset flag after deadlock check */
533
533
534
- if (setitimer (ITIMER_REAL , & timeval , & dummy ))
534
+ if ((expire = select (0 , NULL , NULL , NULL ,
535
+ (deadlock_checked == false) ? & timeval : NULL )) == -1 )
535
536
elog (FATAL , "ProcSleep: Unable to set timer for process wakeup" );
536
537
538
+ if (expire == 0 /* timeout reached */ && deadlock_checked == false)
539
+ {
540
+ HandleDeadLock ();
541
+ deadlock_checked = true;
542
+ }
543
+
537
544
/* --------------
538
545
* if someone wakes us between SpinRelease and IpcSemaphoreLock,
539
546
* IpcSemaphoreLock will not block. The wakeup is "saved" by
@@ -545,14 +552,6 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
545
552
} while (MyProc -> errType == STATUS_NOT_FOUND ); /* sleep after deadlock
546
553
* check */
547
554
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
-
556
555
/* ----------------
557
556
* We were assumed to be in a critical section when we went
558
557
* to sleep.
@@ -695,7 +694,7 @@ ProcAddLock(SHM_QUEUE *elem)
695
694
* --------------------
696
695
*/
697
696
static void
698
- HandleDeadLock (int sig )
697
+ HandleDeadLock ()
699
698
{
700
699
LOCK * mywaitlock ;
701
700
0 commit comments