mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1041632 - Part 7: make MemoryMonitor thread-safe. r=ckitching
This commit is contained in:
parent
3ab60ab52d
commit
f8034be801
@ -40,7 +40,7 @@ class MemoryMonitor extends BroadcastReceiver {
|
||||
private static final String ACTION_MEMORY_DUMP = "org.mozilla.gecko.MEMORY_DUMP";
|
||||
private static final String ACTION_FORCE_PRESSURE = "org.mozilla.gecko.FORCE_MEMORY_PRESSURE";
|
||||
|
||||
// Memory pressue levels, keep in sync with those in AndroidJavaWrappers.h
|
||||
// Memory pressure levels. Keep these in sync with those in AndroidJavaWrappers.h
|
||||
private static final int MEMORY_PRESSURE_NONE = 0;
|
||||
private static final int MEMORY_PRESSURE_CLEANUP = 1;
|
||||
private static final int MEMORY_PRESSURE_LOW = 2;
|
||||
@ -54,8 +54,8 @@ class MemoryMonitor extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private final PressureDecrementer mPressureDecrementer;
|
||||
private int mMemoryPressure;
|
||||
private boolean mStoragePressure;
|
||||
private int mMemoryPressure; // Synchronized access only.
|
||||
private volatile boolean mStoragePressure; // Accessed via UI thread intent, background runnables.
|
||||
private boolean mInited;
|
||||
|
||||
private MemoryMonitor() {
|
||||
@ -166,6 +166,13 @@ class MemoryMonitor extends BroadcastReceiver {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread-safe due to mStoragePressure's volatility.
|
||||
*/
|
||||
boolean isUnderStoragePressure() {
|
||||
return mStoragePressure;
|
||||
}
|
||||
|
||||
private boolean decreaseMemoryPressure() {
|
||||
int newLevel;
|
||||
synchronized (this) {
|
||||
@ -207,7 +214,7 @@ class MemoryMonitor extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
class StorageReducer implements Runnable {
|
||||
private static class StorageReducer implements Runnable {
|
||||
private final Context mContext;
|
||||
public StorageReducer(final Context context) {
|
||||
this.mContext = context;
|
||||
@ -221,8 +228,8 @@ class MemoryMonitor extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mStoragePressure) {
|
||||
// pressure is off, so we can abort
|
||||
if (!MemoryMonitor.getInstance().isUnderStoragePressure()) {
|
||||
// Pressure is off, so we can abort.
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user