Skip to content

Commit 38767b3

Browse files
dtrebbienJean-Baptiste Queru
authored andcommitted
Reorder lock acquision vs try.
In two places involving locking, reordered the code so that the lock acquisition is performed outside of the `try` block and everything else that needs to run while the lock is locked *within* the `try` block. Change-Id: I3dad2c4bbf60b219fc6db2aa35e2ed296cb39128
1 parent cee8d1d commit 38767b3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

core/java/android/database/sqlite/SQLiteCursor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ public void run() {
131131
// the cursor's state doesn't change
132132
while (true) {
133133
mLock.lock();
134-
if (mCursorState != mThreadState) {
135-
mLock.unlock();
136-
break;
137-
}
138134
try {
135+
if (mCursorState != mThreadState) {
136+
break;
137+
}
138+
139139
int count = mQuery.fillWindow(cw, mMaxRead, mCount);
140140
// return -1 means not finished
141141
if (count != 0) {
@@ -217,9 +217,8 @@ public SQLiteCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
217217
mColumnNameMap = null;
218218
mQuery = query;
219219

220+
db.lock();
220221
try {
221-
db.lock();
222-
223222
// Setup the list of columns
224223
int columnCount = mQuery.columnCountLocked();
225224
mColumns = new String[columnCount];

0 commit comments

Comments
 (0)