From 8e45e1973c8903bcf61703fcd2065c5d04d0c885 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Wed, 9 Jun 2004 21:45:03 +0000 Subject: [PATCH] Make sure to run the PathEntryContainerInitializer.initialize() once. * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java --- core/org.eclipse.cdt.core/ChangeLog | 6 ++ .../internal/core/model/PathEntryManager.java | 89 ++++++++++++------- 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index d4b1a2475d1..378a1707a0c 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 Fix for PR 62656 : [Saving] a cpp file after copying/renaming a function in front of a constructor locks Eclipse diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index d83fea1f93f..95daa4a38e5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -93,6 +93,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange private class PathEntryContainerLock implements IPathEntryContainer { + boolean runInitializer; + + public boolean isContainerInitialize() { + return runInitializer; + } + + public void setContainerInitialize(boolean init) { + runInitializer = init; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries() */ @@ -113,8 +123,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange public IPath getPath() { return Path.EMPTY; } - } + /** * Return the singleton. */ @@ -504,39 +514,51 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange // Try the cache. IPathEntryContainer container = containerGet(project, containerPath); if (container instanceof PathEntryContainerLock) { - synchronized(container) { - IPathEntryContainer newContainer = containerGet(project, containerPath); - if (newContainer == container) { - // 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); - } - }); - // retrieve value (if initialization was successful) - container = containerGet(project, containerPath); - if (!ok[0]) { - containerPut(project, containerPath, null); // flush + boolean runInitializer = false; + PathEntryContainerLock lock = (PathEntryContainerLock)container; + synchronized(lock) { + if (!lock.isContainerInitialize()) { + runInitializer = true; + lock.setContainerInitialize(runInitializer); + } else { + // Wait for the inialization to finish. + while(containerGet(project, containerPath) instanceof PathEntryContainerLock) { + try { + lock.wait(); + } catch (InterruptedException e) { + //e.printStackTrace(); } } - } 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; } @@ -601,7 +623,12 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange projectContainers = new HashMap(); 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) {