mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 19:25:15 +01:00
Fix premature timeouts on tile read waits, causing missed tile loads
This commit is contained in:
parent
97ff6a2c2d
commit
e724a7bccb
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user