diff options
| author | 2017-06-21 19:29:04 +0000 | |
|---|---|---|
| committer | 2017-06-21 19:30:17 +0000 | |
| commit | beea9f7636a6b8793beea09996f9d1f61b903f7e (patch) | |
| tree | 2a3f0e5099fb01c55f212185359f581721730766 | |
| parent | 3a18b28ab0cf14e5730aa4d8ad2494e2844a81c3 (diff) | |
Revert "Multiple worker threads for SoundPool"
This reverts commit 7201d9cb6a5d9bcd4f82dfde32e25a1ca8e825e2.
This reduces CPU usage during Camera startup.
Bug: 38031165
Bug: 62447848
Change-Id: I857aefec9dd7566bfdd3b84873eb5d495449815c
| -rw-r--r-- | media/jni/soundpool/SoundPoolThread.cpp | 29 | ||||
| -rw-r--r-- | media/jni/soundpool/SoundPoolThread.h | 1 |
2 files changed, 10 insertions, 20 deletions
diff --git a/media/jni/soundpool/SoundPoolThread.cpp b/media/jni/soundpool/SoundPoolThread.cpp index 3d988773ff04..ba3b482935dd 100644 --- a/media/jni/soundpool/SoundPoolThread.cpp +++ b/media/jni/soundpool/SoundPoolThread.cpp @@ -20,8 +20,6 @@ #include "SoundPoolThread.h" -static const int kMaxWorkers = 3; - namespace android { void SoundPoolThread::write(SoundPoolMsg msg) { @@ -33,21 +31,14 @@ void SoundPoolThread::write(SoundPoolMsg msg) { // if thread is quitting, don't add to queue if (mRunning) { mMsgQueue.push(msg); - if (mNumWorkers < kMaxWorkers) { - if (createThreadEtc(beginThread, this, "SoundPoolThread")) { - mNumWorkers++; - ALOGV("created worker thread"); - } - } + mCondition.signal(); } } const SoundPoolMsg SoundPoolThread::read() { Mutex::Autolock lock(&mLock); - if (mMsgQueue.size() == 0) { - mNumWorkers--; - mCondition.signal(); - return SoundPoolMsg(SoundPoolMsg::KILL, 0); + while (mMsgQueue.size() == 0) { + mCondition.wait(mLock); } SoundPoolMsg msg = mMsgQueue[0]; mMsgQueue.removeAt(0); @@ -60,20 +51,20 @@ void SoundPoolThread::quit() { if (mRunning) { mRunning = false; mMsgQueue.clear(); - mCondition.broadcast(); // wake up any blocked writers - while (mNumWorkers > 0) { - mCondition.wait(mLock); - } + mMsgQueue.push(SoundPoolMsg(SoundPoolMsg::KILL, 0)); + mCondition.signal(); + mCondition.wait(mLock); } ALOGV("return from quit"); } SoundPoolThread::SoundPoolThread(SoundPool* soundPool) : - mSoundPool(soundPool), - mNumWorkers(0), - mRunning(true) + mSoundPool(soundPool) { mMsgQueue.setCapacity(maxMessages); + if (createThreadEtc(beginThread, this, "SoundPoolThread")) { + mRunning = true; + } } SoundPoolThread::~SoundPoolThread() diff --git a/media/jni/soundpool/SoundPoolThread.h b/media/jni/soundpool/SoundPoolThread.h index 5d7bf0c07803..7b3e1dda0a23 100644 --- a/media/jni/soundpool/SoundPoolThread.h +++ b/media/jni/soundpool/SoundPoolThread.h @@ -58,7 +58,6 @@ private: Condition mCondition; Vector<SoundPoolMsg> mMsgQueue; SoundPool* mSoundPool; - int32_t mNumWorkers; bool mRunning; }; |