Fix deadlock when using PackageManagerLocal while holding mLock.
The lock order requires obtaining mSnapshotLock before mLock, however if a caller is called under mLock and tries to use PackageManagerLocal, it will call snapshotComputer() which will try to obtain mSnapshotLock and result in a deadlock. However, actually mSnapshotLock is just a preliminary check that exists as a less contended lock than mLock - it adds a third layer between the regular double checked locking, but still always requires holding the final mLock before actual mutations. So if the caller is already holding mLock, we can simply let it rebuild the snapshot directly when necessary. And in terms of the triple checked locking, we just need to check whether sSnapshot has become up-to-date again after obtaining mLock in the normal path. Fixes: 263455681 Test: manual Change-Id: I7d00ff2091331d02dc666f09cb62523679009300
Loading
Please register or sign in to comment