Migrate from libutils SystemClock.h to std::chrono
Bug: 341997808
Test: mma
Change-Id: Ib4d60eeaaac73566cc79d473f6551e9abd20e69a
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index c3bbdba..61d0dba 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -25,7 +25,6 @@
#include <cutils/sched_policy.h>
#include <utils/CallStack.h>
#include <utils/Log.h>
-#include <utils/SystemClock.h>
#include <atomic>
#include <errno.h>
@@ -38,6 +37,7 @@
#include <sys/resource.h>
#include <unistd.h>
+#include "Utils.h"
#include "binder_module.h"
#if LOG_NDEBUG
@@ -65,6 +65,8 @@
namespace android {
+using namespace std::chrono_literals;
+
// Static const and functions will be optimized out if not used,
// when LOG_NDEBUG and references in IF_LOG_COMMANDS() are optimized out.
static const char* kReturnStrings[] = {
@@ -647,8 +649,9 @@
size_t newThreadsCount = mProcess->mExecutingThreadsCount.fetch_add(1) + 1;
if (newThreadsCount >= mProcess->mMaxThreads) {
- int64_t expected = 0;
- mProcess->mStarvationStartTimeMs.compare_exchange_strong(expected, uptimeMillis());
+ auto expected = ProcessState::never();
+ mProcess->mStarvationStartTime
+ .compare_exchange_strong(expected, std::chrono::steady_clock::now());
}
result = executeCommand(cmd);
@@ -656,12 +659,13 @@
size_t maxThreads = mProcess->mMaxThreads;
newThreadsCount = mProcess->mExecutingThreadsCount.fetch_sub(1) - 1;
if (newThreadsCount < maxThreads) {
- size_t starvationStartTimeMs = mProcess->mStarvationStartTimeMs.exchange(0);
- if (starvationStartTimeMs != 0) {
- int64_t starvationTimeMs = uptimeMillis() - starvationStartTimeMs;
- if (starvationTimeMs > 100) {
+ auto starvationStartTime =
+ mProcess->mStarvationStartTime.exchange(ProcessState::never());
+ if (starvationStartTime != ProcessState::never()) {
+ auto starvationTime = std::chrono::steady_clock::now() - starvationStartTime;
+ if (starvationTime > 100ms) {
ALOGE("binder thread pool (%zu threads) starved for %" PRId64 " ms", maxThreads,
- starvationTimeMs);
+ to_ms(starvationTime));
}
}
}