From 3b368d5578db13b52b2485b11bf3da1e24ccffd2 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 5 Aug 2019 18:00:35 +0200 Subject: [PATCH] In LockFile#waitForStatChange wait in units of file time resolution Since we now measure file time resolution we can use it to replace the hard coded wait time of 25ms. FileSnapshot#equals will return true until the mtime of the old (o) and the new FileSnapshot (n) differ by at least one file time resolution. Change-Id: Icb713a80ce9eb929242ed083406bfb6650c72223 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/internal/storage/file/LockFile.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java index ccca0279aa..420e737543 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java @@ -61,6 +61,7 @@ import java.nio.file.StandardCopyOption; import java.nio.file.attribute.FileTime; import java.text.MessageFormat; import java.time.Instant; +import java.util.concurrent.TimeUnit; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Constants; @@ -425,8 +426,10 @@ public class LockFile { public void waitForStatChange() throws InterruptedException { FileSnapshot o = FileSnapshot.save(ref); FileSnapshot n = FileSnapshot.save(lck); + long fsTimeResolution = FS.getFileStoreAttributes(lck.toPath()) + .getFsTimestampResolution().toNanos(); while (o.equals(n)) { - Thread.sleep(25 /* milliseconds */); + TimeUnit.NANOSECONDS.sleep(fsTimeResolution); try { Files.setLastModifiedTime(lck.toPath(), FileTime.from(Instant.now())); -- 2.39.5