Loading
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