Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 42e70ad

Browse files
committed
Merge pull request #42 from couchbaselabs/feature/issue_937_dead_lock
Fixed Java Core 937 - Dead Lock in inTransaction
2 parents 010a796 + 017a6bf commit 42e70ad

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/main/java/com/couchbase/lite/store/ForestDBStore.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ public class ForestDBStore implements Store, EncryptableStore, Constants {
9494
private boolean readOnly = false;
9595
private SymmetricKey encryptionKey;
9696

97+
private ThreadLocal<Integer> transactionLevel4Thread = new ThreadLocal<Integer>() {
98+
@Override
99+
protected Integer initialValue() {
100+
return 0;
101+
}
102+
};
103+
97104
// Native method for deriving PBDDF2-SHA256 key:
98105
private static native byte[] nativeDerivePBKDF2SHA256Key(String password, byte[] salt, int rounds);
99106

@@ -249,7 +256,7 @@ public long getLastSequence() {
249256

250257
@Override
251258
public boolean inTransaction() {
252-
return forest.isInTransaction();
259+
return transactionLevel4Thread.get() > 0;
253260
}
254261

255262
@Override
@@ -1226,6 +1233,7 @@ private DocumentChange changeWithNewRevision(RevisionInternal inRev,
12261233
private boolean beginTransaction() {
12271234
try {
12281235
forest.beginTransaction();
1236+
transactionLevel4Thread.set(transactionLevel4Thread.get() + 1);
12291237
} catch (ForestException e) {
12301238
Log.e(TAG, "Failed to begin transaction", e);
12311239
return false;
@@ -1235,6 +1243,7 @@ private boolean beginTransaction() {
12351243

12361244
private boolean endTransaction(boolean commit) {
12371245
try {
1246+
transactionLevel4Thread.set(transactionLevel4Thread.get() - 1);
12381247
forest.endTransaction(commit);
12391248
} catch (ForestException e) {
12401249
Log.e(TAG, "Failed to end transaction", e);

0 commit comments

Comments
 (0)