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,12 +473,14 @@ 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) {
synchronized(container) {
IPathEntryContainer newContainer = containerGet(project, containerPath);
if (newContainer == container) {
// remove the lock.
final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0)); final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0));
if (initializer != null) { if (initializer != null) {
containerPut(project, containerPath, container); final boolean[] ok = {true};
boolean ok = false;
try {
// wrap initializer call with Safe runnable in case // wrap initializer call with Safe runnable in case
// initializer would be // initializer would be
// causing some grief // causing some grief
@ -464,6 +490,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
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 {
@ -472,13 +499,13 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}); });
// retrieve value (if initialization was successful) // retrieve value (if initialization was successful)
container = containerGet(project, containerPath); container = containerGet(project, containerPath);
ok = true; if (!ok[0]) {
} finally {
if (!ok) {
containerPut(project, containerPath, null); // flush containerPut(project, containerPath, null); // flush
// cache
} }
} }
} else {
container = newContainer;
}
} }
} }
return container; return container;
@ -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;