Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 198ebf4b authored by Jared Duke's avatar Jared Duke
Browse files

Avoid locks in various singleton HandlerThread types

Avoid taking a lock on critical paths for various singleton
HandlerThread types if unnecessary. While these getters are not
typically called with high frequency, this could lead to contention
and is worth avoiding.

For the service/server HandlerThread singletons, we switch to using a
simpler holder pattern. For the BackgroundThread singleton, we cannot
be quite as invasive, as 1) its static fields are shadowed in
Robolectric, and 2) we want to preserve the ability to prewarm the
thread without actually blocking on full initialization. For this,
we instead use the double-checked locking pattern w/ volatile fields.
This isn't quite as clean, but it's just as efficient while preserving
the shadowed fields and allowing both non-blocking prewarm and blocking
initialized gets.

Bug: 411249866
Test: presubmit
Test: atest FrameworksCoreTests
Flag: EXEMPT bugfix
Change-Id: I2e099f8371a5762be6b8fd317c6417d07f710dd1
parent 2889a983
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment