1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Synchronized the retrieving of the PathEntryContainer

This commit is contained in:
Alain Magloire 2004-06-07 20:43:13 +00:00
parent 0b171d56e4
commit 97ade06599

View file

@ -90,6 +90,30 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
private PathEntryManager() { private PathEntryManager() {
} }
private class PathEntryContainerLock implements IPathEntryContainer {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries()
*/
public IPathEntry[] getPathEntries() {
return NO_PATHENTRIES;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getDescription()
*/
public String getDescription() {
return new String("Lock container"); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPath()
*/
public IPath getPath() {
return Path.EMPTY;
}
}
/** /**
* Return the singleton. * Return the singleton.
*/ */
@ -449,35 +473,38 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public IPathEntryContainer getPathEntryContainer(final IPath containerPath, final ICProject project) throws CModelException { public IPathEntryContainer getPathEntryContainer(final IPath containerPath, final ICProject project) throws CModelException {
// Try the cache. // Try the cache.
IPathEntryContainer container = containerGet(project, containerPath); IPathEntryContainer container = containerGet(project, containerPath);
if (container == null) { if (container instanceof PathEntryContainerLock) {
final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0)); synchronized(container) {
if (initializer != null) { IPathEntryContainer newContainer = containerGet(project, containerPath);
containerPut(project, containerPath, container); if (newContainer == container) {
boolean ok = false; // remove the lock.
try { final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0));
// wrap initializer call with Safe runnable in case if (initializer != null) {
// initializer would be final boolean[] ok = {true};
// causing some grief // wrap initializer call with Safe runnable in case
Platform.run(new ISafeRunnable() { // initializer would be
// causing some grief
Platform.run(new ISafeRunnable() {
public void handleException(Throwable exception) { public void handleException(Throwable exception) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR,
"Exception occurred in container initializer: "+initializer, exception); //$NON-NLS-1$ "Exception occurred in container initializer: "+initializer, exception); //$NON-NLS-1$
CCorePlugin.log(status); CCorePlugin.log(status);
} ok[0] = false;
}
public void run() throws Exception { public void run() throws Exception {
initializer.initialize(containerPath, project); initializer.initialize(containerPath, project);
}
});
// retrieve value (if initialization was successful)
container = containerGet(project, containerPath);
if (!ok[0]) {
containerPut(project, containerPath, null); // flush
} }
});
// retrieve value (if initialization was successful)
container = containerGet(project, containerPath);
ok = true;
} finally {
if (!ok) {
containerPut(project, containerPath, null); // flush
// cache
} }
} else {
container = newContainer;
} }
} }
} }
@ -531,6 +558,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (projectContainers == null) { if (projectContainers == null) {
projectContainers = new HashMap(); projectContainers = new HashMap();
Containers.put(cproject, projectContainers); Containers.put(cproject, projectContainers);
// Initialize the first time with a lock
projectContainers.put(containerPath, new PathEntryContainerLock());
} }
IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath); IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath);
return container; return container;