aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2013-12-17 20:00:25 +0200
committerEli Zaretskii2013-12-17 20:00:25 +0200
commit60e62dc596e0603397c416cd82c4d4512565fa38 (patch)
tree409bbd56b53c324e27159861a0f65d5f4a084b5a
parentaf025ae850c8f30431cf79876c4452d9f1679250 (diff)
downloademacs-60e62dc596e0603397c416cd82c4d4512565fa38.tar.gz
emacs-60e62dc596e0603397c416cd82c4d4512565fa38.zip
Fix minor problems in Windows emulation of getloadavg.
src/w32.c (getloadavg): Don't index samples[] array with negative indices. Recover from wall-clock time being set backwards.
-rw-r--r--src/ChangeLog3
-rw-r--r--src/w32.c21
2 files changed, 23 insertions, 1 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index aaa8788c2ba..0fe25e6fd63 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,8 @@
12013-12-17 Eli Zaretskii <eliz@gnu.org> 12013-12-17 Eli Zaretskii <eliz@gnu.org>
2 2
3 * w32.c (getloadavg): Don't index samples[] array with negative
4 indices. Recover from wall-clock time being set backwards.
5
3 * w32term.c (w32_initialize): Declare the argument of 6 * w32term.c (w32_initialize): Declare the argument of
4 set_user_model as const. 7 set_user_model as const.
5 8
diff --git a/src/w32.c b/src/w32.c
index e4678637cbb..159085e7f50 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1732,9 +1732,28 @@ getloadavg (double loadavg[], int nelem)
1732 ULONGLONG idle, kernel, user; 1732 ULONGLONG idle, kernel, user;
1733 time_t now = time (NULL); 1733 time_t now = time (NULL);
1734 1734
1735 /* If system time jumped back for some reason, delete all samples
1736 whose time is later than the current wall-clock time. This
1737 prevents load average figures from becoming frozen for prolonged
1738 periods of time, when system time is reset backwards. */
1739 if (last_idx >= 0)
1740 {
1741 while (difftime (now, samples[last_idx].sample_time) < -1.0)
1742 {
1743 if (last_idx == first_idx)
1744 {
1745 first_idx = last_idx = -1;
1746 break;
1747 }
1748 last_idx = buf_prev (last_idx);
1749 }
1750 }
1751
1735 /* Store another sample. We ignore samples that are less than 1 sec 1752 /* Store another sample. We ignore samples that are less than 1 sec
1736 apart. */ 1753 apart. */
1737 if (difftime (now, samples[last_idx].sample_time) >= 1.0 - 2*DBL_EPSILON*now) 1754 if (last_idx < 0
1755 || (difftime (now, samples[last_idx].sample_time)
1756 >= 1.0 - 2*DBL_EPSILON*now))
1738 { 1757 {
1739 sample_system_load (&idle, &kernel, &user); 1758 sample_system_load (&idle, &kernel, &user);
1740 last_idx = buf_next (last_idx); 1759 last_idx = buf_next (last_idx);