Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
0b1c08bf
Commit
0b1c08bf
authored
11 years ago
by
Keisuke Kuroynagi
Browse files
Options
Downloads
Patches
Plain Diff
Use ReentrantReadWriteLock in ExpandableBinaryDictionary.
Bug: 6669677 Change-Id: I2acde0517d5ed5cbd7b7149709e35fc36651335d
parent
d365d82d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+18
-15
18 additions, 15 deletions
...android/inputmethod/latin/ExpandableBinaryDictionary.java
with
18 additions
and
15 deletions
java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+
18
−
15
View file @
0b1c08bf
...
...
@@ -35,7 +35,7 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.concurrent.locks.Reentrant
ReadWrite
Lock
;
/**
* Abstract base class for an expandable dictionary that can be created and updated dynamically
...
...
@@ -151,14 +151,14 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
@Override
public
void
close
()
{
// Ensure that no other threads are accessing the local binary dictionary.
mLocalDictionaryController
.
lock
();
mLocalDictionaryController
.
writeLock
().
lock
();
try
{
if
(
mBinaryDictionary
!=
null
)
{
mBinaryDictionary
.
close
();
mBinaryDictionary
=
null
;
}
}
finally
{
mLocalDictionaryController
.
unlock
();
mLocalDictionaryController
.
writeLock
().
unlock
();
}
}
...
...
@@ -205,14 +205,14 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
final
String
prevWord
,
final
ProximityInfo
proximityInfo
,
final
boolean
blockOffensiveWords
)
{
asyncReloadDictionaryIfRequired
();
if
(
mLocalDictionaryController
.
tryLock
())
{
if
(
mLocalDictionaryController
.
readLock
().
tryLock
())
{
try
{
if
(
mBinaryDictionary
!=
null
)
{
return
mBinaryDictionary
.
getSuggestions
(
composer
,
prevWord
,
proximityInfo
,
blockOffensiveWords
);
}
}
finally
{
mLocalDictionaryController
.
unlock
();
mLocalDictionaryController
.
readLock
().
unlock
();
}
}
return
null
;
...
...
@@ -225,11 +225,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
protected
boolean
isValidWordInner
(
final
String
word
)
{
if
(
mLocalDictionaryController
.
tryLock
())
{
if
(
mLocalDictionaryController
.
readLock
().
tryLock
())
{
try
{
return
isValidWordLocked
(
word
);
}
finally
{
mLocalDictionaryController
.
unlock
();
mLocalDictionaryController
.
readLock
().
unlock
();
}
}
return
false
;
...
...
@@ -246,11 +246,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
protected
boolean
isValidBigramInner
(
final
String
word1
,
final
String
word2
)
{
if
(
mLocalDictionaryController
.
tryLock
())
{
if
(
mLocalDictionaryController
.
readLock
().
tryLock
())
{
try
{
return
isValidBigramLocked
(
word1
,
word2
);
}
finally
{
mLocalDictionaryController
.
unlock
();
mLocalDictionaryController
.
readLock
().
unlock
();
}
}
return
false
;
...
...
@@ -293,9 +293,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// Ensure all threads accessing the current dictionary have finished before swapping in
// the new one.
final
BinaryDictionary
oldBinaryDictionary
=
mBinaryDictionary
;
mLocalDictionaryController
.
lock
();
mBinaryDictionary
=
newBinaryDictionary
;
mLocalDictionaryController
.
unlock
();
mLocalDictionaryController
.
writeLock
().
lock
();
try
{
mBinaryDictionary
=
newBinaryDictionary
;
}
finally
{
mLocalDictionaryController
.
writeLock
().
unlock
();
}
oldBinaryDictionary
.
close
();
}
else
{
mBinaryDictionary
=
newBinaryDictionary
;
...
...
@@ -390,7 +393,7 @@ 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.
mSharedDictionaryController
.
lock
();
mSharedDictionaryController
.
writeLock
().
lock
();
try
{
final
long
time
=
SystemClock
.
uptimeMillis
();
final
boolean
dictionaryFileExists
=
dictionaryFileExists
();
...
...
@@ -424,7 +427,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
mLocalDictionaryController
.
mLastUpdateTime
=
time
;
}
finally
{
mSharedDictionaryController
.
unlock
();
mSharedDictionaryController
.
writeLock
().
unlock
();
}
}
...
...
@@ -449,7 +452,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* dictionary is out of date. Can be shared across multiple dictionary instances that access the
* same filename.
*/
private
static
class
DictionaryController
extends
ReentrantLock
{
private
static
class
DictionaryController
extends
Reentrant
ReadWrite
Lock
{
private
volatile
long
mLastUpdateTime
=
0
;
private
volatile
long
mLastUpdateRequestTime
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment