forked from bitcoinj/bitcoinj
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cycle detecting locks, fix Orchid deadlock 2
subgraph/Orchid#10 Conflicts: orchid/src/com/subgraph/orchid/circuits/CircuitIO.java
- Loading branch information
Showing
5 changed files
with
161 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.subgraph.orchid; | ||
|
||
import com.google.common.util.concurrent.CycleDetectingLockFactory; | ||
|
||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
/** | ||
* Created by android on 8/22/14. | ||
*/ | ||
public class Threading { | ||
static { | ||
// Default policy goes here. If you want to change this, use one of the static methods before | ||
// instantiating any orchid objects. The policy change will take effect only on new objects | ||
// from that point onwards. | ||
throwOnLockCycles(); | ||
} | ||
|
||
private static CycleDetectingLockFactory.Policy policy; | ||
public static CycleDetectingLockFactory factory; | ||
|
||
public static ReentrantLock lock(String name) { | ||
return factory.newReentrantLock(name); | ||
} | ||
|
||
public static void warnOnLockCycles() { | ||
setPolicy(CycleDetectingLockFactory.Policies.WARN); | ||
} | ||
|
||
public static void throwOnLockCycles() { | ||
setPolicy(CycleDetectingLockFactory.Policies.THROW); | ||
} | ||
|
||
public static void ignoreLockCycles() { | ||
setPolicy(CycleDetectingLockFactory.Policies.DISABLED); | ||
} | ||
|
||
public static void setPolicy(CycleDetectingLockFactory.Policy policy) { | ||
Threading.policy = policy; | ||
factory = CycleDetectingLockFactory.newInstance(policy); | ||
} | ||
|
||
public static CycleDetectingLockFactory.Policy getPolicy() { | ||
return policy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.