aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-03-12 00:05:55 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-03-12 00:06:17 +0100
commit47d7f7aabb496ec18f0de726d895498575c57a4d (patch)
treee1e21b2bd1ccba74355a19fa4f506bd891285626 /org.eclipse.jgit/src/org/eclipse/jgit
parentae5ea80363efd3b4071e88e04dcf2ca1f3218c93 (diff)
parent19c43806890a5b7556d4d12b87f7ba2bb878cbf8 (diff)
downloadjgit-47d7f7aabb496ec18f0de726d895498575c57a4d.tar.gz
jgit-47d7f7aabb496ec18f0de726d895498575c57a4d.zip
Merge branch 'stable-4.9' into stable-4.10
* stable-4.9: Reduce contention on PackFile.idx() function. Change-Id: I277e53aa752c8ffb8560de710d27ecb58871ec02 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-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 b41ba9b0e6..4a96b6ef7d 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.
*