]> source.dussan.org Git - jgit.git/commitdiff
In LockFile#waitForStatChange wait in units of file time resolution 72/147072/4
authorMatthias Sohn <matthias.sohn@sap.com>
Mon, 5 Aug 2019 16:00:35 +0000 (18:00 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 7 Aug 2019 11:21:39 +0000 (13:21 +0200)
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 <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java

index ccca0279aa32732a5787fbae36869a9e1a0a4d6b..420e7375431c1bd19722bfbe3bbb0ea44419c854 100644 (file)
@@ -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()));