OSDN Git Service

libperfmgr: Change NodeLooperThread thread wait time
authorWei Wang <wvw@google.com>
Tue, 2 Jan 2018 06:23:52 +0000 (22:23 -0800)
committerWei Wang <wvw@google.com>
Mon, 15 Jan 2018 17:23:31 +0000 (09:23 -0800)
Test: libperfmgr_test
Change-Id: I4c52a675c919c6100500bf1aa2ca8ecd10c2bbcb

libperfmgr/NodeLooperThread.cc
libperfmgr/include/perfmgr/NodeLooperThread.h

index da7aa65..cb2ea18 100644 (file)
@@ -95,9 +95,11 @@ bool NodeLooperThread::threadLoop() {
         auto t = n->Update();
         timeout_ms = std::min(t, timeout_ms);
     }
-    // For unsigned types, convert to float to avoid wrap around
-    nsecs_t sleep_timeout_ns =
-        static_cast<nsecs_t>(timeout_ms.count() * 1000.0f * 1000.0f);
+
+    nsecs_t sleep_timeout_ns = std::numeric_limits<nsecs_t>::max();
+    if (timeout_ms.count() < sleep_timeout_ns / 1000 / 1000) {
+        sleep_timeout_ns = timeout_ms.count() * 1000 * 1000;
+    }
     // VERBOSE level won't print by default in user/userdebug build
     LOG(VERBOSE) << "NodeLooperThread will wait for " << sleep_timeout_ns
                  << "ns";
index 5da0987..e8151c8 100644 (file)
@@ -77,11 +77,7 @@ class NodeLooperThread : public ::android::Thread {
     bool threadLoop() override;
     void onFirstRef() override;
 
-    // std::chrono::milliseconds::max() is too long
-    // maintain the list every 60 seconds as the overhead
-    // to loop is not too much if nothing changes
-    static constexpr auto kMaxUpdatePeriod =
-        std::chrono::milliseconds(60 * 1000);
+    static constexpr auto kMaxUpdatePeriod = std::chrono::milliseconds::max();
 
     std::vector<std::unique_ptr<Node>> nodes_;  // parsed from Config