}
/**
- * Executes the runnable immediately if not in dumb mode, or on AWT Event Dispatch thread when the dumb mode ends.
+ * Executes the runnable immediately if not in dumb mode, or on AWT Event Dispatch thread after the dumb mode ends.
+ * Note that it's not guaranteed that the dumb mode won't start again during this runnable execution, it should manage that situation explicitly
+ * (e.g. by starting a read action; it's still necessary to check isDumb inside the read action).
* @param runnable runnable to run
*/
public abstract void runWhenSmart(@NotNull Runnable runnable);
@Override
public void runWhenSmart(@NotNull Runnable runnable) {
- if (!isDumb()) {
- runnable.run();
- }
- else {
- synchronized (myRunWhenSmartQueue) {
+ synchronized (myRunWhenSmartQueue) {
+ if (isDumb()) {
myRunWhenSmartQueue.addLast(runnable);
+ return;
}
}
+
+ runnable.run();
}
private void scheduleCacheUpdate(@NotNull final DumbModeTask task, boolean forceDumbMode) {
application.runWriteAction(new Runnable() {
@Override
public void run() {
- myDumb = true;
+ synchronized (myRunWhenSmartQueue) {
+ myDumb = true;
+ }
myDumbStart = trace;
myModificationCount++;
try {
}
private void updateFinished(boolean modal) {
- myDumb = false;
+ synchronized (myRunWhenSmartQueue) {
+ myDumb = false;
+ }
myDumbStart = null;
myModificationCount++;
if (myProject.isDisposed()) return;