Fix flushing on main thread

This commit is contained in:
Jesse Boyd 2016-09-24 17:55:15 +10:00
parent 6d52e47d3f
commit 64c00e4c3b
4 changed files with 15 additions and 6 deletions

View File

@ -134,8 +134,8 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
@Override
public boolean flush() {
super.flush();
synchronized (this) {
super.flush();
boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null;
try {
if (osBD != null) {

View File

@ -33,6 +33,8 @@ public abstract class FaweChangeSet implements ChangeSet {
private final World world;
private final boolean mainThread;
public static FaweChangeSet getDefaultChangeSet(World world, UUID uuid) {
if (Settings.HISTORY.USE_DISK) {
return new DiskStorageHistory(world, uuid);
@ -43,6 +45,7 @@ public abstract class FaweChangeSet implements ChangeSet {
public FaweChangeSet(World world) {
this.world = world;
this.mainThread = Fawe.get().isMainThread();
}
public World getWorld() {
@ -174,7 +177,7 @@ public abstract class FaweChangeSet implements ChangeSet {
@Override
public void run(final FaweChunk previous, final FaweChunk next) {
waiting.incrementAndGet();
TaskManager.IMP.async(new Runnable() {
Runnable run = new Runnable() {
@Override
public void run() {
try {
@ -271,7 +274,12 @@ public abstract class FaweChangeSet implements ChangeSet {
}
}
}
});
};
if (mainThread) {
new Thread(run).start();
} else {
TaskManager.IMP.async(run);
}
}
});
}

View File

@ -48,8 +48,8 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
@Override
public boolean flush() {
super.flush();
synchronized (this) {
super.flush();
try {
if (idsStream != null) {
idsStreamZip.close();

View File

@ -478,10 +478,11 @@ public class LocalSession {
} else {
history.add(0, changeSet);
}
while ((history.size() > MAX_HISTORY_SIZE || (historySize >> 20) > limitMb) && history.size() > 1) {
while (((!Settings.HISTORY.USE_DISK && history.size() > MAX_HISTORY_SIZE) || (historySize >> 20) > limitMb) && history.size() > 1) {
FaweChangeSet item = (FaweChangeSet) history.remove(0);
item.delete();
historySize -= MainUtil.getSize(item);
long size = MainUtil.getSize(item);
historySize -= size;
}
}