use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class CommitHelper method delegateCommitToVcsThread.
private void delegateCommitToVcsThread(final GeneralCommitProcessor processor) {
final ProgressIndicator indicator = new DelegatingProgressIndicator();
final Semaphore endSemaphore = new Semaphore();
endSemaphore.down();
ChangeListManagerImpl.getInstanceImpl(myProject).executeOnUpdaterThread(new Runnable() {
@Override
public void run() {
indicator.setText("Performing VCS commit...");
try {
ProgressManager.getInstance().runProcess(new Runnable() {
@Override
public void run() {
indicator.checkCanceled();
generalCommit(processor);
}
}, indicator);
} finally {
endSemaphore.up();
}
}
});
indicator.setText("Waiting for VCS background tasks to finish...");
while (!endSemaphore.waitFor(20)) {
indicator.checkCanceled();
}
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ApplicationImplTest method checkPooledThreadsDontGetWrongPrivileges.
private static void checkPooledThreadsDontGetWrongPrivileges() {
ApplicationImpl app = (ApplicationImpl) ApplicationManager.getApplication();
Ref<Future> future = Ref.create();
Disposable disableStderrDumping = Disposer.newDisposable();
LoggedErrorProcessor.getInstance().disableStderrDumping(disableStderrDumping);
Semaphore mayFinish = new Semaphore();
mayFinish.down();
try {
app.executeSuspendingWriteAction(ourProject, "", () -> future.set(app.executeOnPooledThread(() -> assertTrue(mayFinish.waitFor(1000)))));
} catch (AssertionError e) {
if (!isEscapingThreadAssertion(e)) {
e.printStackTrace();
throw e;
}
} finally {
Disposer.dispose(disableStderrDumping);
}
app.executeSuspendingWriteAction(ourProject, "", () -> {
});
mayFinish.up();
waitForFuture(future.get());
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ApplicationImplTest method testCheckCanceledReadAction.
public void testCheckCanceledReadAction() throws Exception {
Semaphore mayStartReadAction = new Semaphore();
mayStartReadAction.down();
ProgressIndicatorBase progress = new ProgressIndicatorBase();
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
mayStartReadAction.waitFor();
ReadAction.run(() -> fail("should be canceled before entering read action"));
}, progress));
WriteAction.run(() -> {
mayStartReadAction.up();
progress.cancel();
future.get(1, TimeUnit.SECONDS);
});
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ApplicationImplTest method testPooledThreadsThatHappenInSuspendedWriteActionStayInSuspendedWriteAction.
public void testPooledThreadsThatHappenInSuspendedWriteActionStayInSuspendedWriteAction() {
LoggedErrorProcessor.getInstance().disableStderrDumping(getTestRootDisposable());
Ref<Future> future = Ref.create();
ApplicationImpl app = (ApplicationImpl) ApplicationManager.getApplication();
safeWrite(() -> {
try {
Semaphore started = new Semaphore();
started.down();
app.executeSuspendingWriteAction(ourProject, "", () -> {
future.set(app.executeOnPooledThread(() -> {
started.up();
TimeoutUtil.sleep(1000);
}));
assertTrue(started.waitFor(1000));
});
fail("should not allow pooled thread to stay there");
} catch (AssertionError e) {
assertTrue(ExceptionUtil.getThrowableText(e), isEscapingThreadAssertion(e));
}
});
waitForFuture(future.get());
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class MavenExecutionTest method execute.
private void execute(final MavenRunnerParameters params) {
final Semaphore sema = new Semaphore();
sema.down();
UIUtil.invokeLaterIfNeeded(() -> MavenRunConfigurationType.runConfiguration(myProject, params, getMavenGeneralSettings(), new MavenRunnerSettings(), new ProgramRunner.Callback() {
@Override
public void processStarted(final RunContentDescriptor descriptor) {
descriptor.getProcessHandler().addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
sema.up();
UIUtil.invokeLaterIfNeeded(() -> Disposer.dispose(descriptor));
}
});
}
}));
sema.waitFor();
}
Aggregations