1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-02 21:23:37 +02:00

Code cleanup.

Change-Id: I9a1945e7633a0f3747a6c33dc62e90d3b76a4e54
This commit is contained in:
Sergey Prigogin 2016-05-27 10:54:57 -07:00
parent a4cd53a926
commit 40b2d17b42
2 changed files with 28 additions and 12 deletions

View file

@ -5,29 +5,44 @@ package org.eclipse.cdt.internal.core.util;
*/ */
public class Canceler implements ICanceler { public class Canceler implements ICanceler {
private ICancelable fCancelable; private ICancelable fCancelable;
private boolean canceled; private volatile boolean canceled;
@Override @Override
public synchronized void setCancelable(ICancelable cancelable) { public void setCancelable(ICancelable cancelable) {
fCancelable= cancelable; synchronized (this) {
checkCanceled(); fCancelable= cancelable;
cancelable = getCancelableToCancel();
}
if (cancelable != null)
cancelable.cancel();
} }
@Override @Override
public synchronized void setCanceled(boolean canceled) { public void setCanceled(boolean canceled) {
this.canceled = canceled; ICancelable cancelable;
checkCanceled(); synchronized (this) {
this.canceled = canceled;
cancelable = getCancelableToCancel();
}
if (cancelable != null)
cancelable.cancel();
} }
@Override @Override
public synchronized boolean isCanceled() { public boolean isCanceled() {
return canceled; return canceled;
} }
private synchronized void checkCanceled() { /**
if (fCancelable != null && canceled) { * Returns the cancelable to cancel, or {@code null} if there is nothing to cancel.
fCancelable.cancel(); * Sets {@link #fCancelable} to {@code null}. Has to be called from a synchronized block.
*/
private ICancelable getCancelableToCancel() {
ICancelable cancelable = null;
if (canceled) {
cancelable = fCancelable;
fCancelable= null; fCancelable= null;
} }
return cancelable;
} }
} }

View file

@ -333,6 +333,7 @@ public abstract class PDOMWriter implements IPDOMASTProcessor {
} }
} }
} }
} catch (OperationCanceledException e) {
} catch (RuntimeException | StackOverflowError | AssertionError e) { } catch (RuntimeException | StackOverflowError | AssertionError e) {
th= e; th= e;
} finally { } finally {
@ -494,7 +495,7 @@ public abstract class PDOMWriter implements IPDOMASTProcessor {
if (cancelationCheckThrottler <= 0) { if (cancelationCheckThrottler <= 0) {
if (fCancelState.isCanceled()) if (fCancelState.isCanceled())
throw new OperationCanceledException(); throw new OperationCanceledException();
cancelationCheckThrottler = 1000; cancelationCheckThrottler = 100;
} else { } else {
cancelationCheckThrottler--; cancelationCheckThrottler--;
} }