[^cdr] fix data race in DumbService.runWhenSmart

This commit is contained in:
peter
2015-11-06 16:48:32 +01:00
parent 1d9b58e0fb
commit a41bf5475d
2 changed files with 14 additions and 8 deletions
@@ -64,7 +64,9 @@ public abstract class DumbService {
}
/**
* 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);
@@ -151,14 +151,14 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica
@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) {
@@ -220,7 +220,9 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica
application.runWriteAction(new Runnable() {
@Override
public void run() {
myDumb = true;
synchronized (myRunWhenSmartQueue) {
myDumb = true;
}
myDumbStart = trace;
myModificationCount++;
try {
@@ -286,7 +288,9 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica
}
private void updateFinished(boolean modal) {
myDumb = false;
synchronized (myRunWhenSmartQueue) {
myDumb = false;
}
myDumbStart = null;
myModificationCount++;
if (myProject.isDisposed()) return;