sm6375-common: power-libperfmgr: Fix race condition between Looper and destructor

1. Clean all messages before add new.
2. Insteading of using `this`, use the unique mStaleHandler sp so Looper
   can hold the sp to keep the instance alive until the last message
   done.

Test: Manual Test
Bug: 219965773
Change-Id: Ic039146f0b966c1f27d86b121d4b72b75ff360e5
This commit is contained in:
Jimmy Shiu 2024-07-18 20:16:00 +05:30 committed by Anand S
commit e943cbd1a8
No known key found for this signature in database
GPG key ID: 3B2983FA448B3D61
2 changed files with 36 additions and 5 deletions

View file

@ -86,16 +86,21 @@ class PowerHintSession : public BnPowerHintSession {
class StaleHandler : public MessageHandler {
public:
StaleHandler(PowerHintSession *session)
: mSession(session), mIsMonitoringStale(false), mLastUpdatedTime(steady_clock::now()) {}
: mSession(session),
mIsMonitoringStale(false),
mLastUpdatedTime(steady_clock::now()),
mIsSessionDead(false) {}
void handleMessage(const Message &message) override;
void updateStaleTimer();
time_point<steady_clock> getStaleTime();
void setSessionDead();
private:
PowerHintSession *mSession;
std::atomic<bool> mIsMonitoringStale;
std::atomic<time_point<steady_clock>> mLastUpdatedTime;
std::mutex mStaleLock;
bool mIsSessionDead;
};
private: