Fix bug 12139: don't launch multiple 'save indexer cache' jobs at once. Also, just in case, always ignore .cproject as a resource that can trigger rebuilding configuration data.
authorEd Swartz <ed.swartz@nokia.com>
Tue, 21 Sep 2010 11:35:22 -0500
changeset 2083 8a7ea8bb2e31
parent 2077 d930aa7f4428
child 2084 588b26a6b387
Fix bug 12139: don't launch multiple 'save indexer cache' jobs at once. Also, just in case, always ignore .cproject as a resource that can trigger rebuilding configuration data.
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildManager.java
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideLanguageData.java
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildManager.java	Mon Sep 20 18:51:12 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildManager.java	Tue Sep 21 11:35:22 2010 -0500
@@ -443,6 +443,9 @@
 				resourceChangedListener.addResource(wsPath, handler);
 			}
 		}
+		
+		// make sure .cproject itself is never accidentally listened to (possible cause in bug 12139)
+		resourceChangedListener.removeResource(new Path(cpi.getProject().getName()).append(".cproject"), handler);
 	}
 
 	public void installedSdkChanged(SDKChangeEventType eventType) {
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideLanguageData.java	Mon Sep 20 18:51:12 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideLanguageData.java	Tue Sep 21 11:35:22 2010 -0500
@@ -95,6 +95,7 @@
 
 	private final String ENTRY_DELIMTER = ";"; //$NON-NLS-1$
 	private final String LOCAL_MARKER = "[LOCAL]"; //$NON-NLS-1$
+	private Job persistCacheJob;
 
 
 	public CarbideLanguageData(ICarbideBuildConfiguration config) {
@@ -154,24 +155,34 @@
 			// But we must save the cache in a workspace job because this code
 			// is usually called when the project description is being read for 
 			// the first time (thus saving just throws an exception).
-			Job job = new Job("Saving Carbide indexer cache for " + carbideBuildConfig.toString()) {
-
-				@Override
-				protected IStatus run(IProgressMonitor monitor) {
-					persistCache(monitor);
-					
-					return Status.OK_STATUS;
+			
+			// Bug 12139: oops, this job was running over and over again without end
+			synchronized (this) {
+				if (persistCacheJob == null) {
+					persistCacheJob = new Job("Saving Carbide indexer cache for " + carbideBuildConfig.toString()) {
+		
+						@Override
+						protected IStatus run(IProgressMonitor monitor) {
+							persistCache(monitor);
+							
+							return Status.OK_STATUS;
+						}
+						
+					};
+					persistCacheJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
+					persistCacheJob.setSystem(true);
+					persistCacheJob.setPriority(Job.LONG);
 				}
-				
-			};
-			job.setRule(ResourcesPlugin.getWorkspace().getRoot());
-			job.setSystem(true);
-			job.setPriority(Job.LONG);
-			job.schedule(5000);	
-				// This scheduling delay is a gross HACK: WorkspaceModelProvider#saveStorage()
-				// has had and still has problems with deadlocks on saving
-				// model content.  This job exacerbates it unless we wait a
-				// while before locking the workspace.
+			
+				// don't reschedule if it has not run yet
+				if (persistCacheJob.getResult() == null || persistCacheJob.getState() == Job.NONE) {
+					persistCacheJob.schedule(5000);	
+					// This scheduling delay is a gross HACK: WorkspaceModelProvider#saveStorage()
+					// has had and still has problems with deadlocks on saving
+					// model content.  This job exacerbates it unless we wait a
+					// while before locking the workspace.
+				}
+			}
 		}
 
 		switch(kind) {