# HG changeset patch # User Jiri Vanek # Date 1539794179 -7200 # Node ID 323a36b41c4a4d12324888d49e334394aa7ad120 # Parent 5b3e94efb41c534a17e161bea2d2e11092239e2e LockedFile.java: caching enabled, or at least semi-enabled on windows diff -r 5b3e94efb41c -r 323a36b41c4a ChangeLog --- a/ChangeLog Wed Oct 17 18:16:40 2018 +0200 +++ b/ChangeLog Wed Oct 17 18:36:19 2018 +0200 @@ -1,3 +1,8 @@ +2018-10-17 Jiri Vanek + Alex Kashchenko + + * netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java: caching enabled, or at least semi-enabled on windows + 2018-10-17 Laurent Bourgès * netx/net/sourceforge/jnlp/controlpanel/CachePane.java: using SwingUtils.invokeLater instead of diff -r 5b3e94efb41c -r 323a36b41c4a netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java --- a/netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java Wed Oct 17 18:16:40 2018 +0200 +++ b/netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java Wed Oct 17 18:36:19 2018 +0200 @@ -94,7 +94,13 @@ */ synchronized public static LockedFile getInstance(File file) { if (!instanceCache.containsKey(file)) { - instanceCache.put(file, new LockedFile(file)); + LockedFile l; + if (JNLPRuntime.isWindows()) { + l = new WindowsLockedFile(file); + } else { + l = new LockedFile(file); + } + instanceCache.put(file, l); } return instanceCache.get(file); @@ -113,9 +119,6 @@ * Lock access to the file. Lock is reentrant. */ public void lock() throws IOException { - if (JNLPRuntime.isWindows()) { - return; - } // Create if does not already exist, cannot lock non-existing file if (!isReadOnly()) { this.file.createNewFile(); @@ -153,10 +156,14 @@ * Unlock access to the file. Lock is reentrant. Does not do anything if not holding the lock. */ public void unlock() throws IOException { - if (JNLPRuntime.isWindows() || !this.threadLock.isHeldByCurrentThread()) { + if (!this.threadLock.isHeldByCurrentThread()) { return; } boolean releaseProcessLock = (this.threadLock.getHoldCount() == 1); + unlockImpl(releaseProcessLock); + } + + protected void unlockImpl(boolean releaseProcessLock) throws IOException { try { if (releaseProcessLock) { if (this.processLock != null){ @@ -180,4 +187,27 @@ public boolean isHeldByCurrentThread() { return this.threadLock.isHeldByCurrentThread(); } -} \ No newline at end of file + + private static class WindowsLockedFile extends LockedFile { + + public WindowsLockedFile(File file) { + super(file); + } + + /*Comment why itis different*/ + @Override + public void lock() throws IOException { + super.file.createNewFile(); + super.threadLock.lock(); + } + + /*Comment why itis different*/ + @Override + public void unlock() throws IOException { + if (!super.threadLock.isHeldByCurrentThread()) { + return; + } + unlockImpl(false); + } + } +}