Loading media/jni/soundpool/SoundPoolThread.cpp +19 −10 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include "SoundPoolThread.h" static const int kMaxWorkers = 3; namespace android { void SoundPoolThread::write(SoundPoolMsg msg) { Loading @@ -31,14 +33,21 @@ void SoundPoolThread::write(SoundPoolMsg msg) { // if thread is quitting, don't add to queue if (mRunning) { mMsgQueue.push(msg); mCondition.signal(); if (mNumWorkers < kMaxWorkers) { if (createThreadEtc(beginThread, this, "SoundPoolThread")) { mNumWorkers++; ALOGV("created worker thread"); } } } } const SoundPoolMsg SoundPoolThread::read() { Mutex::Autolock lock(&mLock); while (mMsgQueue.size() == 0) { mCondition.wait(mLock); if (mMsgQueue.size() == 0) { mNumWorkers--; mCondition.signal(); return SoundPoolMsg(SoundPoolMsg::KILL, 0); } SoundPoolMsg msg = mMsgQueue[0]; mMsgQueue.removeAt(0); Loading @@ -51,20 +60,20 @@ void SoundPoolThread::quit() { if (mRunning) { mRunning = false; mMsgQueue.clear(); mMsgQueue.push(SoundPoolMsg(SoundPoolMsg::KILL, 0)); mCondition.signal(); mCondition.broadcast(); // wake up any blocked writers while (mNumWorkers > 0) { mCondition.wait(mLock); } } ALOGV("return from quit"); } SoundPoolThread::SoundPoolThread(SoundPool* soundPool) : mSoundPool(soundPool) mSoundPool(soundPool), mNumWorkers(0), mRunning(true) { mMsgQueue.setCapacity(maxMessages); if (createThreadEtc(beginThread, this, "SoundPoolThread")) { mRunning = true; } } SoundPoolThread::~SoundPoolThread() Loading media/jni/soundpool/SoundPoolThread.h +1 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ private: Condition mCondition; Vector<SoundPoolMsg> mMsgQueue; SoundPool* mSoundPool; int32_t mNumWorkers; bool mRunning; }; Loading Loading
media/jni/soundpool/SoundPoolThread.cpp +19 −10 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include "SoundPoolThread.h" static const int kMaxWorkers = 3; namespace android { void SoundPoolThread::write(SoundPoolMsg msg) { Loading @@ -31,14 +33,21 @@ void SoundPoolThread::write(SoundPoolMsg msg) { // if thread is quitting, don't add to queue if (mRunning) { mMsgQueue.push(msg); mCondition.signal(); if (mNumWorkers < kMaxWorkers) { if (createThreadEtc(beginThread, this, "SoundPoolThread")) { mNumWorkers++; ALOGV("created worker thread"); } } } } const SoundPoolMsg SoundPoolThread::read() { Mutex::Autolock lock(&mLock); while (mMsgQueue.size() == 0) { mCondition.wait(mLock); if (mMsgQueue.size() == 0) { mNumWorkers--; mCondition.signal(); return SoundPoolMsg(SoundPoolMsg::KILL, 0); } SoundPoolMsg msg = mMsgQueue[0]; mMsgQueue.removeAt(0); Loading @@ -51,20 +60,20 @@ void SoundPoolThread::quit() { if (mRunning) { mRunning = false; mMsgQueue.clear(); mMsgQueue.push(SoundPoolMsg(SoundPoolMsg::KILL, 0)); mCondition.signal(); mCondition.broadcast(); // wake up any blocked writers while (mNumWorkers > 0) { mCondition.wait(mLock); } } ALOGV("return from quit"); } SoundPoolThread::SoundPoolThread(SoundPool* soundPool) : mSoundPool(soundPool) mSoundPool(soundPool), mNumWorkers(0), mRunning(true) { mMsgQueue.setCapacity(maxMessages); if (createThreadEtc(beginThread, this, "SoundPoolThread")) { mRunning = true; } } SoundPoolThread::~SoundPoolThread() Loading
media/jni/soundpool/SoundPoolThread.h +1 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ private: Condition mCondition; Vector<SoundPoolMsg> mMsgQueue; SoundPool* mSoundPool; int32_t mNumWorkers; bool mRunning; }; Loading