]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/Locker.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / utils / Locker.java
index 515b314ca8f10fb74627ee606e855493789a1c0e..097fdd08f3f94dae77fdf4508b9b1c58d858721d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -19,8 +19,8 @@ package net.ktnx.mobileledger.utils;
 
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-public class Locker {
-    private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+public class Locker implements AutoCloseable {
+    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
     public LockHolder lockForWriting() {
         ReentrantReadWriteLock.WriteLock wLock = lock.writeLock();
         wLock.lock();
@@ -35,4 +35,9 @@ public class Locker {
         rLock.lock();
         return new LockHolder(rLock);
     }
+    @Override
+    public void close() {
+        lock.readLock().unlock();
+        lock.writeLock().unlock();
+    }
 }