am 773f2272: Fix: wrong locking order.

* commit '773f2272421738b400c5eb24b36d36b9d3b29207':
  Fix: wrong locking order.
main
Keisuke Kuroyanagi 2013-09-08 20:20:51 -07:00 committed by Android Git Automerger
commit 1d818b06fe
1 changed files with 10 additions and 8 deletions

View File

@ -84,9 +84,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/** Whether to support dynamically updating the dictionary */
private final boolean mIsUpdatable;
// TODO: remove, once dynamic operations will be serialized
/** Controls access to the shared binary dictionary file across multiple instances. */
private final DictionaryController mSharedDictionaryController;
// TODO: remove, once dynamic operations will be serialized
/** Controls access to the local binary dictionary for this instance. */
private final DictionaryController mLocalDictionaryController = new DictionaryController();
@ -446,9 +448,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
private final void syncReloadDictionaryInternal() {
// Ensure that only one thread attempts to read or write to the shared binary dictionary
// file at the same time.
mLocalDictionaryController.writeLock().lock();
mSharedDictionaryController.writeLock().lock();
try {
mSharedDictionaryController.writeLock().lock();
mLocalDictionaryController.writeLock().lock();
try {
final long time = SystemClock.uptimeMillis();
final boolean dictionaryFileExists = dictionaryFileExists();
@ -483,10 +485,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
mLocalDictionaryController.mLastUpdateTime = time;
} finally {
mSharedDictionaryController.writeLock().unlock();
mLocalDictionaryController.writeLock().unlock();
}
} finally {
mLocalDictionaryController.writeLock().unlock();
mSharedDictionaryController.writeLock().unlock();
}
}
@ -519,16 +521,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
private class AsyncLoadDictionaryToMemoryTask extends Thread {
@Override
public void run() {
mLocalDictionaryController.writeLock().lock();
mSharedDictionaryController.readLock().lock();
try {
mSharedDictionaryController.readLock().lock();
mLocalDictionaryController.writeLock().lock();
try {
loadDictionaryAsync();
} finally {
mSharedDictionaryController.readLock().unlock();
mLocalDictionaryController.writeLock().unlock();
}
} finally {
mLocalDictionaryController.writeLock().unlock();
mSharedDictionaryController.readLock().unlock();
}
}
}