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 @Override
public boolean flush() { public boolean flush() {
super.flush();
synchronized (this) { synchronized (this) {
super.flush();
boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null; boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null;
try { try {
if (osBD != null) { if (osBD != null) {

View File

@ -33,6 +33,8 @@ public abstract class FaweChangeSet implements ChangeSet {
private final World world; private final World world;
private final boolean mainThread;
public static FaweChangeSet getDefaultChangeSet(World world, UUID uuid) { public static FaweChangeSet getDefaultChangeSet(World world, UUID uuid) {
if (Settings.HISTORY.USE_DISK) { if (Settings.HISTORY.USE_DISK) {
return new DiskStorageHistory(world, uuid); return new DiskStorageHistory(world, uuid);
@ -43,6 +45,7 @@ public abstract class FaweChangeSet implements ChangeSet {
public FaweChangeSet(World world) { public FaweChangeSet(World world) {
this.world = world; this.world = world;
this.mainThread = Fawe.get().isMainThread();
} }
public World getWorld() { public World getWorld() {
@ -174,7 +177,7 @@ public abstract class FaweChangeSet implements ChangeSet {
@Override @Override
public void run(final FaweChunk previous, final FaweChunk next) { public void run(final FaweChunk previous, final FaweChunk next) {
waiting.incrementAndGet(); waiting.incrementAndGet();
TaskManager.IMP.async(new Runnable() { Runnable run = new Runnable() {
@Override @Override
public void run() { public void run() {
try { 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 @Override
public boolean flush() { public boolean flush() {
super.flush();
synchronized (this) { synchronized (this) {
super.flush();
try { try {
if (idsStream != null) { if (idsStream != null) {
idsStreamZip.close(); idsStreamZip.close();

View File

@ -478,10 +478,11 @@ public class LocalSession {
} else { } else {
history.add(0, changeSet); 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); FaweChangeSet item = (FaweChangeSet) history.remove(0);
item.delete(); item.delete();
historySize -= MainUtil.getSize(item); long size = MainUtil.getSize(item);
historySize -= size;
} }
} }