mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
bsqblockchain: use write lock for atomic writes
A ReentrantReadWriteLock is used. By acquiring the write lock over the atomic write all other locks acquired during the atomic operation will work as expected.
This commit is contained in:
parent
9aef72a558
commit
e9e4a827ca
2 changed files with 4 additions and 16 deletions
|
@ -67,16 +67,4 @@ public class FunctionalReadWriteLock {
|
|||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO triggers deadlocks with reads
|
||||
public <T> T readWrite(Supplier<T> block) {
|
||||
readLock.lock();
|
||||
writeLock.lock();
|
||||
try {
|
||||
return block.get();
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class BsqBlockChain implements PersistableEnvelope {
|
|||
private static final int BTC_TEST_NET_GENESIS_BLOCK_HEIGHT = 1227630;
|
||||
|
||||
// REG TEST
|
||||
private static final String BTC_REG_TEST_GENESIS_TX_ID = "5d946044ea547df121b49c07274dcf37f5a554f86c2ce65c8b43625acc01c93b";
|
||||
private static final String BTC_REG_TEST_GENESIS_TX_ID = "5116d4f9107ce2b6bacacf750037f1b51fa302a9c96fe20c0d68b35728182a38";
|
||||
private static final int BTC_REG_TEST_GENESIS_BLOCK_HEIGHT = 200;
|
||||
|
||||
public static int getGenesisHeight() {
|
||||
|
@ -237,8 +237,8 @@ public class BsqBlockChain implements PersistableEnvelope {
|
|||
// Atomic access
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public <T> T callFunctionWithReadWriteLock(Supplier<T> supplier) {
|
||||
return lock.readWrite(supplier::get);
|
||||
public <T> T callFunctionWithWriteLock(Supplier<T> supplier) {
|
||||
return lock.write(supplier::get);
|
||||
}
|
||||
|
||||
|
||||
|
@ -527,7 +527,7 @@ public class BsqBlockChain implements PersistableEnvelope {
|
|||
if (snapshotCandidate != null) {
|
||||
// We clone because storage is in a threaded context
|
||||
final BsqBlockChain cloned = getClone(snapshotCandidate);
|
||||
checkNotNull(storage, "storage must nto be null");
|
||||
checkNotNull(storage, "storage must not be null");
|
||||
storage.queueUpForSave(cloned);
|
||||
// dont access cloned anymore with methods as locks are transient!
|
||||
log.info("Saved snapshotCandidate to Disc at height " + cloned.chainHeadHeight);
|
||||
|
|
Loading…
Add table
Reference in a new issue