[res] Make TargetContainer thread safe
idmap2d caches target containers, and that cached container can
be used from multiple binder threads at once. If any of those
threads tries to initialize the assets for the first time, it
causes crashes in all other threads as they get their zip_ field
cleared from under their reads. This CL ensures that all access
to the mutable fields are under a lock.
This shouldn't cause any notable differences in performance, as
that access is usually a single pointer read. When it's not,
it's loading the whole APK of assets, and we're still better off
waiting for the thread that is doing it vs loading the same APK
in parallel.
+ a few missing std::move() calls
Bug: b/377804994
Test: build + boot + atest idmap2_tests
Flag: EXEMPT bugfix, adding a mutex is unflaggable
Change-Id: I17223e2567434b177f21ab044cfdb737a74bf6de
1 file changed