Merge "Don\'t hold a lock while reading shared preferences from disk." into nyc-dev am: 5350306989
am: d24ac9abd6
* commit 'd24ac9abd617c5c1753dd1f8c662e42c4207e94e':
Don't hold a lock while reading shared preferences from disk.
This commit is contained in:
@@ -87,20 +87,20 @@ final class SharedPreferencesImpl implements SharedPreferences {
|
||||
}
|
||||
new Thread("SharedPreferencesImpl-load") {
|
||||
public void run() {
|
||||
synchronized (SharedPreferencesImpl.this) {
|
||||
loadFromDiskLocked();
|
||||
}
|
||||
loadFromDisk();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void loadFromDiskLocked() {
|
||||
if (mLoaded) {
|
||||
return;
|
||||
}
|
||||
if (mBackupFile.exists()) {
|
||||
mFile.delete();
|
||||
mBackupFile.renameTo(mFile);
|
||||
private void loadFromDisk() {
|
||||
synchronized (SharedPreferencesImpl.this) {
|
||||
if (mLoaded) {
|
||||
return;
|
||||
}
|
||||
if (mBackupFile.exists()) {
|
||||
mFile.delete();
|
||||
mBackupFile.renameTo(mFile);
|
||||
}
|
||||
}
|
||||
|
||||
// Debugging
|
||||
@@ -118,27 +118,27 @@ final class SharedPreferencesImpl implements SharedPreferences {
|
||||
str = new BufferedInputStream(
|
||||
new FileInputStream(mFile), 16*1024);
|
||||
map = XmlUtils.readMapXml(str);
|
||||
} catch (XmlPullParserException e) {
|
||||
Log.w(TAG, "getSharedPreferences", e);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.w(TAG, "getSharedPreferences", e);
|
||||
} catch (IOException e) {
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
Log.w(TAG, "getSharedPreferences", e);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(str);
|
||||
}
|
||||
}
|
||||
} catch (ErrnoException e) {
|
||||
/* ignore */
|
||||
}
|
||||
mLoaded = true;
|
||||
if (map != null) {
|
||||
mMap = map;
|
||||
mStatTimestamp = stat.st_mtime;
|
||||
mStatSize = stat.st_size;
|
||||
} else {
|
||||
mMap = new HashMap<String, Object>();
|
||||
|
||||
synchronized (SharedPreferencesImpl.this) {
|
||||
mLoaded = true;
|
||||
if (map != null) {
|
||||
mMap = map;
|
||||
mStatTimestamp = stat.st_mtime;
|
||||
mStatSize = stat.st_size;
|
||||
} else {
|
||||
mMap = new HashMap<>();
|
||||
}
|
||||
notifyAll();
|
||||
}
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
static File makeBackupFile(File prefsFile) {
|
||||
|
||||
Reference in New Issue
Block a user