diff options
| author | 2021-04-12 15:32:09 -0700 | |
|---|---|---|
| committer | 2021-04-12 15:32:09 -0700 | |
| commit | cdd7df92b0efdea578b32aa98276d20817c7c48e (patch) | |
| tree | feccf38bbec26a38e2055d75baabec210eb6686f | |
| parent | b7f378a110e98d05d160e1ecd34386cacd3160e6 (diff) | |
SurfaceFlinger::getNewTexture: Don't deadlock on main thread
This codepath may be invoked on the main thread via the
RefreshRateOverlay surface creation codepath. In such case it will
trigger a deadlock as we wait on the main thread to complete while
blocking the main thread. This can be observed by running
RefreshRateOverlayTests with ~5 iterations. It seems safest to just
avoid this deadlock.
Bug: 184991996
Test: Existing tests pass
Change-Id: I3c5c495b8e93761813157840c9878c73bcdee579
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 02579c6bde..82661eca68 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -693,12 +693,16 @@ uint32_t SurfaceFlinger::getNewTexture() { // The pool was empty, so we need to get a new texture name directly using a // blocking call to the main thread - return schedule([this] { + auto genTextures = [this] { uint32_t name = 0; getRenderEngine().genTextures(1, &name); return name; - }) - .get(); + }; + if (std::this_thread::get_id() == mMainThreadId) { + return genTextures(); + } else { + return schedule(genTextures).get(); + } } void SurfaceFlinger::deleteTextureAsync(uint32_t texture) { |