void (@NotNull ProgressIndicator indicator) { myIndicator = indicator; myIndicator.setIndeterminate(false); myBuildViewService.onStart(mySessionId, myStartCompilationStamp, myRestartWork, indicator); Semaphore semaphore = ((CompilerManagerImpl)CompilerManager.getInstance(myProject)).getCompilationSemaphore(); boolean acquired = false; try { try { while (!acquired) { acquired = semaphore.tryAcquire(300, TimeUnit.MILLISECONDS); if (!acquired && !myWaitForPreviousSession) { return; } if (indicator.isCanceled()) { // give up obtaining the semaphore, // let compile work begin in order to stop gracefuly on cancel event break; } } } catch (InterruptedException ignored) { } if (!isHeadless()) { addIndicatorDelegate(); } myCompileWork.run(); } catch (ProcessCanceledException ignored) { } finally { try { indicator.stop(); myBuildViewService.onEnd(mySessionId, myExitStatus, myEndCompilationStamp); } finally { if (acquired) { semaphore.release(); } } } }