mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Bug 312552 Use ILock rather than scheduling rule for mutual exclusion. Scheduling rules require knowing in advance all scheduling rules clients require.
This commit is contained in:
parent
18f0684dd3
commit
7b265afa4e
1 changed files with 14 additions and 42 deletions
|
@ -60,7 +60,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.core.runtime.jobs.ILock;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
|
||||
public class CfgDiscoveredPathManager implements IResourceChangeListener {
|
||||
|
@ -69,38 +70,8 @@ public class CfgDiscoveredPathManager implements IResourceChangeListener {
|
|||
|
||||
private IDiscoveredPathManager fBaseMngr;
|
||||
|
||||
|
||||
private class GetDiscoveredInfoRunnable implements IWorkspaceRunnable {
|
||||
|
||||
private PathInfo fPathInfo;
|
||||
private ContextInfo fContextInfo;
|
||||
private IProject fProject;
|
||||
private CfgInfoContext fContext;
|
||||
|
||||
public GetDiscoveredInfoRunnable(ContextInfo cInfo, IProject project, CfgInfoContext context) {
|
||||
fContextInfo = cInfo;
|
||||
fProject = project;
|
||||
fContext = context;
|
||||
}
|
||||
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
|
||||
fPathInfo = getCachedPathInfo(fContextInfo);
|
||||
|
||||
if(fPathInfo == null){
|
||||
IDiscoveredPathManager.IDiscoveredPathInfo baseInfo = loadPathInfo(fProject, fContext.getConfiguration(), fContextInfo);
|
||||
|
||||
fPathInfo = resolveCacheBaseDiscoveredInfo(fContextInfo, baseInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PathInfo getPathInfo() {
|
||||
return fPathInfo;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** Deadlock-safe mutex lock */
|
||||
private ILock lock = Job.getJobManager().newLock();
|
||||
|
||||
private static class ContextInfo {
|
||||
|
||||
|
@ -196,16 +167,17 @@ public class CfgDiscoveredPathManager implements IResourceChangeListener {
|
|||
|
||||
PathInfo info = getCachedPathInfo(cInfo);
|
||||
if (info == null) {
|
||||
// Change synchronization to be a lock on the project, otherwise
|
||||
// if the project description is queried from a project change listener, it will deadlock
|
||||
|
||||
GetDiscoveredInfoRunnable runnable = new GetDiscoveredInfoRunnable(cInfo, project, context);
|
||||
ISchedulingRule rule = project;
|
||||
|
||||
ResourcesPlugin.getWorkspace().run(runnable, rule, IWorkspace.AVOID_UPDATE, null);
|
||||
|
||||
info = runnable.getPathInfo();
|
||||
try {
|
||||
lock.acquire();
|
||||
info = getCachedPathInfo(cInfo);
|
||||
|
||||
if(info == null){
|
||||
IDiscoveredPathManager.IDiscoveredPathInfo baseInfo = loadPathInfo(project, context.getConfiguration(), cInfo);
|
||||
info = resolveCacheBaseDiscoveredInfo(cInfo, baseInfo);
|
||||
}
|
||||
} finally {
|
||||
lock.release();
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue