summaryrefslogtreecommitdiff
path: root/libs/androidfw/FileStream.cpp
diff options
context:
space:
mode:
author Dave Mankoff <mankoff@google.com> 2023-09-27 17:21:33 +0000
committer Dave Mankoff <mankoff@google.com> 2023-09-27 17:21:33 +0000
commit8b61ba28d2242b3fc132a67ee24c0c08027ead6f (patch)
tree73abd2957f429586e166f89ef6935443d84c8341 /libs/androidfw/FileStream.cpp
parentd62cfd94edb9c017ac9f6cb175e818e07b7c8661 (diff)
Fix concurrent access to Flag Cache.
A rare NPE sometimes occurs in FeatureFlagsClassicDebug. My best hypothesis is that it occurs when one thread was attempting to read the internal flag cache while another was adding an item to the cache. The new code in this cl replaces the TreeMap with a ConcurrentHashMap. In addition, it first tries to read the value out of the cache instead of checking for a key's existence and then branching accordingly. If the read fails, it determins what the value should be and adds it to the cache, with no additionaly locks necessary beyond the internals of `ConcurrentHashMap#put`. This means it is theoretically possible for a flag to be `#put` twice if it is read from two different threads simultaneously, but the odds of this are vanishingly small in addition to being completely harmless. Test: atest && manually built and run SystemUI Fixes: 299029193 Change-Id: Iaaa7431dfdc454f6cacdb8561ae07d5fd9e44983
Diffstat (limited to 'libs/androidfw/FileStream.cpp')
0 files changed, 0 insertions, 0 deletions