Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93ed831c authored by Vasu Nori's avatar Vasu Nori Committed by Android (Google) Code Review
Browse files

Merge "fix race condition introduced by CL https://android-git.corp.google.com/g/40395"

parents 299102f8 ec37e42f
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -95,12 +95,16 @@ import android.util.Log;
        }
    }

    /* package */ synchronized boolean isInUse() {
        return mInUse;
    /**
     * returns true if acquire() succeeds. false otherwise.
     */
    /* package */ synchronized boolean acquire() {
        if (mInUse) {
            // someone already has acquired it.
            return false;
        }

    /* package */ synchronized void acquire() {
        mInUse = true;
        return true;
    }

    /* package */ synchronized void release() {
+3 −6
Original line number Diff line number Diff line
@@ -61,16 +61,13 @@ public abstract class SQLiteProgram extends SQLiteClosable {
            mCompiledSql.acquire();
        } else {
            // it is already in compiled-sql cache.
            if (mCompiledSql.isInUse()) {
                // but the CompiledSql in cache is in use by some other SQLiteProgram object.
            // try to acquire the object.
            if (!mCompiledSql.acquire()) {
                // the SQLiteCompiledSql in cache is in use by some other SQLiteProgram object.
                // we can't have two different SQLiteProgam objects can't share the same
                // CompiledSql object. create a new one.
                // finalize it when I am done with it in "this" object.
                mCompiledSql = new SQLiteCompiledSql(db, sql);
            } else {
                // the CompiledSql in cache is NOT in use by any other SQLiteProgram object.
                // it is safe to give it to this SQLIteProgram Object.
                mCompiledSql.acquire();
            }
        }
        nStatement = mCompiledSql.nStatement;