@@ -1586,16 +1586,16 @@ checkControlFile(void)
1586
1586
}
1587
1587
1588
1588
/*
1589
- * Determine how long should we let ServerLoop sleep.
1589
+ * Determine how long should we let ServerLoop sleep, in milliseconds .
1590
1590
*
1591
1591
* In normal conditions we wait at most one minute, to ensure that the other
1592
1592
* background tasks handled by ServerLoop get done even when no requests are
1593
1593
* arriving. However, if there are background workers waiting to be started,
1594
1594
* we don't actually sleep so that they are quickly serviced. Other exception
1595
1595
* cases are as shown in the code.
1596
1596
*/
1597
- static void
1598
- DetermineSleepTime (struct timeval * timeout )
1597
+ static int
1598
+ DetermineSleepTime (void )
1599
1599
{
1600
1600
TimestampTz next_wakeup = 0 ;
1601
1601
@@ -1608,26 +1608,20 @@ DetermineSleepTime(struct timeval *timeout)
1608
1608
{
1609
1609
if (AbortStartTime != 0 )
1610
1610
{
1611
+ int seconds ;
1612
+
1611
1613
/* time left to abort; clamp to 0 in case it already expired */
1612
- timeout -> tv_sec = SIGKILL_CHILDREN_AFTER_SECS -
1614
+ seconds = SIGKILL_CHILDREN_AFTER_SECS -
1613
1615
(time (NULL ) - AbortStartTime );
1614
- timeout -> tv_sec = Max ( timeout -> tv_sec , 0 );
1615
- timeout -> tv_usec = 0 ;
1616
+
1617
+ return Max ( seconds * 1000 , 0 ) ;
1616
1618
}
1617
1619
else
1618
- {
1619
- timeout -> tv_sec = 60 ;
1620
- timeout -> tv_usec = 0 ;
1621
- }
1622
- return ;
1620
+ return 60 * 1000 ;
1623
1621
}
1624
1622
1625
1623
if (StartWorkerNeeded )
1626
- {
1627
- timeout -> tv_sec = 0 ;
1628
- timeout -> tv_usec = 0 ;
1629
- return ;
1630
- }
1624
+ return 0 ;
1631
1625
1632
1626
if (HaveCrashedWorker )
1633
1627
{
@@ -1665,26 +1659,14 @@ DetermineSleepTime(struct timeval *timeout)
1665
1659
1666
1660
if (next_wakeup != 0 )
1667
1661
{
1668
- long secs ;
1669
- int microsecs ;
1670
-
1671
- TimestampDifference (GetCurrentTimestamp (), next_wakeup ,
1672
- & secs , & microsecs );
1673
- timeout -> tv_sec = secs ;
1674
- timeout -> tv_usec = microsecs ;
1675
-
1676
- /* Ensure we don't exceed one minute */
1677
- if (timeout -> tv_sec > 60 )
1678
- {
1679
- timeout -> tv_sec = 60 ;
1680
- timeout -> tv_usec = 0 ;
1681
- }
1682
- }
1683
- else
1684
- {
1685
- timeout -> tv_sec = 60 ;
1686
- timeout -> tv_usec = 0 ;
1662
+ /* Ensure we don't exceed one minute, or go under 0. */
1663
+ return Max (0 ,
1664
+ Min (60 * 1000 ,
1665
+ TimestampDifferenceMilliseconds (GetCurrentTimestamp (),
1666
+ next_wakeup )));
1687
1667
}
1668
+
1669
+ return 60 * 1000 ;
1688
1670
}
1689
1671
1690
1672
/*
@@ -1743,12 +1725,9 @@ ServerLoop(void)
1743
1725
for (;;)
1744
1726
{
1745
1727
time_t now ;
1746
- struct timeval timeout ;
1747
-
1748
- DetermineSleepTime (& timeout );
1749
1728
1750
1729
nevents = WaitEventSetWait (pm_wait_set ,
1751
- timeout . tv_sec * 1000 + timeout . tv_usec / 1000 ,
1730
+ DetermineSleepTime () ,
1752
1731
events ,
1753
1732
lengthof (events ),
1754
1733
0 /* postmaster posts no wait_events */ );
0 commit comments