]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/LockHolder.java
LockHolder: reset lock instances to null after unlocking
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / utils / LockHolder.java
index f0c976dd96612720d47a1cd46bc97c60d55cb536..5890f0a89a75b5946afee89a0df98587ac68a44f 100644 (file)
 
 package net.ktnx.mobileledger.utils;
 
-import java.io.Closeable;
 import java.util.concurrent.locks.Lock;
 
-public class LockHolder implements Closeable {
+public class LockHolder implements AutoCloseable {
     private Lock rLock, wLock;
     LockHolder(Lock rLock) {
         this.rLock = rLock;
         this.wLock = null;
     }
-    public LockHolder(Lock rLock, Lock wLock) {
+    LockHolder(Lock rLock, Lock wLock) {
         this.rLock = rLock;
         this.wLock = wLock;
     }
     @Override
     public void close() {
-        if (wLock != null) wLock.unlock();
-        if (rLock != null) rLock.unlock();
+        if (wLock != null) { wLock.unlock(); wLock = null; }
+        if (rLock != null) { rLock.unlock(); rLock = null; }
     }
     public void downgrade() {
         if (rLock == null) throw new IllegalStateException("no locks are held");