aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-03-12 00:10:51 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-03-12 00:10:59 +0100
commit57f3ee4c160c68dd603165d000de617182c6ae85 (patch)
tree8020258256f3c26f8ae00eb17e9bf7d83048ee14 /org.eclipse.jgit/src
parent3ebb8183c826343afa2f8af52f9bb3d515b79045 (diff)
parent35e96348d3032a5670e8dbd0fb0a90852af65cf1 (diff)
downloadjgit-57f3ee4c160c68dd603165d000de617182c6ae85.tar.gz
jgit-57f3ee4c160c68dd603165d000de617182c6ae85.zip
Merge branch 'stable-5.0' into stable-5.1
* stable-5.0: Reduce contention on PackFile.idx() function. Change-Id: Ic50f375faa757076e2dfd6c25e9e0025482aa3d9 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java61
1 files changed, 35 insertions, 26 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
index ed238a40e7..7549274efd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
@@ -139,7 +139,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
private byte[] packChecksum;
- private PackIndex loadedIdx;
+ private volatile PackIndex loadedIdx;
private PackReverseIndex reverseIdx;
@@ -174,35 +174,44 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
length = Long.MAX_VALUE;
}
- private synchronized PackIndex idx() throws IOException {
- if (loadedIdx == null) {
- if (invalid)
- throw new PackInvalidException(packFile);
-
- try {
- final PackIndex idx = PackIndex.open(extFile(INDEX));
-
- if (packChecksum == null) {
- packChecksum = idx.packChecksum;
- } else if (!Arrays.equals(packChecksum, idx.packChecksum)) {
- throw new PackMismatchException(MessageFormat.format(
- JGitText.get().packChecksumMismatch,
- packFile.getPath(),
- ObjectId.fromRaw(packChecksum).name(),
- ObjectId.fromRaw(idx.packChecksum).name()));
+ private PackIndex idx() throws IOException {
+ PackIndex idx = loadedIdx;
+ if (idx == null) {
+ synchronized (this) {
+ idx = loadedIdx;
+ if (idx == null) {
+ if (invalid) {
+ throw new PackInvalidException(packFile);
+ }
+ try {
+ idx = PackIndex.open(extFile(INDEX));
+
+ if (packChecksum == null) {
+ packChecksum = idx.packChecksum;
+ } else if (!Arrays.equals(packChecksum,
+ idx.packChecksum)) {
+ throw new PackMismatchException(MessageFormat
+ .format(JGitText.get().packChecksumMismatch,
+ packFile.getPath(),
+ ObjectId.fromRaw(packChecksum)
+ .name(),
+ ObjectId.fromRaw(idx.packChecksum)
+ .name()));
+ }
+ loadedIdx = idx;
+ } catch (InterruptedIOException e) {
+ // don't invalidate the pack, we are interrupted from
+ // another thread
+ throw e;
+ } catch (IOException e) {
+ invalid = true;
+ throw e;
+ }
}
- loadedIdx = idx;
- } catch (InterruptedIOException e) {
- // don't invalidate the pack, we are interrupted from another thread
- throw e;
- } catch (IOException e) {
- invalid = true;
- throw e;
}
}
- return loadedIdx;
+ return idx;
}
-
/**
* Get the File object which locates this pack on disk.
*