summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lais Andrade <lsandrade@google.com> 2024-04-26 15:07:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-04-26 15:07:19 +0000
commit04eded00df2a07e20c815cbb5f17c41d33a91a89 (patch)
treeb737dc7fe0f343a22a30835dfa92e707c32d4dbe
parent39fe0cd400d7da816e544dff16a8791d95d89cee (diff)
parentc8069856c3bd0286986651fc5a8e58dbfcc3e7f5 (diff)
Merge "Fix VibratorCallbackScheduler destructor lock" into main
-rw-r--r--services/vibratorservice/VibratorCallbackScheduler.cpp8
-rw-r--r--services/vibratorservice/test/test_utils.h8
2 files changed, 9 insertions, 7 deletions
diff --git a/services/vibratorservice/VibratorCallbackScheduler.cpp b/services/vibratorservice/VibratorCallbackScheduler.cpp
index 7eda9ef0c7..b2b1988d97 100644
--- a/services/vibratorservice/VibratorCallbackScheduler.cpp
+++ b/services/vibratorservice/VibratorCallbackScheduler.cpp
@@ -87,13 +87,13 @@ void CallbackScheduler::loop() {
lock.lock();
}
if (mQueue.empty()) {
- // Wait until a new callback is scheduled.
- mCondition.wait(mMutex);
+ // Wait until a new callback is scheduled or destructor was called.
+ mCondition.wait(lock, [this] { return mFinished || !mQueue.empty(); });
} else {
- // Wait until next callback expires, or a new one is scheduled.
+ // Wait until next callback expires or a new one is scheduled.
// Use the monotonic steady clock to wait for the measured delay interval via wait_for
// instead of using a wall clock via wait_until.
- mCondition.wait_for(mMutex, mQueue.top().getWaitForExpirationDuration());
+ mCondition.wait_for(lock, mQueue.top().getWaitForExpirationDuration());
}
}
}
diff --git a/services/vibratorservice/test/test_utils.h b/services/vibratorservice/test/test_utils.h
index bf13aa7487..715c2215c4 100644
--- a/services/vibratorservice/test/test_utils.h
+++ b/services/vibratorservice/test/test_utils.h
@@ -90,13 +90,15 @@ public:
TestCounter(int32_t init = 0) : mMutex(), mCondVar(), mCount(init) {}
int32_t get() {
- std::unique_lock<std::mutex> lock(mMutex);
+ std::lock_guard<std::mutex> lock(mMutex);
return mCount;
}
void increment() {
- std::unique_lock<std::mutex> lock(mMutex);
- mCount += 1;
+ {
+ std::lock_guard<std::mutex> lock(mMutex);
+ mCount += 1;
+ }
mCondVar.notify_all();
}