improve runInReadActionWithWriteActionPriority, add assertion (IDEA-CR-15454)

This commit is contained in:
peter
2016-11-07 15:05:26 +01:00
parent 3ae90e31bb
commit ec829ba511
3 changed files with 6 additions and 1 deletions
@@ -234,6 +234,8 @@ public abstract class ProgressManager extends ProgressIndicatorProvider {
* <li>action started to execute, but was aborted using {@link ProcessCanceledException} when some other thread initiated
* write action</li>
* </ul>
* If unable to run read action because of interfering write action, this method waits for that write action to complete.
* So under no circumstances must you call this method from read action or under critical locks.
* @since 171.*
*/
public abstract boolean runInReadActionWithWriteActionPriority(@NotNull final Runnable action);
@@ -159,6 +159,9 @@ public class ProgressManagerImpl extends CoreProgressManager implements Disposab
@Override
public boolean runInReadActionWithWriteActionPriority(@NotNull Runnable action) {
if (ApplicationManager.getApplication().isReadAccessAllowed()) {
throw new AssertionError("runInReadActionWithWriteActionPriority shouldn't be invoked from read action");
}
boolean success = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(action);
if (!success) {
ProgressIndicatorUtils.yieldToPendingWriteActions();
@@ -230,7 +230,7 @@ public class ProgressIndicatorUtils {
/**
* Ensure the current EDT activity finishes in case it requires many write actions, with each being delayed a bit
* by background thread read action (until its first checkCanceled call).
* by background thread read action (until its first checkCanceled call). Shouldn't be called from under read action.
*/
public static void yieldToPendingWriteActions() {
ApplicationManager.getApplication().invokeAndWait(EmptyRunnable.INSTANCE, ModalityState.any());