1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Fix for 173561, in cooperation with Warren Paul, waiting for the binary runner to stop.

This commit is contained in:
Markus Schorn 2007-02-14 12:54:17 +00:00
parent 3daf0d10d8
commit 6aeb464e1d

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2005, 2006 QNX Software Systems and others. * Copyright (c) 2000, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,8 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Warren Paul (Nokia)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -61,6 +63,9 @@ public class BinaryRunner {
CElementDelta cdelta = new CElementDelta(root); CElementDelta cdelta = new CElementDelta(root);
cdelta.changed(cproj, ICElementDelta.F_CONTENT); cdelta.changed(cproj, ICElementDelta.F_CONTENT);
for (int j = 0; j < containers.length; ++j) { for (int j = 0; j < containers.length; ++j) {
if (fMonitor.isCanceled()) {
return;
}
IParent container = containers[j]; IParent container = containers[j];
ICElement[] children = container.getChildren(); ICElement[] children = container.getChildren();
if (children.length > 0) { if (children.length > 0) {
@ -74,23 +79,20 @@ public class BinaryRunner {
} }
} }
ICProject cproject;
Job runner; private final ICProject cproject;
private final Job runnerJob; // final fields don't need syncronization
private boolean isStopped= false; // access to isStopped must be syncronized.
public BinaryRunner(IProject prj) { public BinaryRunner(IProject prj) {
cproject = CModelManager.getDefault().create(prj); cproject = CModelManager.getDefault().create(prj);
runnerJob= createRunnerJob();
} }
public void start() { private Job createRunnerJob() {
String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1$ String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1$
taskName += " (" + cproject.getElementName() + ")"; //$NON-NLS-1$//$NON-NLS-2$ taskName += " (" + cproject.getElementName() + ")"; //$NON-NLS-1$//$NON-NLS-2$
runner = new Job(taskName) { Job job= new Job(taskName) {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS; IStatus status = Status.OK_STATUS;
try { try {
@ -107,9 +109,10 @@ public class BinaryRunner {
cproject.getProject().accept(new Visitor(monitor), IContainer.INCLUDE_PHANTOMS); cproject.getProject().accept(new Visitor(monitor), IContainer.INCLUDE_PHANTOMS);
if (!monitor.isCanceled()) {
CModelOperation op = new BinaryRunnerOperation(cproject); CModelOperation op = new BinaryRunnerOperation(cproject);
op.runOperation(monitor); op.runOperation(monitor);
}
} }
} catch (CoreException e) { } catch (CoreException e) {
// Ignore the error and just cancel the binary thread // Ignore the error and just cancel the binary thread
@ -121,26 +124,37 @@ public class BinaryRunner {
return status; return status;
} }
}; };
runner.setPriority(Job.LONG); job.setPriority(Job.LONG);
runner.schedule(); return job;
}
public void start() {
synchronized (runnerJob) {
if (!isStopped) {
runnerJob.schedule();
}
}
} }
/** /**
* wrap the wait call and the interrupteException. * wrap the wait call and the interrupteException.
*/ */
public void waitIfRunning() { public void waitIfRunning() {
if (runner != null) {
try { try {
runner.join(); runnerJob.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
}
/**
* Cancels the binary runner and waits until it is stopped.
*/
public void stop() { public void stop() {
if (runner != null && runner.getState() == Job.RUNNING) { synchronized (runnerJob) {
runner.cancel(); isStopped= true; // make sure job is not scheduled afterwards
runnerJob.cancel();
} }
waitIfRunning();
} }
private class Visitor implements IResourceProxyVisitor { private class Visitor implements IResourceProxyVisitor {