1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-03 05:33:33 +02:00

Make sure to run the PathEntryContainerInitializer.initialize()

once.
	* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
This commit is contained in:
Alain Magloire 2004-06-09 21:45:03 +00:00
parent e8e773e868
commit 8e45e1973c
2 changed files with 64 additions and 31 deletions

View file

@ -1,3 +1,9 @@
2004-06-09 Alain Magloire
Make sure to run the PathEntryContainerInitializer.initialize()
once.
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
2004-06-09 Hoda Amer 2004-06-09 Hoda Amer
Fix for PR 62656 : [Saving] a cpp file after copying/renaming a function in front of a constructor locks Eclipse Fix for PR 62656 : [Saving] a cpp file after copying/renaming a function in front of a constructor locks Eclipse

View file

@ -93,6 +93,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
private class PathEntryContainerLock implements IPathEntryContainer { private class PathEntryContainerLock implements IPathEntryContainer {
boolean runInitializer;
public boolean isContainerInitialize() {
return runInitializer;
}
public void setContainerInitialize(boolean init) {
runInitializer = init;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries() * @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries()
*/ */
@ -113,8 +123,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public IPath getPath() { public IPath getPath() {
return Path.EMPTY; return Path.EMPTY;
} }
} }
/** /**
* Return the singleton. * Return the singleton.
*/ */
@ -504,39 +514,51 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
// Try the cache. // Try the cache.
IPathEntryContainer container = containerGet(project, containerPath); IPathEntryContainer container = containerGet(project, containerPath);
if (container instanceof PathEntryContainerLock) { if (container instanceof PathEntryContainerLock) {
synchronized(container) { boolean runInitializer = false;
IPathEntryContainer newContainer = containerGet(project, containerPath); PathEntryContainerLock lock = (PathEntryContainerLock)container;
if (newContainer == container) { synchronized(lock) {
// remove the lock. if (!lock.isContainerInitialize()) {
final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0)); runInitializer = true;
if (initializer != null) { lock.setContainerInitialize(runInitializer);
final boolean[] ok = {true}; } else {
// wrap initializer call with Safe runnable in case // Wait for the inialization to finish.
// initializer would be while(containerGet(project, containerPath) instanceof PathEntryContainerLock) {
// causing some grief try {
Platform.run(new ISafeRunnable() { lock.wait();
} catch (InterruptedException e) {
public void handleException(Throwable exception) { //e.printStackTrace();
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR,
"Exception occurred in container initializer: "+initializer, exception); //$NON-NLS-1$
CCorePlugin.log(status);
ok[0] = false;
}
public void run() throws Exception {
initializer.initialize(containerPath, project);
}
});
// retrieve value (if initialization was successful)
container = containerGet(project, containerPath);
if (!ok[0]) {
containerPut(project, containerPath, null); // flush
} }
} }
} else {
container = newContainer;
} }
} }
if (runInitializer) {
// remove the lock.
final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0));
if (initializer != null) {
final boolean[] ok = {true};
// wrap initializer call with Safe runnable in case
// initializer would be
// causing some grief
Platform.run(new ISafeRunnable() {
public void handleException(Throwable exception) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR,
"Exception occurred in container initializer: "+initializer, exception); //$NON-NLS-1$
CCorePlugin.log(status);
ok[0] = false;
}
public void run() throws Exception {
initializer.initialize(containerPath, project);
}
});
if (!ok[0]) {
containerPut(project, containerPath, null); // flush and notify
}
}
}
// retrieve new value
container = containerGet(project, containerPath);
} }
return container; return container;
} }
@ -601,7 +623,12 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
projectContainers = new HashMap(); projectContainers = new HashMap();
Containers.put(cproject, projectContainers); Containers.put(cproject, projectContainers);
} }
projectContainers.put(containerPath, container); IPathEntryContainer oldContainer = (IPathEntryContainer)projectContainers.put(containerPath, container);
if (oldContainer instanceof PathEntryContainerLock) {
synchronized (oldContainer) {
oldContainer.notifyAll();
}
}
} }
private synchronized void containerRemove(ICProject cproject) { private synchronized void containerRemove(ICProject cproject) {