Add sleep in EffectThread to avoid busy wait
Bug: 261129656
Test: Enable AIDL and run YTM on pixel phone
Change-Id: If7ea5324b8a884e8f07b6855b70cb33b4c7868e4
diff --git a/audio/aidl/default/include/effect-impl/EffectThread.h b/audio/aidl/default/include/effect-impl/EffectThread.h
index 9b1a75b..f9c6a31 100644
--- a/audio/aidl/default/include/effect-impl/EffectThread.h
+++ b/audio/aidl/default/include/effect-impl/EffectThread.h
@@ -35,7 +35,7 @@
// called by effect implementation.
RetCode createThread(std::shared_ptr<EffectContext> context, const std::string& name,
- const int priority = ANDROID_PRIORITY_URGENT_AUDIO);
+ int priority = ANDROID_PRIORITY_URGENT_AUDIO, int sleepUs = kSleepTimeUs);
RetCode destroyThread();
RetCode startThread();
RetCode stopThread();
@@ -72,7 +72,8 @@
virtual void process_l() REQUIRES(mThreadMutex);
private:
- const int kMaxTaskNameLen = 15;
+ static constexpr int kMaxTaskNameLen = 15;
+ static constexpr int kSleepTimeUs = 2000; // in micro-second
std::mutex mThreadMutex;
std::condition_variable mCv;
bool mExit GUARDED_BY(mThreadMutex) = false;
@@ -80,6 +81,7 @@
std::shared_ptr<EffectContext> mThreadContext GUARDED_BY(mThreadMutex);
std::thread mThread;
int mPriority;
+ int mSleepTimeUs = kSleepTimeUs; // sleep time in micro-second
std::string mName;
RetCode handleStartStop(bool stop);