ADPF: avoid to call close() twice
To get rid of error logs, avoid to call close() twice.
07-29 17:20:35.341 E powerhal-libperfmgr: Unexpected Error! Failed to
look up tid:2585 in TidRefCountMap
07-29 17:20:35.341 E powerhal-libperfmgr: Unexpected Error! Failed to
look up tid:2586 in TidRefCountMap
07-29 17:20:35.341 E powerhal-libperfmgr: Unexpected Error! Failed to
look up tid:2031 in TidRefCountMap
07-29 17:20:35.341 E powerhal-libperfmgr: Unexpected Error! Failed to
look up tid:2585 in TidRefCountMap
Bug: 194775170
Test: build and check log.
Change-Id: I91adf907b837382f68935b9054e19465a499049c
diff --git a/aidl/power-libperfmgr/PowerHintSession.cpp b/aidl/power-libperfmgr/PowerHintSession.cpp
index 053aeda..e76d828 100644
--- a/aidl/power-libperfmgr/PowerHintSession.cpp
+++ b/aidl/power-libperfmgr/PowerHintSession.cpp
@@ -24,6 +24,7 @@
#include <sys/syscall.h>
#include <time.h>
#include <utils/Trace.h>
+#include <atomic>
#include "PowerHintSession.h"
#include "PowerSessionManager.h"
@@ -238,8 +239,11 @@
}
ndk::ScopedAStatus PowerHintSession::close() {
+ bool sessionClosedExpectedToBe = false;
+ if (!mSessionClosed.compare_exchange_strong(sessionClosedExpectedToBe, true)) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
+ }
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mStaleHandler);
- // Reset to (0, 1024) uclamp value -- instead of threads' original setting.
setUclamp(0);
PowerSessionManager::getInstance()->removePowerSession(this);
updateUniveralBoostMode();
diff --git a/aidl/power-libperfmgr/PowerHintSession.h b/aidl/power-libperfmgr/PowerHintSession.h
index 6ad2652..e3c0f84 100644
--- a/aidl/power-libperfmgr/PowerHintSession.h
+++ b/aidl/power-libperfmgr/PowerHintSession.h
@@ -108,6 +108,7 @@
sp<MessageHandler> mPowerManagerHandler;
std::mutex mLock;
const nanoseconds kAdpfRate;
+ std::atomic<bool> mSessionClosed = false;
};
} // namespace pixel