emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r115571: Fix minor problems in Windows emulation of


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r115571: Fix minor problems in Windows emulation of getloadavg.
Date: Tue, 17 Dec 2013 18:00:45 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115571
revision-id: address@hidden
parent: address@hidden
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Tue 2013-12-17 20:00:25 +0200
message:
  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.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/w32.c                      w32.c-20091113204419-o5vbwnq5f7feedwu-808
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-12-17 17:46:31 +0000
+++ b/src/ChangeLog     2013-12-17 18:00:25 +0000
@@ -1,5 +1,8 @@
 2013-12-17  Eli Zaretskii  <address@hidden>
 
+       * w32.c (getloadavg): Don't index samples[] array with negative
+       indices.  Recover from wall-clock time being set backwards.
+
        * w32term.c (w32_initialize): Declare the argument of
        set_user_model as const.
 

=== modified file 'src/w32.c'
--- a/src/w32.c 2013-12-14 08:29:42 +0000
+++ b/src/w32.c 2013-12-17 18:00:25 +0000
@@ -1732,9 +1732,28 @@
   ULONGLONG idle, kernel, user;
   time_t now = time (NULL);
 
+  /* If system time jumped back for some reason, delete all samples
+     whose time is later than the current wall-clock time.  This
+     prevents load average figures from becoming frozen for prolonged
+     periods of time, when system time is reset backwards.  */
+  if (last_idx >= 0)
+    {
+      while (difftime (now, samples[last_idx].sample_time) < -1.0)
+       {
+         if (last_idx == first_idx)
+           {
+             first_idx = last_idx = -1;
+             break;
+           }
+         last_idx = buf_prev (last_idx);
+       }
+    }
+
   /* Store another sample.  We ignore samples that are less than 1 sec
      apart.  */
-  if (difftime (now, samples[last_idx].sample_time) >= 1.0 - 2*DBL_EPSILON*now)
+  if (last_idx < 0
+      || (difftime (now, samples[last_idx].sample_time)
+         >= 1.0 - 2*DBL_EPSILON*now))
     {
       sample_system_load (&idle, &kernel, &user);
       last_idx = buf_next (last_idx);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]