Skip to content

Commit

Permalink
feat: support deadlock detection on android (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering authored Apr 8, 2024
1 parent f62029d commit d161488
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/src/main/java/org/bitcoinj/evolution/QuorumState.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public void processDiff(@Nullable Peer peer, SimplifiedMasternodeListDiff mnlist

lock.lock();
try {
log.info("lock acquired when processing mnlistdiff");
applyDiff(peer, blockChain, mnlistdiff, isLoadingBootStrap);

log.info(this.toString());
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/org/bitcoinj/utils/Threading.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,19 @@ public void execute(@Nonnull Runnable runnable) {

private static CycleDetectingLockFactory.Policy policy;
public static CycleDetectingLockFactory factory;
private static boolean useDefaultAndroidPolicy = true;

public static ReentrantLock lock(String name) {
if (Utils.isAndroidRuntime())
if (Utils.isAndroidRuntime() && useDefaultAndroidPolicy)
return new ReentrantLock(true);
else
return factory.newReentrantLock(name);
}

public static void setUseDefaultAndroidPolicy(boolean use) {
useDefaultAndroidPolicy = use;
}

public static void warnOnLockCycles() {
setPolicy(CycleDetectingLockFactory.Policies.WARN);
}
Expand Down

0 comments on commit d161488

Please sign in to comment.