1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

Bug 224707 - PathEntryManager inefficient usage of jobs

This commit is contained in:
Vivian Kong 2008-07-25 14:48:10 +00:00
parent ec58119cbe
commit 849ac074a6

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,6 +9,7 @@
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@ -19,6 +20,7 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
@ -60,6 +62,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@ -119,9 +122,25 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
private Map<IProject, IPathEntryStore> storeMap = new HashMap<IProject, IPathEntryStore>();
private static PathEntryManager pathEntryManager;
protected ConcurrentLinkedQueue<PathEntryProblem> markerProblems = new ConcurrentLinkedQueue<PathEntryProblem>();
//Setting up a generate markers job, it does not get scheduled
Job markerTask = new GenerateMarkersJob("PathEntry Marker Job"); //$NON-NLS-1$
private PathEntryManager() {
}
private class PathEntryProblem {
IProject project;
ICModelStatus[] problems;
public PathEntryProblem(IProject project, ICModelStatus[] problems) {
this.project = project;
this.problems = problems;
}
}
private class PathEntryContainerLock implements IPathEntryContainer {
boolean runInitializer;
@ -585,7 +604,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
problemList.toArray(problems);
IProject project = cproject.getProject();
if (PathEntryUtil.hasPathEntryProblemMarkersChange(project, problems)) {
generateMarkers(project, problems);
addProblemMarkers(project, problems);
}
}
@ -994,40 +1013,38 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
}
public void generateMarkers(final IProject project, final ICModelStatus[] problems) {
Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
CCorePlugin.getWorkspace().run(new IWorkspaceRunnable() {
/* (non-Javadoc)
* @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor mon) throws CoreException {
PathEntryUtil.flushPathEntryProblemMarkers(project);
for (int i = 0; i < problems.length; ++i) {
PathEntryUtil.createPathEntryProblemMarker(project, problems[i]);
}
}
}, null);
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
};
ISchedulingRule rule = project.getWorkspace().getRuleFactory().markerRule(project);
markerTask.setRule(rule);
/**
* Collects path entry errors for each project and generate error markers for these errors
* @param project - Project with path entry errors
* @param problems - The path entry errors associated with the project
*/
public void addProblemMarkers(final IProject project, final ICModelStatus[] problems) {
PathEntryProblem problem = new PathEntryProblem(project, problems);
//queue up the problems to be logged
markerProblems.add(problem);
//generate the error markers
markerTask.schedule();
}
private class GenerateMarkersJob extends WorkspaceJob {
public GenerateMarkersJob(String name) {
super(name);
}
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
while (markerProblems.peek() != null) {
PathEntryProblem problem = markerProblems.poll();
IProject project = problem.project;
ICModelStatus[] problems = problem.problems;
PathEntryUtil.flushPathEntryProblemMarkers(project);
for (int i = 0; i < problems.length; ++i) {
PathEntryUtil.createPathEntryProblemMarker(project, problems[i]);
}
}
return Status.OK_STATUS;
}
}
private boolean needDelta(ICProject cproject){
try {
@ -1337,7 +1354,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ICModelStatus[] problems = new ICModelStatus[problemList.size()];
problemList.toArray(problems);
if (PathEntryUtil.hasPathEntryProblemMarkersChange(project, problems)) {
generateMarkers(project, problems);
addProblemMarkers(project, problems);
}
}
} catch (CoreException e) {