Go back to using a reentrant lock for store operations.
This commit is contained in:
parent
4b862cf4c7
commit
1b9efeb049
1 changed files with 23 additions and 13 deletions
|
@ -4,8 +4,11 @@ import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
import org.whispersystems.signalservice.api.SignalSessionLock;
|
import org.whispersystems.signalservice.api.SignalSessionLock;
|
||||||
|
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of {@link SignalSessionLock} that effectively re-uses our database lock.
|
* An implementation of {@link SignalSessionLock} that effectively re-uses our database lock.
|
||||||
*/
|
*/
|
||||||
|
@ -15,10 +18,13 @@ public enum DatabaseSessionLock implements SignalSessionLock {
|
||||||
|
|
||||||
public static final long NO_OWNER = -1;
|
public static final long NO_OWNER = -1;
|
||||||
|
|
||||||
|
private static final ReentrantLock LEGACY_LOCK = new ReentrantLock();
|
||||||
|
|
||||||
private volatile long ownerThreadId = NO_OWNER;
|
private volatile long ownerThreadId = NO_OWNER;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Lock acquire() {
|
public Lock acquire() {
|
||||||
|
if (FeatureFlags.internalUser()) {
|
||||||
SQLiteDatabase db = DatabaseFactory.getInstance(ApplicationDependencies.getApplication()).getRawDatabase();
|
SQLiteDatabase db = DatabaseFactory.getInstance(ApplicationDependencies.getApplication()).getRawDatabase();
|
||||||
|
|
||||||
if (db.isDbLockedByCurrentThread()) {
|
if (db.isDbLockedByCurrentThread()) {
|
||||||
|
@ -34,6 +40,10 @@ public enum DatabaseSessionLock implements SignalSessionLock {
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
LEGACY_LOCK.lock();
|
||||||
|
return LEGACY_LOCK::unlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue