OSDN Git Service

Only log excessive timeouts if those appear accidental
authorHans Boehm <hboehm@google.com>
Mon, 28 Mar 2016 21:36:23 +0000 (14:36 -0700)
committerHans Boehm <hboehm@google.com>
Tue, 29 Mar 2016 06:01:16 +0000 (23:01 -0700)
Do not generate a log message even when timeout would cause us to wake
up past the end of Linux time, if the timeout specification looks like
it was meant to wait forever.  Avoids log spam.

Bug: 27723547
Change-Id: I98d0fc1b1813a10ad906282957675b85bd933472

runtime/base/time_utils.cc

index b7cf207..3e5bac8 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <inttypes.h>
+#include <limits>
 #include <sstream>
 
 #include "time_utils.h"
@@ -190,9 +191,16 @@ void InitTimeSpec(bool absolute, int clock, int64_t ms, int32_t ns, timespec* ts
   }
 
   int64_t end_sec = ts->tv_sec + ms / 1000;
-  if (UNLIKELY(end_sec >= 0x7fffffff)) {
-    LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
-    end_sec = 0x7ffffffe;
+  constexpr int32_t int32_max = std::numeric_limits<int32_t>::max();
+  if (UNLIKELY(end_sec >= int32_max)) {
+    // Either ms was intended to denote an infinite timeout, or we have a
+    // problem. The former generally uses the largest possible millisecond
+    // or nanosecond value.  Log only in the latter case.
+    constexpr int64_t int64_max = std::numeric_limits<int64_t>::max();
+    if (ms != int64_max && ms != int64_max / (1000 * 1000)) {
+      LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
+    }
+    end_sec = int32_max - 1;  // Allow for increment below.
   }
   ts->tv_sec = end_sec;
   ts->tv_nsec = (ts->tv_nsec + (ms % 1000) * 1000000) + ns;