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 {
private ICancelable fCancelable;
private boolean canceled;
private volatile boolean canceled;
@Override
public synchronized void setCancelable(ICancelable cancelable) {
fCancelable= cancelable;
checkCanceled();
public void setCancelable(ICancelable cancelable) {
synchronized (this) {
fCancelable= cancelable;
cancelable = getCancelableToCancel();
}
if (cancelable != null)
cancelable.cancel();
}
@Override
public synchronized void setCanceled(boolean canceled) {
this.canceled = canceled;
checkCanceled();
public void setCanceled(boolean canceled) {
ICancelable cancelable;
synchronized (this) {
this.canceled = canceled;
cancelable = getCancelableToCancel();
}
if (cancelable != null)
cancelable.cancel();
}
@Override
public synchronized boolean isCanceled() {
public boolean isCanceled() {
return canceled;
}
private synchronized void checkCanceled() {
if (fCancelable != null && canceled) {
fCancelable.cancel();
/**
* Returns the cancelable to cancel, or {@code null} if there is nothing to 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;
}
return cancelable;
}
}

View file

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