Loading media/jni/soundpool/SoundDecoder.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -29,14 +29,15 @@ static constexpr size_t kMaxQueueSize = 128; // before the SoundDecoder thread closes. static constexpr int32_t kWaitTimeBeforeCloseMs = 1000; SoundDecoder::SoundDecoder(SoundManager* soundManager, size_t threads) SoundDecoder::SoundDecoder(SoundManager* soundManager, size_t threads, int32_t threadPriority) : mSoundManager(soundManager) { ALOGV("%s(%p, %zu)", __func__, soundManager, threads); // ThreadPool is created, but we don't launch any threads. mThreadPool = std::make_unique<ThreadPool>( std::min(threads, (size_t)std::thread::hardware_concurrency()), "SoundDecoder_"); "SoundDecoder_", threadPriority); } SoundDecoder::~SoundDecoder() Loading media/jni/soundpool/SoundDecoder.h +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ namespace android::soundpool { */ class SoundDecoder { public: SoundDecoder(SoundManager* soundManager, size_t threads); SoundDecoder(SoundManager* soundManager, size_t threads, int32_t threadPriority); ~SoundDecoder(); void loadSound(int32_t soundID) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock void quit(); Loading media/jni/soundpool/SoundManager.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ namespace android::soundpool { static const size_t kDecoderThreads = std::thread::hardware_concurrency() >= 4 ? 2 : 1; SoundManager::SoundManager() : mDecoder{std::make_unique<SoundDecoder>(this, kDecoderThreads)} : mDecoder{std::make_unique<SoundDecoder>(this, kDecoderThreads, ANDROID_PRIORITY_NORMAL)} { ALOGV("%s()", __func__); } Loading media/jni/soundpool/StreamManager.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,8 @@ StreamManager::StreamManager( mThreadPool = std::make_unique<ThreadPool>( std::min((size_t)streams, // do not make more threads than streams to play std::min(threads, (size_t)std::thread::hardware_concurrency())), "SoundPool_"); "SoundPool_", ANDROID_PRIORITY_AUDIO); } #pragma clang diagnostic pop Loading media/jni/soundpool/StreamManager.h +9 −5 Original line number Diff line number Diff line Loading @@ -46,9 +46,9 @@ namespace android::soundpool { */ class JavaThread { public: JavaThread(std::function<void()> f, const char *name) JavaThread(std::function<void()> f, const char *name, int32_t threadPriority) : mF{std::move(f)} { createThreadEtc(staticFunction, this, name, ANDROID_PRIORITY_AUDIO); createThreadEtc(staticFunction, this, name, threadPriority); } JavaThread(JavaThread &&) = delete; // uses "this" ptr, not moveable. Loading Loading @@ -109,9 +109,11 @@ private: */ class ThreadPool { public: ThreadPool(size_t maxThreadCount, std::string name) ThreadPool(size_t maxThreadCount, std::string name, int32_t threadPriority = ANDROID_PRIORITY_NORMAL) : mMaxThreadCount(maxThreadCount) , mName{std::move(name)} { } , mName{std::move(name)} , mThreadPriority(threadPriority) {} ~ThreadPool() { quit(); } Loading Loading @@ -159,7 +161,8 @@ public: const int32_t id = mNextThreadId; mThreads.emplace_back(std::make_unique<JavaThread>( [this, id, mf = std::move(f)] { mf(id); --mActiveThreadCount; }, (mName + std::to_string(id)).c_str())); (mName + std::to_string(id)).c_str(), mThreadPriority)); ++mActiveThreadCount; return id; } Loading @@ -180,6 +183,7 @@ public: private: const size_t mMaxThreadCount; const std::string mName; const int32_t mThreadPriority; std::atomic_size_t mActiveThreadCount = 0; Loading Loading
media/jni/soundpool/SoundDecoder.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -29,14 +29,15 @@ static constexpr size_t kMaxQueueSize = 128; // before the SoundDecoder thread closes. static constexpr int32_t kWaitTimeBeforeCloseMs = 1000; SoundDecoder::SoundDecoder(SoundManager* soundManager, size_t threads) SoundDecoder::SoundDecoder(SoundManager* soundManager, size_t threads, int32_t threadPriority) : mSoundManager(soundManager) { ALOGV("%s(%p, %zu)", __func__, soundManager, threads); // ThreadPool is created, but we don't launch any threads. mThreadPool = std::make_unique<ThreadPool>( std::min(threads, (size_t)std::thread::hardware_concurrency()), "SoundDecoder_"); "SoundDecoder_", threadPriority); } SoundDecoder::~SoundDecoder() Loading
media/jni/soundpool/SoundDecoder.h +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ namespace android::soundpool { */ class SoundDecoder { public: SoundDecoder(SoundManager* soundManager, size_t threads); SoundDecoder(SoundManager* soundManager, size_t threads, int32_t threadPriority); ~SoundDecoder(); void loadSound(int32_t soundID) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock void quit(); Loading
media/jni/soundpool/SoundManager.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ namespace android::soundpool { static const size_t kDecoderThreads = std::thread::hardware_concurrency() >= 4 ? 2 : 1; SoundManager::SoundManager() : mDecoder{std::make_unique<SoundDecoder>(this, kDecoderThreads)} : mDecoder{std::make_unique<SoundDecoder>(this, kDecoderThreads, ANDROID_PRIORITY_NORMAL)} { ALOGV("%s()", __func__); } Loading
media/jni/soundpool/StreamManager.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,8 @@ StreamManager::StreamManager( mThreadPool = std::make_unique<ThreadPool>( std::min((size_t)streams, // do not make more threads than streams to play std::min(threads, (size_t)std::thread::hardware_concurrency())), "SoundPool_"); "SoundPool_", ANDROID_PRIORITY_AUDIO); } #pragma clang diagnostic pop Loading
media/jni/soundpool/StreamManager.h +9 −5 Original line number Diff line number Diff line Loading @@ -46,9 +46,9 @@ namespace android::soundpool { */ class JavaThread { public: JavaThread(std::function<void()> f, const char *name) JavaThread(std::function<void()> f, const char *name, int32_t threadPriority) : mF{std::move(f)} { createThreadEtc(staticFunction, this, name, ANDROID_PRIORITY_AUDIO); createThreadEtc(staticFunction, this, name, threadPriority); } JavaThread(JavaThread &&) = delete; // uses "this" ptr, not moveable. Loading Loading @@ -109,9 +109,11 @@ private: */ class ThreadPool { public: ThreadPool(size_t maxThreadCount, std::string name) ThreadPool(size_t maxThreadCount, std::string name, int32_t threadPriority = ANDROID_PRIORITY_NORMAL) : mMaxThreadCount(maxThreadCount) , mName{std::move(name)} { } , mName{std::move(name)} , mThreadPriority(threadPriority) {} ~ThreadPool() { quit(); } Loading Loading @@ -159,7 +161,8 @@ public: const int32_t id = mNextThreadId; mThreads.emplace_back(std::make_unique<JavaThread>( [this, id, mf = std::move(f)] { mf(id); --mActiveThreadCount; }, (mName + std::to_string(id)).c_str())); (mName + std::to_string(id)).c_str(), mThreadPriority)); ++mActiveThreadCount; return id; } Loading @@ -180,6 +183,7 @@ public: private: const size_t mMaxThreadCount; const std::string mName; const int32_t mThreadPriority; std::atomic_size_t mActiveThreadCount = 0; Loading