Fixed tests broken due to the flush() call buffering and not executing

immediately
This commit is contained in:
dragonmacher 2020-12-11 17:29:12 -05:00
parent 422d41dd53
commit e4fac450f0
2 changed files with 25 additions and 32 deletions

View file

@ -18,7 +18,7 @@ package ghidra.util.task;
import javax.swing.Timer;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
import ghidra.util.Swing;
import ghidra.util.datastruct.WeakDataStructureFactory;
import ghidra.util.datastruct.WeakSet;
import utilities.util.reflection.ReflectionUtilities;
@ -67,9 +67,9 @@ public abstract class AbstractSwingUpdateManager {
private final String name;
private String inceptionInformation;
protected long requestTime = NONE;
protected long bufferingStartTime;
protected boolean disposed = false;
private long requestTime = NONE;
private long bufferingStartTime;
private boolean disposed = false;
// This is true when work has begun and is not finished. This is only mutated on the
// Swing thread, but is read by other threads.
@ -148,7 +148,7 @@ public abstract class AbstractSwingUpdateManager {
}
requestTime = System.currentTimeMillis();
SystemUtilities.runSwingLater(this::checkForWork);
Swing.runLater(this::checkForWork);
}
/**
@ -175,19 +175,33 @@ public abstract class AbstractSwingUpdateManager {
return;
}
// force an update by disabling buffering with a new request
requestTime = System.currentTimeMillis();
bufferingStartTime = NONE; // set so that the max delay check will trigger work
}
SystemUtilities.runSwingNow(this::checkForWork);
Swing.runNow(this::checkForWork);
}
/**
* Causes this run manager to run if it has a pending update
*/
public void flush() {
if (hasPendingUpdates()) {
SystemUtilities.runSwingNow(this::checkForWork);
synchronized (this) {
if (disposed) {
return;
}
if (!hasPendingUpdates()) {
return;
}
// force an update by disabling buffering with a new request
requestTime = System.currentTimeMillis();
bufferingStartTime = NONE; // set so that the max delay check will trigger work
}
Swing.runNow(this::checkForWork);
}
/**

View file

@ -15,8 +15,6 @@
*/
package ghidra.util.task;
import ghidra.util.Swing;
/**
* A class to allow clients to buffer events. UI components may receive numbers events to make
* changes to their underlying data model. Further, for many of these clients, it is sufficient
@ -116,12 +114,7 @@ public class SwingUpdateManager extends AbstractSwingUpdateManager {
*/
@Override
public synchronized void update() {
if (disposed) {
return;
}
requestTime = System.currentTimeMillis();
Swing.runLater(this::checkForWork);
super.update();
}
/**
@ -130,13 +123,7 @@ public class SwingUpdateManager extends AbstractSwingUpdateManager {
*/
@Override
public synchronized void updateLater() {
if (disposed) {
return;
}
requestTime = System.currentTimeMillis();
bufferingStartTime = bufferingStartTime == NONE ? requestTime : bufferingStartTime;
scheduleCheckForWork();
super.updateLater();
}
/**
@ -145,15 +132,7 @@ public class SwingUpdateManager extends AbstractSwingUpdateManager {
*/
@Override
public void updateNow() {
synchronized (this) {
if (disposed) {
return;
}
requestTime = System.currentTimeMillis();
bufferingStartTime = NONE; // set so that the max delay check will trigger work
}
Swing.runLater(this::checkForWork);
super.updateNow();
}
}