From: Damyan Ivanov Date: Sat, 1 Aug 2020 12:59:18 +0000 (+0000) Subject: implement AutoCloseable in Locker X-Git-Tag: v0.15.0~76 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=414e2eaa40920ea9f9748804e51052b043afb0ca;p=mobile-ledger.git implement AutoCloseable in Locker --- diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java b/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java index 515b314c..474ce83f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java @@ -19,7 +19,7 @@ package net.ktnx.mobileledger.utils; import java.util.concurrent.locks.ReentrantReadWriteLock; -public class Locker { +public class Locker implements AutoCloseable { private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); public LockHolder lockForWriting() { ReentrantReadWriteLock.WriteLock wLock = lock.writeLock(); @@ -35,4 +35,9 @@ public class Locker { rLock.lock(); return new LockHolder(rLock); } + @Override + public void close() { + lock.readLock().unlock(); + lock.writeLock().unlock(); + } }