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

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

Merge "reduce synchronization on SQLiteDatabase wherever possible"

parents 726e75d4 8fef1b75
Loading
Loading
Loading
Loading
+76 −87
Original line number Diff line number Diff line
@@ -58,8 +58,7 @@ import java.util.Random;
    /**
     * close all database connections in the pool - even if they are in use!
     */
    /* package */ void close() {
        synchronized(mParentDbObj) {
    /* package */ synchronized void close() {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Closing the connection pool on " + mParentDbObj.getPath() + toString());
        }
@@ -68,7 +67,6 @@ import java.util.Random;
        }
        mPool.clear();
    }
    }

    /**
     * get a free connection from the pool
@@ -77,10 +75,9 @@ import java.util.Random;
     * the compiled statement for this sql.
     * @return the Database connection that the caller can use
     */
    /* package */ SQLiteDatabase get(String sql) {
    /* package */ synchronized SQLiteDatabase get(String sql) {
        SQLiteDatabase db = null;
        PoolObj poolObj = null;
        synchronized(mParentDbObj) {
        int poolSize = mPool.size();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            assert sql != null;
@@ -145,8 +142,6 @@ import java.util.Random;
        assert poolObj.mDb == db;

        poolObj.acquire();
        }

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "END get-connection: " + toString() + poolObj.toString());
        }
@@ -159,16 +154,14 @@ import java.util.Random;
     * release the given database connection back to the pool.
     * @param db the connection to be released
     */
    /* package */ void release(SQLiteDatabase db) {
        PoolObj poolObj;
        synchronized(mParentDbObj) {
    /* package */ synchronized void release(SQLiteDatabase db) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            assert db.mConnectionNum > 0;
            doAsserts();
            assert mPool.get(db.mConnectionNum - 1).mDb == db;
        }

            poolObj = mPool.get(db.mConnectionNum - 1);
        PoolObj poolObj = mPool.get(db.mConnectionNum - 1);

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "BEGIN release-conn: " + toString() + poolObj.toString());
@@ -180,8 +173,6 @@ import java.util.Random;
        }

        poolObj.release();
        }

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "END release-conn: " + toString() + poolObj.toString());
        }
@@ -191,13 +182,11 @@ import java.util.Random;
     * Returns a list of all database connections in the pool (both free and busy connections).
     * This method is used when "adb bugreport" is done.
     */
    /* package */ ArrayList<SQLiteDatabase> getConnectionList() {
    /* package */ synchronized ArrayList<SQLiteDatabase> getConnectionList() {
        ArrayList<SQLiteDatabase> list = new ArrayList<SQLiteDatabase>();
        synchronized(mParentDbObj) {
        for (int i = mPool.size() - 1; i >= 0; i--) {
            list.add(mPool.get(i).mDb);
        }
        }
        return list;
    }