]> git.ktnx.net Git - mobile-ledger.git/commitdiff
implement AutoCloseable in Locker
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 1 Aug 2020 12:59:18 +0000 (12:59 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 1 Aug 2020 12:59:18 +0000 (12:59 +0000)
app/src/main/java/net/ktnx/mobileledger/utils/Locker.java

index 515b314ca8f10fb74627ee606e855493789a1c0e..474ce83f92907d521886222975530ef1066a4101 100644 (file)
@@ -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();
+    }
 }