aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2018-06-08 09:50:39 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2018-06-08 09:54:38 +0200
commit1cb8c5d7fe2d88c127bafcff3800b91e5ab5eda4 (patch)
treeb8ad2f21732f3f02b34f5490326ba8e13d59cef6 /org.eclipse.jgit
parentb782518caedc7b20e3d568f78a5a1d2b0aa17424 (diff)
downloadjgit-1cb8c5d7fe2d88c127bafcff3800b91e5ab5eda4.tar.gz
jgit-1cb8c5d7fe2d88c127bafcff3800b91e5ab5eda4.zip
Simplify locking of FileRepository's index snapshot
synchronize on simple Object monitor instead of using ReentrantLock Change-Id: I897020ab35786336b51b0fef76ea6071aff8aefa Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java13
1 files changed, 3 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
index d4056871b0..d02888a872 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
@@ -56,7 +56,6 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -125,7 +124,7 @@ public class FileRepository extends Repository {
private final RefDatabase refs;
private final ObjectDirectory objectDatabase;
- private final ReentrantLock snapshotLock = new ReentrantLock();
+ private final Object snapshotLock = new Object();
// protected by snapshotLock
private FileSnapshot snapshot;
@@ -553,8 +552,7 @@ public class FileRepository extends Repository {
}
File indexFile = getIndexFile();
- snapshotLock.lock();
- try {
+ synchronized (snapshotLock) {
if (snapshot == null) {
snapshot = FileSnapshot.save(indexFile);
return;
@@ -562,8 +560,6 @@ public class FileRepository extends Repository {
if (!snapshot.isModified(indexFile)) {
return;
}
- } finally {
- snapshotLock.unlock();
}
notifyIndexChanged(false);
}
@@ -571,11 +567,8 @@ public class FileRepository extends Repository {
/** {@inheritDoc} */
@Override
public void notifyIndexChanged(boolean internal) {
- snapshotLock.lock();
- try {
+ synchronized (snapshotLock) {
snapshot = FileSnapshot.save(getIndexFile());
- } finally {
- snapshotLock.unlock();
}
fireEvent(new IndexChangedEvent(internal));
}