commit | b79e751bef29517e39eaf173226fb95e5869f292 | [log] [tgz] |
---|---|---|
author | Ady Abraham <adyabr@google.com> | Wed Dec 20 13:33:56 2023 -0800 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Tue Jan 23 01:22:24 2024 +0000 |
tree | 06fd45d0bf35cf703a29d69c640ee04c08023b69 | |
parent | 4b28d6e43546fb7a426ff797989613e1db768865 [diff] |
SF: make RenderEngineThreaded::waitUntilInitialized more efficient RenderEngineThreaded::waitUntilInitialized is called from multiple threads. Use atomic to avoid contending on a mutex. Bug: 313924033 Test: presubmit (cherry picked from commit 36135d0e0f880d28a77792bd1b7519e3a2110a8d) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d6ac7795876884aa18e565ebdd1400b49acc5c64) Merged-In: I4d61240a76f3ca814c28ccba62626f8b43a125cd Change-Id: I4d61240a76f3ca814c28ccba62626f8b43a125cd
diff --git a/libs/renderengine/threaded/RenderEngineThreaded.cpp b/libs/renderengine/threaded/RenderEngineThreaded.cpp index 6a1561a..528115d 100644 --- a/libs/renderengine/threaded/RenderEngineThreaded.cpp +++ b/libs/renderengine/threaded/RenderEngineThreaded.cpp
@@ -127,8 +127,10 @@ } void RenderEngineThreaded::waitUntilInitialized() const { - std::unique_lock<std::mutex> lock(mInitializedMutex); - mInitializedCondition.wait(lock, [=] { return mIsInitialized; }); + if (!mIsInitialized) { + std::unique_lock<std::mutex> lock(mInitializedMutex); + mInitializedCondition.wait(lock, [this] { return mIsInitialized.load(); }); + } } std::future<void> RenderEngineThreaded::primeCache() {
diff --git a/libs/renderengine/threaded/RenderEngineThreaded.h b/libs/renderengine/threaded/RenderEngineThreaded.h index 6eb108e..4ba26bf 100644 --- a/libs/renderengine/threaded/RenderEngineThreaded.h +++ b/libs/renderengine/threaded/RenderEngineThreaded.h
@@ -100,7 +100,7 @@ // Used to allow select thread safe methods to be accessed without requiring the // method to be invoked on the RenderEngine thread - bool mIsInitialized = false; + std::atomic_bool mIsInitialized = false; mutable std::mutex mInitializedMutex; mutable std::condition_variable mInitializedCondition;