Fix premature timeouts on tile read waits, causing missed tile loads

This commit is contained in:
Mike Primm 2011-07-03 11:30:48 -05:00
parent 97ff6a2c2d
commit e724a7bccb

View File

@ -72,7 +72,9 @@ public class FileLockManager {
String fn = f.getPath(); String fn = f.getPath();
synchronized(lock) { synchronized(lock) {
boolean got_lock = false; boolean got_lock = false;
boolean first_wait = true; long starttime = 0;
if(timeout > 0)
starttime = System.currentTimeMillis();
while(!got_lock) { while(!got_lock) {
Integer lockcnt = filelocks.get(fn); /* Get lock count */ Integer lockcnt = filelocks.get(fn); /* Get lock count */
if(lockcnt == null) { if(lockcnt == null) {
@ -85,14 +87,16 @@ public class FileLockManager {
} }
else { /* Write lock in place */ else { /* Write lock in place */
try { try {
if((timeout > 0) && (!first_wait)) { /* We already waited */ if(timeout < 0) {
return false;
}
if(timeout < 0)
lock.wait(); lock.wait();
else }
lock.wait(timeout); else {
first_wait = false; long now = System.currentTimeMillis();
long elapsed = now-starttime;
if(elapsed > timeout) /* Give up on timeout */
return false;
lock.wait(timeout-elapsed);
}
} catch (InterruptedException ix) { } catch (InterruptedException ix) {
Log.severe("getReadLock(" + fn + ") interrupted"); Log.severe("getReadLock(" + fn + ") interrupted");
return false; return false;