Merge "KernelWakelockReader: provide class level lock when updates staleStats" am: b9f60a53c3 am: ec13727383

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1534034

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I32722ae3a7f5fbde2aa7d42402f8f2d670423f4b
This commit is contained in:
Benjamin Schwartz
2020-12-22 17:38:56 +00:00
committed by Automerger Merge Worker

View File

@@ -78,6 +78,8 @@ public class KernelWakelockReader {
boolean useSystemSuspend = (new File(sSysClassWakeupDir)).exists(); boolean useSystemSuspend = (new File(sSysClassWakeupDir)).exists();
if (useSystemSuspend) { if (useSystemSuspend) {
// static read/write lock protection for sKernelWakelockUpdateVersion
synchronized (KernelWakelockReader.class) {
// Get both kernel and native wakelock stats from SystemSuspend // Get both kernel and native wakelock stats from SystemSuspend
updateVersion(staleStats); updateVersion(staleStats);
if (getWakelockStatsFromSystemSuspend(staleStats) == null) { if (getWakelockStatsFromSystemSuspend(staleStats) == null) {
@@ -85,6 +87,7 @@ public class KernelWakelockReader {
return null; return null;
} }
return removeOldStats(staleStats); return removeOldStats(staleStats);
}
} else { } else {
Arrays.fill(mKernelWakelockBuffer, (byte) 0); Arrays.fill(mKernelWakelockBuffer, (byte) 0);
int len = 0; int len = 0;
@@ -141,6 +144,8 @@ public class KernelWakelockReader {
} }
} }
// static read/write lock protection for sKernelWakelockUpdateVersion
synchronized (KernelWakelockReader.class) {
updateVersion(staleStats); updateVersion(staleStats);
// Get native wakelock stats from SystemSuspend // Get native wakelock stats from SystemSuspend
if (getWakelockStatsFromSystemSuspend(staleStats) == null) { if (getWakelockStatsFromSystemSuspend(staleStats) == null) {
@@ -151,6 +156,7 @@ public class KernelWakelockReader {
return removeOldStats(staleStats); return removeOldStats(staleStats);
} }
} }
}
/** /**
* Attempt to wait for suspend_control service if not immediately available. * Attempt to wait for suspend_control service if not immediately available.