Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] CDT 2_0 Version: Indexer patch for Bug 51232


This patch adds a layer of separation between the indexer and the parser by running the parser in its own thread. This allows the indexer to finish all jobs regardless of the individual parser outcomes. Also fixed a potential EOF bug while reading stored indexes.

This patch is for the head branch.


 Test Suite on Windows.

- Bogdan


Index: index/ChangeLog
===================================================================
retrieving revision 1.28
diff -u -r1.28 ChangeLog
--- index/ChangeLog	3 Feb 2004 16:04:41 -0000	1.28
+++ index/ChangeLog	10 Feb 2004 17:46:10 -0000
@@ -1,3 +1,17 @@
+2004-02-09 Bogdan Gheorghe
+	PR 51232
+	
+	- Added a layer of separation between the parser and the indexer: we now
+	  create a worker thread to run the parser in. This allows the indexer to 
+	  finish all scheduled jobs regardless of how the parser performs on
+	  individual files (i.e. indexing no longer affected by parser failures)
+	  
+	- Modified some of the stored index block reading routines to use separate
+	  counters, thus avoiding potential EOF exceptions.
+	  
+    * index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
+	* index/org/eclipse/cdt/internal/core/index/search/indexing/SourceIndexer.java
+	
 2004-02-03 Alain Magloire
 
 	PR 51106                                                                                                                   
Index: index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
===================================================================
retrieving revision 1.4
diff -u -r1.4 BlocksIndexInput.java
--- index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java	26 Sep 2003 17:53:31 -0000	1.4
+++ index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java	10 Feb 2004 17:46:11 -0000
@@ -30,6 +30,7 @@
 	protected FileListBlock currentFileListBlock;
 	protected int currentFileListBlockNum;
 	protected int currentIndexBlockNum;
+	protected int currentIncludeBlockNum;
 	protected IndexBlock currentIndexBlock;
 	protected IndexBlock currentIncludeIndexBlock;
 	private RandomAccessFile raf;
@@ -408,7 +409,7 @@
 		//if end of the current block, we load the next one.
 		boolean endOfBlock= !currentIncludeIndexBlock.nextEntry(currentIncludeEntry);
 		if (endOfBlock) {
-			currentIncludeIndexBlock= getIndexBlock(++currentIndexBlockNum);
+			currentIncludeIndexBlock= getIndexBlock(++currentIncludeBlockNum);
 			currentIncludeIndexBlock.nextEntry(currentWordEntry);
 		}
 	}
@@ -418,8 +419,8 @@
 	protected void setFirstInclude() throws IOException {
 		includePosition= 1;
 		if (getNumIncludes() > 0) {
-			currentIndexBlockNum= summary.getFirstIncludeBlockNum();
-			currentIncludeIndexBlock= getIndexBlock(currentIndexBlockNum);
+			currentIncludeBlockNum= summary.getFirstIncludeBlockNum();
+			currentIncludeIndexBlock= getIndexBlock(currentIncludeBlockNum);
 			currentIncludeEntry= new IncludeEntry(0);
 			currentIncludeIndexBlock.reset();
 			currentIncludeIndexBlock.nextEntry(currentIncludeEntry);
Index: index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
===================================================================
retrieving revision 1.16
diff -u -r1.16 SourceIndexer.java
--- index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java	27 Jan 2004 01:21:18 -0000	1.16
+++ index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java	10 Feb 2004 17:46:11 -0000
@@ -97,7 +97,18 @@
 		{
 		}
 		
-		boolean retVal = parser.parse();
+		ParserRunner p = new ParserRunner(parser);
+		Thread t = new Thread(p, "CDT Indexer Parser Runner");
+		t.start();
+		
+		try{
+			t.join();
+		}
+		catch (InterruptedException e){
+			org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Runner InterruptedException - file: " + resourceFile.getFullPath(), ICLogConstants.CDT);
+		}
+		
+		boolean retVal = p.getResult();
 		
 		if (!retVal)
 			org.eclipse.cdt.internal.core.model.Util.log(null, "Failed to index " + resourceFile.getFullPath(), ICLogConstants.CDT);
@@ -119,5 +130,27 @@
 	 */
 	public IFile getResourceFile() {
 		return resourceFile;
+	}
+	
+	class ParserRunner implements Runnable {
+		IParser parser;
+		boolean retVal;
+		ParserRunner(IParser parser){
+			this.parser = parser;
+		}
+		/* (non-Javadoc)
+		 * @see java.lang.Runnable#run()
+		 */
+		public void run() {
+			try{
+				retVal=parser.parse();
+			}
+			catch (Exception e){
+				org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Runner Exception " + resourceFile.getFullPath() + " Message: " + e.getMessage(), ICLogConstants.CDT);
+			}
+		}
+		
+		boolean getResult(){ return retVal;}
+		
 	}
 }

Back to the top