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