Add volatile to some cancel compaction signals to avoid compiler optimizations

The compaction cancel signals are delivered between different threads so
add volatile keyword for such variables to make sure the compiler does
not try to optimize the values avoiding them to be effective due to
potential register caching.

Bug: 227060330
Test: Manual

Change-Id: I42503e02627c6f76382a58da9320b3f5df15a75d
This commit is contained in:
Edgar Arriaga
2022-03-29 19:53:06 -07:00
parent 463a08b2ac
commit ce1bdbe56d
2 changed files with 3 additions and 1 deletions

View File

@@ -1737,7 +1737,7 @@ public final class CachedAppOptimizer {
* Default implementation for ProcessDependencies, public vor visibility to OomAdjuster class.
*/
private static final class DefaultProcessDependencies implements ProcessDependencies {
public static int mPidCompacting = -1;
public static volatile int mPidCompacting = -1;
// Get memory RSS from process.
@Override

View File

@@ -79,6 +79,8 @@ using android::base::unique_fd;
namespace android {
// Signal happening in separate thread that would bail out compaction
// before starting next VMA batch
static std::atomic<bool> cancelRunningCompaction;
// Legacy method for compacting processes, any new code should