8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.107 2001/09/07 00:27:29 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.108 2001/09/21 17:06:12 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -327,18 +327,7 @@ LockWaitCancel(void)
327
327
waitingForLock = false;
328
328
329
329
/* Turn off the deadlock timer, if it's still running (see ProcSleep) */
330
- #ifndef __BEOS__
331
- {
332
- struct itimerval timeval ,
333
- dummy ;
334
-
335
- MemSet (& timeval , 0 , sizeof (struct itimerval ));
336
- setitimer (ITIMER_REAL , & timeval , & dummy );
337
- }
338
- #else
339
- /* BeOS doesn't have setitimer, but has set_alarm */
340
- set_alarm (B_INFINITE_TIMEOUT , B_PERIODIC_ALARM );
341
- #endif /* __BEOS__ */
330
+ disable_sigalrm_interrupt ();
342
331
343
332
/* Unlink myself from the wait queue, if on it (might not be anymore!) */
344
333
LockLockTable ();
@@ -501,12 +490,6 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
501
490
bool early_deadlock = false;
502
491
PROC * proc ;
503
492
int i ;
504
- #ifndef __BEOS__
505
- struct itimerval timeval ,
506
- dummy ;
507
- #else
508
- bigtime_t time_interval ;
509
- #endif
510
493
511
494
/*
512
495
* Determine where to add myself in the wait queue.
@@ -629,21 +612,9 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
629
612
*
630
613
* By delaying the check until we've waited for a bit, we can avoid
631
614
* running the rather expensive deadlock-check code in most cases.
632
- *
633
- * Need to zero out struct to set the interval and the microseconds
634
- * fields to 0.
635
615
*/
636
- #ifndef __BEOS__
637
- MemSet (& timeval , 0 , sizeof (struct itimerval ));
638
- timeval .it_value .tv_sec = DeadlockTimeout / 1000 ;
639
- timeval .it_value .tv_usec = (DeadlockTimeout % 1000 ) * 1000 ;
640
- if (setitimer (ITIMER_REAL , & timeval , & dummy ))
616
+ if (! enable_sigalrm_interrupt (DeadlockTimeout ))
641
617
elog (FATAL , "ProcSleep: Unable to set timer for process wakeup" );
642
- #else
643
- time_interval = DeadlockTimeout * 1000000 ; /* usecs */
644
- if (set_alarm (time_interval , B_ONE_SHOT_RELATIVE_ALARM ) < 0 )
645
- elog (FATAL , "ProcSleep: Unable to set timer for process wakeup" );
646
- #endif
647
618
648
619
/*
649
620
* If someone wakes us between SpinRelease and IpcSemaphoreLock,
@@ -664,14 +635,8 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
664
635
/*
665
636
* Disable the timer, if it's still running
666
637
*/
667
- #ifndef __BEOS__
668
- MemSet (& timeval , 0 , sizeof (struct itimerval ));
669
- if (setitimer (ITIMER_REAL , & timeval , & dummy ))
670
- elog (FATAL , "ProcSleep: Unable to disable timer for process wakeup" );
671
- #else
672
- if (set_alarm (B_INFINITE_TIMEOUT , B_PERIODIC_ALARM ) < 0 )
638
+ if (! disable_sigalrm_interrupt ())
673
639
elog (FATAL , "ProcSleep: Unable to disable timer for process wakeup" );
674
- #endif
675
640
676
641
/*
677
642
* Now there is nothing for LockWaitCancel to do.
@@ -949,6 +914,69 @@ ProcSendSignal(BackendId procId)
949
914
}
950
915
951
916
917
+ /*****************************************************************************
918
+ * SIGALRM interrupt support
919
+ *
920
+ * Maybe these should be in pqsignal.c?
921
+ *****************************************************************************/
922
+
923
+ /*
924
+ * Enable the SIGALRM interrupt to fire after the specified delay
925
+ *
926
+ * Delay is given in milliseconds. Caller should be sure a SIGALRM
927
+ * signal handler is installed before this is called.
928
+ *
929
+ * Returns TRUE if okay, FALSE on failure.
930
+ */
931
+ bool
932
+ enable_sigalrm_interrupt (int delayms )
933
+ {
934
+ #ifndef __BEOS__
935
+ struct itimerval timeval ,
936
+ dummy ;
937
+
938
+ MemSet (& timeval , 0 , sizeof (struct itimerval ));
939
+ timeval .it_value .tv_sec = delayms / 1000 ;
940
+ timeval .it_value .tv_usec = (delayms % 1000 ) * 1000 ;
941
+ if (setitimer (ITIMER_REAL , & timeval , & dummy ))
942
+ return false;
943
+ #else
944
+ /* BeOS doesn't have setitimer, but has set_alarm */
945
+ bigtime_t time_interval ;
946
+
947
+ time_interval = delayms * 1000 ; /* usecs */
948
+ if (set_alarm (time_interval , B_ONE_SHOT_RELATIVE_ALARM ) < 0 )
949
+ return false;
950
+ #endif
951
+
952
+ return true;
953
+ }
954
+
955
+ /*
956
+ * Disable the SIGALRM interrupt, if it has not yet fired
957
+ *
958
+ * Returns TRUE if okay, FALSE on failure.
959
+ */
960
+ bool
961
+ disable_sigalrm_interrupt (void )
962
+ {
963
+ #ifndef __BEOS__
964
+ struct itimerval timeval ,
965
+ dummy ;
966
+
967
+ MemSet (& timeval , 0 , sizeof (struct itimerval ));
968
+ if (setitimer (ITIMER_REAL , & timeval , & dummy ))
969
+ return false;
970
+ #else
971
+ /* BeOS doesn't have setitimer, but has set_alarm */
972
+ if (set_alarm (B_INFINITE_TIMEOUT , B_PERIODIC_ALARM ) < 0 )
973
+ return false;
974
+ #endif
975
+
976
+ return true;
977
+ }
978
+
979
+
952
980
/*****************************************************************************
953
981
*
954
982
*****************************************************************************/
0 commit comments