Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 287907 | Differences between
and this patch

Collapse All | Expand All

(-)parser/org/eclipse/cdt/core/index/IIndex.java (+7 lines)
Lines 9-14 Link Here
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Andrew Ferguson (Symbian)
10
 *    Andrew Ferguson (Symbian)
11
 *    Bryan Wilkinson (QNX)
11
 *    Bryan Wilkinson (QNX)
12
 *    Sergey Prigogin (Google)
12
 *******************************************************************************/ 
13
 *******************************************************************************/ 
13
package org.eclipse.cdt.core.index;
14
package org.eclipse.cdt.core.index;
14
15
Lines 92-97 Link Here
92
	public void releaseReadLock();
93
	public void releaseReadLock();
93
	
94
	
94
	/**
95
	/**
96
	 * @return <code>true</code> if there are threads waiting for read locks.
97
	 * @since 5.2
98
	 */
99
	public boolean hasWaitingReaders();
100
101
	/**
95
	 * Returns a timestamp of when the index was last written to. This can
102
	 * Returns a timestamp of when the index was last written to. This can
96
	 * be used to figure out whether information read from the index is 
103
	 * be used to figure out whether information read from the index is 
97
	 * still reliable or not.
104
	 * still reliable or not.
(-)parser/org/eclipse/cdt/internal/core/index/CIndex.java (+10 lines)
Lines 10-15 Link Here
10
 *    Bryan Wilkinson (QNX)
10
 *    Bryan Wilkinson (QNX)
11
 *    Andrew Ferguson (Symbian)
11
 *    Andrew Ferguson (Symbian)
12
 *    Anton Leherbauer (Wind River Systems)
12
 *    Anton Leherbauer (Wind River Systems)
13
 *    Sergey Prigogin (Google)
13
 *******************************************************************************/ 
14
 *******************************************************************************/ 
14
package org.eclipse.cdt.internal.core.index;
15
package org.eclipse.cdt.internal.core.index;
15
16
Lines 355-360 Link Here
355
		return fReadLock;
356
		return fReadLock;
356
	}
357
	}
357
358
359
	public boolean hasWaitingReaders() {
360
		for (int i= 0; i < fFragments.length; i++) {
361
			if (fFragments[i].hasWaitingReaders()) {
362
				return true;
363
			}
364
		}
365
		return false;
366
	}
367
358
	public long getLastWriteAccess() {
368
	public long getLastWriteAccess() {
359
		long result= 0;
369
		long result= 0;
360
		for (int i = 0; i < fFragments.length; i++) {
370
		for (int i = 0; i < fFragments.length; i++) {
(-)parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java (+5 lines)
Lines 9-14 Link Here
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Bryan Wilkinson (QNX)
10
 *    Bryan Wilkinson (QNX)
11
 *    Andrew Ferguson (Symbian)
11
 *    Andrew Ferguson (Symbian)
12
 *    Sergey Prigogin (Google)
12
 *******************************************************************************/ 
13
 *******************************************************************************/ 
13
14
14
package org.eclipse.cdt.internal.core.index;
15
package org.eclipse.cdt.internal.core.index;
Lines 85-90 Link Here
85
	public void releaseReadLock() {
86
	public void releaseReadLock() {
86
	}
87
	}
87
88
89
	public boolean hasWaitingReaders() {
90
		return false;
91
	}
92
88
	public long getLastWriteAccess() {
93
	public long getLastWriteAccess() {
89
		return 0;
94
		return 0;
90
	}
95
	}
(-)parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java (+6 lines)
Lines 9-14 Link Here
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Bryan Wilkinson (QNX)
10
 *    Bryan Wilkinson (QNX)
11
 *    Andrew Ferguson (Symbian)
11
 *    Andrew Ferguson (Symbian)
12
 *    Sergey Prigogin (Google)
12
 *******************************************************************************/ 
13
 *******************************************************************************/ 
13
package org.eclipse.cdt.internal.core.index;
14
package org.eclipse.cdt.internal.core.index;
14
15
Lines 191-196 Link Here
191
	void releaseReadLock();
192
	void releaseReadLock();
192
	
193
	
193
	/**
194
	/**
195
	 * @return <code>true</code> if there are threads waiting for read locks.
196
	 */
197
	public boolean hasWaitingReaders();
198
199
	/**
194
	 * Returns the timestamp of the last modification to the index.
200
	 * Returns the timestamp of the last modification to the index.
195
	 */
201
	 */
196
	long getLastWriteAccess();
202
	long getLastWriteAccess();
(-)parser/org/eclipse/cdt/internal/core/index/IWritableIndex.java (-2 / +18 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Andrew Ferguson (Symbian)
10
 *    Andrew Ferguson (Symbian)
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/ 
12
 *******************************************************************************/ 
12
13
13
package org.eclipse.cdt.internal.core.index;
14
package org.eclipse.cdt.internal.core.index;
Lines 21-26 Link Here
21
import org.eclipse.cdt.core.index.IIndexFile;
22
import org.eclipse.cdt.core.index.IIndexFile;
22
import org.eclipse.cdt.core.index.IIndexFileLocation;
23
import org.eclipse.cdt.core.index.IIndexFileLocation;
23
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
24
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
25
import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock;
24
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.CoreException;
25
27
26
/**
28
/**
Lines 65-71 Link Here
65
	/**
67
	/**
66
	 * Creates a file object for the given location or returns an existing one.
68
	 * Creates a file object for the given location or returns an existing one.
67
	 */
69
	 */
68
	IIndexFragmentFile addFile(int linkageID, IIndexFileLocation fileLocation) throws CoreException;
70
	IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location) throws CoreException;
71
72
	/**
73
	 * Creates a uncommitted file object for the given location.
74
	 */
75
	IIndexFragmentFile addUncommittedFile(int linkageID, IIndexFileLocation location) throws CoreException;
76
77
	/**
78
	 * Makes an uncommitted file that was created earlier by calling
79
	 * {@link #addUncommittedFile(int, IIndexFileLocation)} method visible in the index.
80
	 *
81
	 * @return The file that was updated.
82
	 * @throws CoreException
83
	 */
84
	IIndexFragmentFile commitUncommittedFile() throws CoreException;
69
85
70
	/**
86
	/**
71
	 * Adds content to the given file.
87
	 * Adds content to the given file.
Lines 73-79 Link Here
73
	void setFileContent(IIndexFragmentFile sourceFile, 
89
	void setFileContent(IIndexFragmentFile sourceFile, 
74
			int linkageID, IncludeInformation[] includes, 
90
			int linkageID, IncludeInformation[] includes, 
75
			IASTPreprocessorStatement[] macros, IASTName[][] names,
91
			IASTPreprocessorStatement[] macros, IASTName[][] names,
76
			ASTFilePathResolver resolver) throws CoreException;
92
			ASTFilePathResolver resolver, YieldableIndexLock lock) throws CoreException, InterruptedException;
77
93
78
	/**
94
	/**
79
	 * Clears the entire index.
95
	 * Clears the entire index.
(-)parser/org/eclipse/cdt/internal/core/index/IWritableIndexFragment.java (-7 / +27 lines)
Lines 8-14 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Andrew Ferguson (Symbian)
10
 *    Andrew Ferguson (Symbian)
11
 *******************************************************************************/ 
11
 *    Sergey Prigogin (Google)
12
******************************************************************************/ 
12
13
13
package org.eclipse.cdt.internal.core.index;
14
package org.eclipse.cdt.internal.core.index;
14
15
Lines 19-24 Link Here
19
import org.eclipse.cdt.core.index.IIndexFileLocation;
20
import org.eclipse.cdt.core.index.IIndexFileLocation;
20
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
21
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
21
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
22
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
23
import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock;
22
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
23
25
24
/**
26
/**
Lines 41-58 Link Here
41
43
42
	/**
44
	/**
43
	 * Creates a file object for the given location and linkage or returns an existing one.
45
	 * Creates a file object for the given location and linkage or returns an existing one.
44
	 * @param fileLocation an IIndexFileLocation representing the location of the file
46
	 * @param fileLocation an IIndexFileLocation representing the location of the file.
45
	 * @return the existing IIndexFragmentFile for this location, or a newly created one 
47
	 * @return the existing IIndexFragmentFile for this location, or a newly created one. 
46
	 * @throws CoreException
48
	 * @throws CoreException
47
	 */
49
	 */
48
	IIndexFragmentFile addFile(int linkageID, IIndexFileLocation fileLocation) throws CoreException;
50
	IIndexFragmentFile addFile(int linkageID, IIndexFileLocation fileLocation) throws CoreException;
49
51
50
	/**
52
	/**
51
	 * Adds an include to the given file.
53
	 * Creates a file object for the given location and linkage. The created file object is not added to
54
	 * the file index.
55
	 * @param fileLocation an IIndexFileLocation representing the location of the file.
56
	 * @return a newly created IIndexFragmentFile. 
57
	 * @throws CoreException
58
	 */
59
	IIndexFragmentFile addUncommittedFile(int linkageID, IIndexFileLocation fileLocation) throws CoreException;
60
61
	/**
62
	 * Makes the file that was created earlier by calling {@link #addUncommittedFile(int, IIndexFileLocation)}
63
	 * visible in the index.
64
     *
65
	 * @return The file that was updated.
66
	 * @throws CoreException
67
	 */
68
	IIndexFragmentFile commitUncommittedFile() throws CoreException;
69
70
	/**
71
	 * Adds includes, macros and names to the given file.
52
	 */
72
	 */
53
	void addFileContent(IIndexFragmentFile sourceFile, 
73
	void addFileContent(IIndexFragmentFile sourceFile, IncludeInformation[] includes,  
54
			IncludeInformation[] includes,  
74
			IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver resolver,
55
			IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException;
75
			YieldableIndexLock lock) throws CoreException, InterruptedException;
56
76
57
	/**
77
	/**
58
	 * Acquires a write lock, while giving up a certain amount of read locks.
78
	 * Acquires a write lock, while giving up a certain amount of read locks.
(-)parser/org/eclipse/cdt/internal/core/index/WritableCIndex.java (-6 / +16 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Andrew Ferguson (Symbian)
10
 *    Andrew Ferguson (Symbian)
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/ 
12
 *******************************************************************************/ 
12
13
13
package org.eclipse.cdt.internal.core.index;
14
package org.eclipse.cdt.internal.core.index;
Lines 19-24 Link Here
19
import org.eclipse.cdt.core.index.IIndexFile;
20
import org.eclipse.cdt.core.index.IIndexFile;
20
import org.eclipse.cdt.core.index.IIndexFileLocation;
21
import org.eclipse.cdt.core.index.IIndexFileLocation;
21
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
22
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
23
import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock;
22
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
23
25
24
public class WritableCIndex extends CIndex implements IWritableIndex {
26
public class WritableCIndex extends CIndex implements IWritableIndex {
Lines 50-66 Link Here
50
		return fWritableFragment.getFiles(location);
52
		return fWritableFragment.getFiles(location);
51
	}
53
	}
52
54
53
	public IIndexFragmentFile addFile(int linkageID, IIndexFileLocation fileLocation) throws CoreException {
55
	public IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location) throws CoreException {
54
		return fWritableFragment.addFile(linkageID, fileLocation);
56
		return fWritableFragment.addFile(linkageID, location);
57
	}
58
59
	public IIndexFragmentFile addUncommittedFile(int linkageID, IIndexFileLocation location) throws CoreException {
60
		return fWritableFragment.addUncommittedFile(linkageID, location);
61
	}
62
63
	public IIndexFragmentFile commitUncommittedFile() throws CoreException {
64
		return fWritableFragment.commitUncommittedFile();
55
	}
65
	}
56
66
57
	private boolean isWritableFragment(IIndexFragment frag) {
67
	private boolean isWritableFragment(IIndexFragment frag) {
58
		return frag == fWritableFragment;
68
		return frag == fWritableFragment;
59
	}
69
	}
60
70
61
	public void setFileContent(IIndexFragmentFile file, int linkageID,
71
	public void setFileContent(IIndexFragmentFile file, int linkageID, IncludeInformation[] includes,
62
			IncludeInformation[] includes,
72
			IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver resolver,
63
			IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException {
73
			YieldableIndexLock lock) throws CoreException, InterruptedException {
64
		IIndexFragment indexFragment = file.getIndexFragment();
74
		IIndexFragment indexFragment = file.getIndexFragment();
65
		if (!isWritableFragment(indexFragment)) {
75
		if (!isWritableFragment(indexFragment)) {
66
			assert false : "Attempt to update file of read-only fragment"; //$NON-NLS-1$
76
			assert false : "Attempt to update file of read-only fragment"; //$NON-NLS-1$
Lines 70-76 Link Here
70
					ii.fTargetFile= addFile(linkageID, ii.fLocation);
80
					ii.fTargetFile= addFile(linkageID, ii.fLocation);
71
				}
81
				}
72
			}
82
			}
73
			((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names, resolver);
83
			((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names, resolver, lock);
74
		}
84
		}
75
	}
85
	}
76
86
(-)parser/org/eclipse/cdt/internal/core/pdom/PDOM.java (-13 / +33 lines)
Lines 6-16 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Doug Schaefer (QNX) - Initial API and implementation
9
 *    Doug Schaefer (QNX) - Initial API and implementation
10
 *     Markus Schorn (Wind River Systems)
10
 *    Markus Schorn (Wind River Systems)
11
 *     IBM Corporation
11
 *    IBM Corporation
12
 *     Andrew Ferguson (Symbian)
12
 *    Andrew Ferguson (Symbian)
13
 *     Anton Leherbauer (Wind River Systems)
13
 *    Anton Leherbauer (Wind River Systems)
14
 *    Sergey Prigogin (Google)
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.cdt.internal.core.pdom;
16
package org.eclipse.cdt.internal.core.pdom;
16
17
Lines 48-53 Link Here
48
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
49
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
49
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
50
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
50
import org.eclipse.cdt.core.index.IIndexBinding;
51
import org.eclipse.cdt.core.index.IIndexBinding;
52
import org.eclipse.cdt.core.index.IIndexFile;
51
import org.eclipse.cdt.core.index.IIndexFileLocation;
53
import org.eclipse.cdt.core.index.IIndexFileLocation;
52
import org.eclipse.cdt.core.index.IIndexLinkage;
54
import org.eclipse.cdt.core.index.IIndexLinkage;
53
import org.eclipse.cdt.core.index.IIndexLocationConverter;
55
import org.eclipse.cdt.core.index.IIndexLocationConverter;
Lines 341-347 Link Here
341
		}
343
		}
342
	}
344
	}
343
345
344
	private PDOMLinkage createLinkage(int linkageID) throws CoreException {
346
	protected PDOMLinkage createLinkage(int linkageID) throws CoreException {
345
		PDOMLinkage pdomLinkage= fLinkageIDCache.get(linkageID);
347
		PDOMLinkage pdomLinkage= fLinkageIDCache.get(linkageID);
346
		if (pdomLinkage == null) {
348
		if (pdomLinkage == null) {
347
			final String linkageName= Linkage.getLinkageName(linkageID);
349
			final String linkageName= Linkage.getLinkageName(linkageID);
Lines 783-789 Link Here
783
		}
785
		}
784
	}
786
	}
785
787
786
787
	public void releaseReadLock() {
788
	public void releaseReadLock() {
788
		boolean clearCache= false;
789
		boolean clearCache= false;
789
		synchronized (mutex) {
790
		synchronized (mutex) {
Lines 884-889 Link Here
884
		fireChange(event);
885
		fireChange(event);
885
	}
886
	}
886
887
888
	public boolean hasWaitingReaders() {
889
		synchronized (mutex) {
890
			return waitingReaders > 0;
891
		}
892
	}
893
	
887
	public long getLastWriteAccess() {
894
	public long getLastWriteAccess() {
888
		return lastWriteAccess;
895
		return lastWriteAccess;
889
	}
896
	}
Lines 957-973 Link Here
957
		PDOMName name;
964
		PDOMName name;
958
		if ((options & FIND_DECLARATIONS) != 0) {
965
		if ((options & FIND_DECLARATIONS) != 0) {
959
			for (name= pdomBinding.getFirstDeclaration(); name != null; name= name.getNextInBinding()) {
966
			for (name= pdomBinding.getFirstDeclaration(); name != null; name= name.getNextInBinding()) {
960
				names.add(name);
967
				addName(name, names);
961
			}
968
			}
962
		}
969
		}
963
		if ((options & FIND_DEFINITIONS) != 0) {
970
		if ((options & FIND_DEFINITIONS) != 0) {
964
			for (name = pdomBinding.getFirstDefinition(); name != null; name= name.getNextInBinding()) {
971
			for (name = pdomBinding.getFirstDefinition(); name != null; name= name.getNextInBinding()) {
965
				names.add(name);
972
				addName(name, names);
966
			}
973
			}
967
		}
974
		}
968
		if ((options & FIND_REFERENCES) != 0) {
975
		if ((options & FIND_REFERENCES) != 0) {
969
			for (name = pdomBinding.getFirstReference(); name != null; name= name.getNextInBinding()) {
976
			for (name = pdomBinding.getFirstReference(); name != null; name= name.getNextInBinding()) {
970
				names.add(name);
977
				addName(name, names);
971
			}
978
			}
972
		}
979
		}
973
	}
980
	}
Lines 978-1000 Link Here
978
			for (PDOMMacro macro= container.getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) {
985
			for (PDOMMacro macro= container.getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) {
979
				final IIndexFragmentName name = macro.getDefinition();
986
				final IIndexFragmentName name = macro.getDefinition();
980
				if (name != null) {
987
				if (name != null) {
981
					names.add(name);
988
					addName(name, names);
982
				}
989
				}
983
			}
990
			}
984
		}
991
		}
985
		if ((options & FIND_REFERENCES) != 0) {
992
		if ((options & FIND_REFERENCES) != 0) {
986
			for (PDOMMacroReferenceName name = container.getFirstReference(); name != null; name= name.getNextInContainer()) {
993
			for (PDOMMacroReferenceName name = container.getFirstReference(); name != null; name= name.getNextInContainer()) {
987
				names.add(name);
994
				addName(name, names);
988
			}
995
			}
989
		}
996
		}
990
	}
997
	}
991
998
999
	private void addName(IIndexFragmentName name, ArrayList<IIndexFragmentName> names) throws CoreException {
1000
		IIndexFile file = name.getFile();
1001
		if (file == null || file.getTimestamp() > 0) {
1002
			names.add(name);
1003
		}
1004
	}
1005
992
	public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
1006
	public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
993
		PDOMFile pdomFile= adaptFile(file);
1007
		PDOMFile pdomFile= adaptFile(file);
994
		if (pdomFile != null) {
1008
		if (pdomFile != null) {
995
			List<PDOMInclude> result = new ArrayList<PDOMInclude>();
1009
			List<PDOMInclude> result = new ArrayList<PDOMInclude>();
996
			for (PDOMInclude i= pdomFile.getFirstIncludedBy(); i != null; i= i.getNextInIncludedBy()) {
1010
			for (PDOMInclude i= pdomFile.getFirstIncludedBy(); i != null; i= i.getNextInIncludedBy()) {
997
				result.add(i);
1011
				if (i.getIncludedBy().getTimestamp() > 0) {
1012
					result.add(i);
1013
				}
998
			}
1014
			}
999
			return result.toArray(new PDOMInclude[result.size()]);
1015
			return result.toArray(new PDOMInclude[result.size()]);
1000
		}
1016
		}
Lines 1197-1202 Link Here
1197
	public String createKeyForCache(long record, char[] name) {
1213
	public String createKeyForCache(long record, char[] name) {
1198
		return new StringBuilder(name.length+2).append((char) (record >> 16)).append((char) record).append(name).toString();
1214
		return new StringBuilder(name.length+2).append((char) (record >> 16)).append((char) record).append(name).toString();
1199
	}
1215
	}
1216
1217
	public boolean hasLastingDefinition(PDOMBinding binding) throws CoreException {
1218
		return binding.hasDefinition();
1219
	}
1200
	
1220
	
1201
	private PDOMBinding[] getCrossLanguageBindings(IBinding binding) throws CoreException {
1221
	private PDOMBinding[] getCrossLanguageBindings(IBinding binding) throws CoreException {
1202
		switch(binding.getLinkage().getLinkageID()) {
1222
		switch(binding.getLinkage().getLinkageID()) {
(-)parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java (+5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Sergey Prigogin (Google)
10
 *******************************************************************************/ 
11
 *******************************************************************************/ 
11
package org.eclipse.cdt.internal.core.pdom;
12
package org.eclipse.cdt.internal.core.pdom;
12
13
Lines 187-192 Link Here
187
		}
188
		}
188
	}
189
	}
189
190
191
	public boolean hasWaitingReaders() {
192
		return fDelegate != null && fDelegate.hasWaitingReaders();
193
	}
194
190
	public synchronized void resetCacheCounters() {
195
	public synchronized void resetCacheCounters() {
191
		if (fDelegate != null)
196
		if (fDelegate != null)
192
			fDelegate.resetCacheCounters();
197
			fDelegate.resetCacheCounters();
(-)parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java (-13 / +42 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    IBM Corporation
10
 *    IBM Corporation
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/ 
12
 *******************************************************************************/ 
12
package org.eclipse.cdt.internal.core.pdom;
13
package org.eclipse.cdt.internal.core.pdom;
13
14
Lines 46-51 Link Here
46
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
47
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
47
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
48
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
48
import org.eclipse.cdt.core.index.IIndexFileLocation;
49
import org.eclipse.cdt.core.index.IIndexFileLocation;
50
import org.eclipse.cdt.core.index.IIndexInclude;
49
import org.eclipse.cdt.core.parser.IProblem;
51
import org.eclipse.cdt.core.parser.IProblem;
50
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
52
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
51
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
53
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
Lines 68-73 Link Here
68
 * @since 4.0
70
 * @since 4.0
69
 */
71
 */
70
abstract public class PDOMWriter {
72
abstract public class PDOMWriter {
73
	public static boolean FINE_GRAINED_LOCKING = true;
71
	public static int SKIP_ALL_REFERENCES= -1;
74
	public static int SKIP_ALL_REFERENCES= -1;
72
	public static int SKIP_TYPE_REFERENCES= 1;
75
	public static int SKIP_TYPE_REFERENCES= 1;
73
	public static int SKIP_MACRO_REFERENCES= 2;
76
	public static int SKIP_MACRO_REFERENCES= 2;
Lines 200-210 Link Here
200
				if (fShowActivity) {
203
				if (fShowActivity) {
201
					trace("Indexer: adding " + ifl.getURI());  //$NON-NLS-1$
204
					trace("Indexer: adding " + ifl.getURI());  //$NON-NLS-1$
202
				}
205
				}
203
				index.acquireWriteLock(readlockCount);
204
				long start= System.currentTimeMillis();
205
				Throwable th= null;
206
				Throwable th= null;
207
				YieldableIndexLock lock = new YieldableIndexLock(index, readlockCount, flushIndex);
208
				lock.acquire();
206
				try {
209
				try {
207
					storeFileInIndex(index, ifl, symbolMap, linkageID, configHash, contextIncludes);
210
					storeFileInIndex(index, ifl, symbolMap, linkageID, configHash, contextIncludes, lock);
208
				} catch (RuntimeException e) {
211
				} catch (RuntimeException e) {
209
					th= e; 
212
					th= e; 
210
				} catch (PDOMNotImplementedError e) {
213
				} catch (PDOMNotImplementedError e) {
Lines 214-220 Link Here
214
				} catch (AssertionError e) {
217
				} catch (AssertionError e) {
215
					th= e;
218
					th= e;
216
				} finally {
219
				} finally {
217
					index.releaseWriteLock(readlockCount, flushIndex);
220
					lock.release();
218
				}
221
				}
219
				if (th != null) {
222
				if (th != null) {
220
					stati.add(createStatus(NLS.bind(Messages.PDOMWriter_errorWhileParsing,
223
					stati.add(createStatus(NLS.bind(Messages.PDOMWriter_errorWhileParsing,
Lines 223-229 Link Here
223
				if (i < ifls.length - 1) {
226
				if (i < ifls.length - 1) {
224
					updateFileCount(0, 0, 1); // update header count
227
					updateFileCount(0, 0, 1); // update header count
225
				}
228
				}
226
				fStatistics.fAddToIndexTime += System.currentTimeMillis() - start;
229
				fStatistics.fAddToIndexTime += lock.getCumulativeLockTime();
227
			}
230
			}
228
		}
231
		}
229
	}
232
	}
Lines 448-463 Link Here
448
451
449
	private IIndexFragmentFile storeFileInIndex(IWritableIndex index, IIndexFileLocation location,
452
	private IIndexFragmentFile storeFileInIndex(IWritableIndex index, IIndexFileLocation location,
450
			Map<IIndexFileLocation, Symbols> symbolMap, int linkageID, int configHash,
453
			Map<IIndexFileLocation, Symbols> symbolMap, int linkageID, int configHash,
451
			Set<IASTPreprocessorIncludeStatement> contextIncludes) throws CoreException {
454
			Set<IASTPreprocessorIncludeStatement> contextIncludes, YieldableIndexLock lock)
455
			throws CoreException, InterruptedException {
452
		Set<IIndexFileLocation> clearedContexts= Collections.emptySet();
456
		Set<IIndexFileLocation> clearedContexts= Collections.emptySet();
453
		IIndexFragmentFile file= index.getWritableFile(linkageID, location);
457
		IIndexFragmentFile file;
454
		if (file != null) {
458
		long timestamp = fResolver.getLastModified(location);
455
			clearedContexts= new HashSet<IIndexFileLocation>();
459
		if (FINE_GRAINED_LOCKING) {
456
			index.clearFile(file, clearedContexts);
460
			// In fine grained locking mode we create a temporary PDOMFile with zero timestamp,
461
			// add names to it, then replace contents of the old file from the temporary one, then
462
			// delete the temporary file. The write lock on the index is periodically yielded while
463
			// adding names to the temporary file, if the process takes long time.
464
			IIndexFragmentFile oldFile = index.getWritableFile(linkageID, location);
465
			if (oldFile != null) {
466
				IIndexInclude[] includedBy = index.findIncludedBy(oldFile);
467
				if (includedBy.length > 0) {
468
					clearedContexts= new HashSet<IIndexFileLocation>();
469
					for (IIndexInclude include : includedBy) {
470
						clearedContexts.add(include.getIncludedByLocation());
471
					}
472
				}
473
			}
474
			file= index.addUncommittedFile(linkageID, location);
457
		} else {
475
		} else {
458
			file= index.addFile(linkageID, location);
476
			file= index.getWritableFile(linkageID, location);
477
			if (file != null) {
478
				clearedContexts= new HashSet<IIndexFileLocation>();
479
				index.clearFile(file, clearedContexts);
480
			} else {
481
				file= index.addFile(linkageID, location);
482
			}
483
			file.setTimestamp(timestamp);
459
		}
484
		}
460
		file.setTimestamp(fResolver.getLastModified(location));
461
		file.setScannerConfigurationHashcode(configHash);
485
		file.setScannerConfigurationHashcode(configHash);
462
		Symbols lists= symbolMap.get(location);
486
		Symbols lists= symbolMap.get(location);
463
		if (lists != null) {
487
		if (lists != null) {
Lines 481-488 Link Here
481
						(contextIncludes.contains(include) || clearedContexts.contains(info.fLocation));
505
						(contextIncludes.contains(include) || clearedContexts.contains(info.fLocation));
482
				}
506
				}
483
			}
507
			}
484
			index.setFileContent(file, linkageID, includeInfos, macros, names, fResolver);
508
			index.setFileContent(file, linkageID, includeInfos, macros, names, fResolver,
509
					FINE_GRAINED_LOCKING ? lock : null);
485
		}
510
		}
511
		if (FINE_GRAINED_LOCKING) {
512
			file.setTimestamp(timestamp);
513
			file = index.commitUncommittedFile();
514
		}			
486
		return file;
515
		return file;
487
	}
516
	}
488
	
517
	
(-)parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java (-5 / +66 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Markus Schorn - initial API and implementation
9
 *    Markus Schorn - initial API and implementation
10
 *    Andrew Ferguson (Symbian)
10
 *    Andrew Ferguson (Symbian)
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/ 
12
 *******************************************************************************/ 
12
package org.eclipse.cdt.internal.core.pdom;
13
package org.eclipse.cdt.internal.core.pdom;
13
14
Lines 25-41 Link Here
25
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
26
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
26
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
27
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
27
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
28
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
29
import org.eclipse.cdt.internal.core.pdom.db.BTree;
28
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
30
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
29
import org.eclipse.cdt.internal.core.pdom.db.DBProperties;
31
import org.eclipse.cdt.internal.core.pdom.db.DBProperties;
30
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
32
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
31
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
33
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
34
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
32
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
35
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
36
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
37
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
33
import org.eclipse.core.runtime.CoreException;
38
import org.eclipse.core.runtime.CoreException;
34
39
35
public class WritablePDOM extends PDOM implements IWritableIndexFragment {	
40
public class WritablePDOM extends PDOM implements IWritableIndexFragment {	
36
	private boolean fClearedBecauseOfVersionMismatch= false;
41
	private boolean fClearedBecauseOfVersionMismatch= false;
37
	private boolean fCreatedFromScratch= false;
42
	private boolean fCreatedFromScratch= false;
38
	private ASTFilePathResolver fPathResolver;
43
	private ASTFilePathResolver fPathResolver;
44
	private PDOMFile fileBeingUpdated;
45
	private PDOMFile uncommittedFile;
46
	private IIndexFileLocation uncommittedLocation;
39
47
40
	public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
48
	public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
41
		this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
49
		this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
Lines 51-61 Link Here
51
59
52
	@Override
60
	@Override
53
	public IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location) throws CoreException {
61
	public IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location) throws CoreException {
62
		if (uncommittedLocation != null && uncommittedLocation.equals(location)) {
63
			return uncommittedFile;
64
		}
54
		return super.addFile(linkageID, location);
65
		return super.addFile(linkageID, location);
55
	}
66
	}
56
67
68
	public IIndexFragmentFile addUncommittedFile(int linkageID, IIndexFileLocation location) throws CoreException {
69
		uncommittedLocation = location;
70
		fileBeingUpdated = getFile(linkageID, uncommittedLocation);
71
		PDOMLinkage linkage= createLinkage(linkageID);
72
		uncommittedFile = new PDOMFile(linkage, location, linkageID);
73
		return uncommittedFile;
74
	}
75
76
	public IIndexFragmentFile commitUncommittedFile() throws CoreException {
77
		if (uncommittedFile == null)
78
			return null;
79
		IIndexFragmentFile file;
80
		if (fileBeingUpdated == null) {
81
			// New file.
82
			BTree fileIndex = getFileIndex();
83
			fileIndex.insert(uncommittedFile.getRecord());
84
			file = uncommittedFile;
85
		} else {
86
			// Existing file.
87
			fileBeingUpdated.replaceContentsFrom(uncommittedFile);
88
			file = fileBeingUpdated;
89
			fileBeingUpdated = null;
90
		}
91
		fEvent.fFilesWritten.add(uncommittedLocation);
92
		uncommittedFile = null;
93
		uncommittedLocation = null;
94
		return file;
95
	}
96
57
	public void addFileContent(IIndexFragmentFile sourceFile, IncludeInformation[] includes, 
97
	public void addFileContent(IIndexFragmentFile sourceFile, IncludeInformation[] includes, 
58
			IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver pathResolver) throws CoreException {
98
			IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver pathResolver,
99
			YieldableIndexLock lock) throws CoreException, InterruptedException {
59
		assert sourceFile.getIndexFragment() == this;
100
		assert sourceFile.getIndexFragment() == this;
60
		
101
		
61
		PDOMFile pdomFile = (PDOMFile) sourceFile;
102
		PDOMFile pdomFile = (PDOMFile) sourceFile;
Lines 64-77 Link Here
64
		final ASTFilePathResolver origResolver= fPathResolver;
105
		final ASTFilePathResolver origResolver= fPathResolver;
65
		fPathResolver= pathResolver;
106
		fPathResolver= pathResolver;
66
		try {
107
		try {
67
			pdomFile.addNames(names);
108
			pdomFile.addNames(names, lock);
68
		} finally {
109
		} finally {
69
			fPathResolver= origResolver;
110
			fPathResolver= origResolver;
70
		}
111
		}
71
		
112
		
72
		final IIndexFileLocation location = pdomFile.getLocation();
113
		final IIndexFileLocation location = pdomFile.getLocation();
73
		fEvent.fClearedFiles.remove(location);
114
		if (location != null) {
74
		fEvent.fFilesWritten.add(location);
115
			fEvent.fClearedFiles.remove(location);
116
			fEvent.fFilesWritten.add(location);
117
		}
75
	}
118
	}
76
119
77
	public void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
120
	public void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
Lines 168-178 Link Here
168
211
169
	public PDOMFile getFileForASTPath(int linkageID, String astPath) throws CoreException {
212
	public PDOMFile getFileForASTPath(int linkageID, String astPath) throws CoreException {
170
		if (fPathResolver != null && astPath != null) {
213
		if (fPathResolver != null && astPath != null) {
171
			return getFile(linkageID, fPathResolver.resolveASTPath(astPath));
214
			IIndexFileLocation location = fPathResolver.resolveASTPath(astPath);
215
			if (location.equals(uncommittedLocation))
216
				return fileBeingUpdated != null ? fileBeingUpdated : uncommittedFile;
217
			return getFile(linkageID, location);
172
		}
218
		}
173
		return null;
219
		return null;
174
	}
220
	}
175
221
222
	@Override
223
	public boolean hasLastingDefinition(PDOMBinding binding) throws CoreException {
224
		if (fileBeingUpdated == null) {
225
			return binding.hasDefinition();
226
		}
227
		// Definitions in fileBeingUpdated will soon go away, so look for a definition elsewhere.
228
		for (PDOMName name = binding.getFirstDefinition(); name != null; name = name.getNextInBinding()) {
229
			if (!fileBeingUpdated.getPDOM().equals(name.getPDOM()) ||
230
					fileBeingUpdated.getRecord() != name.getFileRecord()) {
231
				return true;
232
			}
233
		}
234
		return false;
235
	}
236
	
176
	/* (non-Javadoc)
237
	/* (non-Javadoc)
177
	 * @see org.eclipse.cdt.internal.core.index.IWritableIndexFragment#getDatabaseSizeBytes()
238
	 * @see org.eclipse.cdt.internal.core.index.IWritableIndexFragment#getDatabaseSizeBytes()
178
	 */
239
	 */
(-)parser/org/eclipse/cdt/internal/core/pdom/YieldableIndexLock.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Google, Inc and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * 	  Sergey Prigogin (Google) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.core.pdom;
12
13
import org.eclipse.cdt.internal.core.index.IWritableIndex;
14
15
/**
16
 * Write lock on the index that can be yielded temporarily to unblock threads that need
17
 * read access to the index. 
18
 * @since 5.2
19
 */
20
public class YieldableIndexLock {
21
	private final IWritableIndex index;
22
	private final int readlockCount;
23
	private final boolean flushIndex;
24
	private long lastLockTime;
25
	private long cumulativeLockTime;
26
27
	public YieldableIndexLock(IWritableIndex index, int readlockCount, boolean flushIndex) {
28
		this.index = index;
29
		this.readlockCount = readlockCount;
30
		this.flushIndex = flushIndex;
31
	}
32
33
	/**
34
	 * Acquires the lock.
35
	 * 
36
	 * @throws InterruptedException
37
	 */
38
	public void acquire() throws InterruptedException {
39
		index.acquireWriteLock(readlockCount);
40
		lastLockTime = System.currentTimeMillis();
41
	}
42
43
	/**
44
	 * Releases the lock.
45
	 */
46
	public void release() {
47
		if (lastLockTime != 0) {
48
			index.releaseWriteLock(readlockCount, flushIndex);
49
			cumulativeLockTime += System.currentTimeMillis() - lastLockTime;
50
			lastLockTime = 0;
51
		}
52
	}
53
54
	/**
55
	 * Yields the lock temporarily if it was held for YIELD_INTERVAL or more, and somebody is waiting
56
	 * for a read lock. 
57
	 * @throws InterruptedException
58
	 */
59
	public void yield() throws InterruptedException {
60
		if (index.hasWaitingReaders()) {
61
			index.releaseWriteLock(readlockCount, false);
62
			cumulativeLockTime += System.currentTimeMillis() - lastLockTime;
63
			lastLockTime = 0;
64
			acquire();
65
		}
66
	}
67
68
	/**
69
	 * @return Total time the lock was held in milliseconds. 
70
	 */
71
	public long getCumulativeLockTime() {
72
		return cumulativeLockTime;
73
	}
74
}
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java (-5 / +130 lines)
Lines 9-14 Link Here
9
 *    QNX - Initial API and implementation
9
 *    QNX - Initial API and implementation
10
 *    Markus Schorn (Wind River Systems)
10
 *    Markus Schorn (Wind River Systems)
11
 *    Andrew Ferguson (Symbian)
11
 *    Andrew Ferguson (Symbian)
12
 *    Sergey Prigogin (Google)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.internal.core.pdom.dom;
14
package org.eclipse.cdt.internal.core.pdom.dom;
14
15
Lines 30-35 Link Here
30
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
31
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
31
import org.eclipse.cdt.core.dom.ast.IParameter;
32
import org.eclipse.cdt.core.dom.ast.IParameter;
32
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
33
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
34
import org.eclipse.cdt.core.index.IIndexFile;
33
import org.eclipse.cdt.core.index.IIndexFileLocation;
35
import org.eclipse.cdt.core.index.IIndexFileLocation;
34
import org.eclipse.cdt.core.index.IIndexInclude;
36
import org.eclipse.cdt.core.index.IIndexInclude;
35
import org.eclipse.cdt.core.index.IIndexLocationConverter;
37
import org.eclipse.cdt.core.index.IIndexLocationConverter;
Lines 42-47 Link Here
42
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
44
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
43
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
45
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
44
import org.eclipse.cdt.internal.core.pdom.PDOM;
46
import org.eclipse.cdt.internal.core.pdom.PDOM;
47
import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock;
45
import org.eclipse.cdt.internal.core.pdom.db.BTree;
48
import org.eclipse.cdt.internal.core.pdom.db.BTree;
46
import org.eclipse.cdt.internal.core.pdom.db.Database;
49
import org.eclipse.cdt.internal.core.pdom.db.Database;
47
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
50
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
Lines 119-124 Link Here
119
		return record;
122
		return record;
120
	}
123
	}
121
124
125
	public PDOM getPDOM() {
126
		return fLinkage.getPDOM();
127
	}
128
	
122
	@Override
129
	@Override
123
	public boolean equals(Object obj) {
130
	public boolean equals(Object obj) {
124
		if (obj == this)
131
		if (obj == this)
Lines 136-144 Link Here
136
	}
143
	}
137
	
144
	
138
	/**
145
	/**
139
	 * Directly changes this record's internal location string. The format
146
	 * Transfers names, macros and includes from another file to this one and deletes the other file.
140
	 * of this string is unspecified in general and is determined by the 
147
	 * @param sourceFile the file to transfer the local bindings from.
141
	 * associated IIndexLocationConverter
148
	 * @throws CoreException
149
	 */
150
	public void replaceContentsFrom(PDOMFile sourceFile) throws CoreException {
151
		ICPPUsingDirective[] directives= getUsingDirectives();
152
		for (ICPPUsingDirective ud : directives) {
153
			if (ud instanceof IPDOMNode) {
154
				((IPDOMNode) ud).delete(null);
155
			}
156
		}
157
		setFirstUsingDirectiveRec(sourceFile.getLastUsingDirectiveRec());
158
159
		// Replace the includes
160
		PDOMInclude include = getFirstInclude();
161
		while (include != null) {
162
			PDOMInclude nextInclude = include.getNextInIncludes();
163
			IIndexFile includedBy = include.getIncludedBy();
164
			if (includedBy.equals(this)) {
165
				include.delete();
166
			}
167
			include = nextInclude;
168
		}
169
		include = sourceFile.getFirstInclude();
170
		setFirstInclude(include);
171
		while (include != null) {
172
			IIndexFile includedBy = include.getIncludedBy();
173
			if (includedBy.equals(sourceFile)) {
174
				include.setIncludedBy(this);
175
			}
176
			include = include.getNextInIncludes();
177
		}
178
179
		include = sourceFile.getFirstIncludedBy();
180
		setFirstIncludedBy(include);
181
		while (include != null) {
182
			include.setIncludes(this);
183
			include = include.getNextInIncludedBy();
184
		}
185
186
		// Replace all the macros in this file.
187
		PDOMLinkage linkage= getLinkage();
188
		PDOMMacro macro = getFirstMacro();
189
		while (macro != null) {
190
			PDOMMacro nextMacro = macro.getNextMacro();
191
			macro.delete(linkage);
192
			macro = nextMacro;
193
		}
194
		macro = sourceFile.getFirstMacro();
195
		setFirstMacro(macro);
196
		for (; macro != null; macro = macro.getNextMacro()) {
197
			macro.setFile(this);
198
		}
199
200
		// Replace all macro references
201
		ArrayList<PDOMMacroReferenceName> mrefs= new ArrayList<PDOMMacroReferenceName>();
202
		PDOMMacroReferenceName mref = getFirstMacroReference();
203
		while (mref != null) {
204
			mrefs.add(mref);
205
			mref= mref.getNextInFile();
206
		}
207
		for (PDOMMacroReferenceName m : mrefs) {
208
			m.delete();
209
		}
210
		mref = sourceFile.getFirstMacroReference();
211
		setFirstMacroReference(mref);
212
		for (; mref != null; mref = mref.getNextInFile()) {
213
			mref.setFile(this);
214
		}
215
216
		// Replace all the names in this file
217
		ArrayList<PDOMName> names= new ArrayList<PDOMName>();
218
		PDOMName name = getFirstName();
219
		for (; name != null; name= name.getNextInFile()) {
220
			names.add(name);
221
			linkage.onDeleteName(name);
222
		}
223
		for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) {
224
			name = iterator.next();
225
			name.delete();
226
		}
227
		name = sourceFile.getFirstName();
228
		setFirstName(name);
229
		for (; name != null; name= name.getNextInFile()) {
230
			name.setFile(this);
231
		}
232
233
		setTimestamp(sourceFile.getTimestamp());
234
		setScannerConfigurationHashcode(sourceFile.getScannerConfigurationHashcode());
235
236
		sourceFile.delete();
237
	}
238
239
	/**
240
	 * This method should not be called on PDOMFile objects that are referenced by the file index.
241
	 * @param location a new location
242
	 * @throws CoreException
243
	 */
244
	public void setLocation(IIndexFileLocation location) throws CoreException {
245
		String locationString = fLinkage.getPDOM().getLocationConverter().toInternalFormat(location);
246
		if (locationString == null)
247
			throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toInternalProblem") + //$NON-NLS-1$
248
					location.getURI()));
249
		setInternalLocation(locationString);
250
	}
251
252
	/**
253
	 * Directly changes this record's internal location string. The format of this string is unspecified
254
	 * in general and is determined by the associated IIndexLocationConverter.
255
	 * This method should not be called on PDOMFile objects that are referenced by the file index.
142
	 * @param internalLocation
256
	 * @param internalLocation
143
	 * @throws CoreException
257
	 * @throws CoreException
144
	 */
258
	 */
Lines 260-274 Link Here
260
		return fLinkage;
374
		return fLinkage;
261
	}
375
	}
262
376
263
	public void addNames(IASTName[][] names) throws CoreException {
377
	public void addNames(IASTName[][] names, YieldableIndexLock lock) throws CoreException, InterruptedException {
264
		assert getFirstName() == null;
378
		assert getFirstName() == null;
265
		assert getFirstMacroReference() == null;
379
		assert getFirstMacroReference() == null;
266
		final PDOMLinkage linkage= getLinkage();
380
		final PDOMLinkage linkage= getLinkage();
267
		HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
381
		HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
268
		PDOMName lastName= null;
382
		PDOMName lastName= null;
269
		PDOMMacroReferenceName lastMacroName= null;
383
		PDOMMacroReferenceName lastMacroName= null;
384
		int counter = 0;
270
		for (IASTName[] name : names) {
385
		for (IASTName[] name : names) {
271
			if (name[0] != null) {
386
			if (name[0] != null) {
387
				// Once in a while check if anybody waits for index reader lock
388
				// and yield the writer lock if so.
389
				if (lock != null && ++counter >= 50) {
390
					counter = 0;
391
					lock.yield();
392
				}
272
				PDOMName caller= nameCache.get(name[1]);
393
				PDOMName caller= nameCache.get(name[1]);
273
				IIndexFragmentName fname= createPDOMName(linkage, name[0], caller);
394
				IIndexFragmentName fname= createPDOMName(linkage, name[0], caller);
274
				if (fname instanceof PDOMName) {
395
				if (fname instanceof PDOMName) {
Lines 344-350 Link Here
344
			include.delete();
465
			include.delete();
345
			include = nextInclude;
466
			include = nextInclude;
346
		}
467
		}
347
		setFirstInclude(include);
468
		setFirstInclude(null);
348
469
349
		// Delete all the macros in this file
470
		// Delete all the macros in this file
350
		PDOMLinkage linkage= getLinkage();
471
		PDOMLinkage linkage= getLinkage();
Lines 385-390 Link Here
385
		setTimestamp(-1);
506
		setTimestamp(-1);
386
	}
507
	}
387
508
509
	private void delete() throws CoreException {
510
		fLinkage.getDB().free(record);
511
	}
512
388
	public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException {
513
	public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException {
389
		assert getFirstInclude() == null;
514
		assert getFirstInclude() == null;
390
515
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java (-1 / +6 lines)
Lines 141-146 Link Here
141
		return rec != 0 ? new PDOMFile(linkage, rec) : null;
141
		return rec != 0 ? new PDOMFile(linkage, rec) : null;
142
	}
142
	}
143
143
144
	void setIncludes(PDOMFile includedFile) throws CoreException {
145
		long rec = includedFile != null ? includedFile.getRecord() : 0;
146
		linkage.getDB().putRecPtr(record + INCLUDED_FILE, rec);
147
	}
148
144
	/**
149
	/**
145
	 * Checks if the name is the same as the end part of the path of the included file.
150
	 * Checks if the name is the same as the end part of the path of the included file.
146
	 */
151
	 */
Lines 166-172 Link Here
166
		return rec != 0 ? new PDOMFile(linkage, rec) : null;
171
		return rec != 0 ? new PDOMFile(linkage, rec) : null;
167
	}
172
	}
168
173
169
	private void setIncludedBy(PDOMFile includedBy) throws CoreException {
174
	void setIncludedBy(PDOMFile includedBy) throws CoreException {
170
		long rec = includedBy != null ? includedBy.getRecord() : 0;
175
		long rec = includedBy != null ? includedBy.getRecord() : 0;
171
		linkage.getDB().putRecPtr(record + INCLUDED_BY, rec);
176
		linkage.getDB().putRecPtr(record + INCLUDED_BY, rec);
172
	}
177
	}
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java (+5 lines)
Lines 9-14 Link Here
9
 *    QNX - Initial API and implementation
9
 *    QNX - Initial API and implementation
10
 *    Markus Schorn (Wind River Systems)
10
 *    Markus Schorn (Wind River Systems)
11
 *    Andrew Ferguson (Symbian)
11
 *    Andrew Ferguson (Symbian)
12
 *    Sergey Prigogin (Google)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.internal.core.pdom.dom;
14
package org.eclipse.cdt.internal.core.pdom.dom;
14
15
Lines 269-274 Link Here
269
		return filerec != 0 ? new PDOMFile(fLinkage, filerec) : null;
270
		return filerec != 0 ? new PDOMFile(fLinkage, filerec) : null;
270
	}
271
	}
271
272
273
	void setFile(PDOMFile file) throws CoreException {
274
		fLinkage.getDB().putRecPtr(fRecord + FILE, file != null ? file.getRecord() : 0);
275
	}
276
272
	public int getEndingLineNumber() {
277
	public int getEndingLineNumber() {
273
		return 0;
278
		return 0;
274
	}
279
	}
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java (-1 / +6 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    QNX - Initial API and implementation
9
 *    QNX - Initial API and implementation
10
 *    Markus Schorn (Wind River Systems)
10
 *    Markus Schorn (Wind River Systems)
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.core.pdom.dom;
13
package org.eclipse.cdt.internal.core.pdom.dom;
13
14
Lines 110-116 Link Here
110
		long filerec = linkage.getDB().getRecPtr(record + FILE_REC_OFFSET);
111
		long filerec = linkage.getDB().getRecPtr(record + FILE_REC_OFFSET);
111
		return filerec != 0 ? new PDOMFile(linkage, filerec) : null;
112
		return filerec != 0 ? new PDOMFile(linkage, filerec) : null;
112
	}
113
	}
113
	
114
115
	void setFile(PDOMFile file) throws CoreException {
116
		linkage.getDB().putRecPtr(record + FILE_REC_OFFSET, file != null ? file.getRecord() : 0);
117
	}
118
114
	PDOMMacroReferenceName getNextInFile() throws CoreException {
119
	PDOMMacroReferenceName getNextInFile() throws CoreException {
115
		return getNameField(FILE_NEXT_OFFSET);
120
		return getNameField(FILE_NEXT_OFFSET);
116
	}
121
	}
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java (+14 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    QNX - Initial API and implementation
9
 *    QNX - Initial API and implementation
10
 *    Markus Schorn (Wind River Systems)
10
 *    Markus Schorn (Wind River Systems)
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.core.pdom.dom;
13
package org.eclipse.cdt.internal.core.pdom.dom;
13
14
Lines 22-27 Link Here
22
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
23
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
23
import org.eclipse.cdt.internal.core.index.IIndexFragment;
24
import org.eclipse.cdt.internal.core.index.IIndexFragment;
24
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
25
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
26
import org.eclipse.cdt.internal.core.pdom.PDOM;
25
import org.eclipse.cdt.internal.core.pdom.db.Database;
27
import org.eclipse.cdt.internal.core.pdom.db.Database;
26
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IPath;
Lines 121-126 Link Here
121
		linkage.getDB().putRecPtr(record + offset, fieldrec);
123
		linkage.getDB().putRecPtr(record + offset, fieldrec);
122
	}
124
	}
123
125
126
	public PDOM getPDOM() {
127
		return linkage.getPDOM();
128
	}
129
	
124
	public PDOMBinding getBinding() throws CoreException {
130
	public PDOMBinding getBinding() throws CoreException {
125
		long bindingrec = getRecField(BINDING_REC_OFFSET);
131
		long bindingrec = getRecField(BINDING_REC_OFFSET);
126
		return linkage.getBinding(bindingrec);
132
		return linkage.getBinding(bindingrec);
Lines 162-167 Link Here
162
		return filerec != 0 ? new PDOMFile(linkage, filerec) : null;
168
		return filerec != 0 ? new PDOMFile(linkage, filerec) : null;
163
	}
169
	}
164
170
171
	public long getFileRecord() throws CoreException {
172
		return linkage.getDB().getRecPtr(record + FILE_REC_OFFSET);
173
	}
174
175
	void setFile(PDOMFile file) throws CoreException {
176
		linkage.getDB().putRecPtr(record + FILE_REC_OFFSET, file != null ? file.getRecord() : 0);
177
	}
178
165
	public IIndexName getEnclosingDefinition() throws CoreException {
179
	public IIndexName getEnclosingDefinition() throws CoreException {
166
		long namerec = getEnclosingDefinitionRecord();
180
		long namerec = getEnclosingDefinitionRecord();
167
		return namerec != 0 ? new PDOMName(linkage, namerec) : null;
181
		return namerec != 0 ? new PDOMName(linkage, namerec) : null;
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java (-3 / +3 lines)
Lines 299-305 Link Here
299
			if (fromName.isDefinition()) {
299
			if (fromName.isDefinition()) {
300
				return true;
300
				return true;
301
			}
301
			}
302
			return !pdomBinding.hasDefinition();
302
			return !getPDOM().hasLastingDefinition(pdomBinding);
303
		}
303
		}
304
		return false;
304
		return false;
305
	}
305
	}
Lines 444-451 Link Here
444
					if (!(method instanceof IProblemBinding)) {
444
					if (!(method instanceof IProblemBinding)) {
445
						PDOMBinding pdomBinding= adaptBinding(method);
445
						PDOMBinding pdomBinding= adaptBinding(method);
446
						if (pdomBinding == null) {
446
						if (pdomBinding == null) {
447
							createBinding(type, method, fileLocalRec);
447
							pdomBinding = createBinding(type, method, fileLocalRec);
448
						} else if (!pdomBinding.hasDefinition()) {
448
						} else if (!getPDOM().hasLastingDefinition(pdomBinding)) {
449
							pdomBinding.update(this, method);
449
							pdomBinding.update(this, method);
450
						}
450
						}
451
					}
451
					}
(-)parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java (+6 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Andrew Ferguson (Symbian) - initial API and implementation
9
 *    Andrew Ferguson (Symbian) - initial API and implementation
10
 *    Markus Schorn (Wind River Systems)
10
 *    Markus Schorn (Wind River Systems)
11
 *    Sergey Prigogin (Google)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.index.tests;
13
package org.eclipse.cdt.internal.index.tests;
13
14
Lines 123-128 Link Here
123
	}
124
	}
124
125
125
	public void releaseReadLock() {}
126
	public void releaseReadLock() {}
127
128
	public boolean hasWaitingReaders() {
129
		return false;
130
	}
131
126
	public void resetCacheCounters() {}
132
	public void resetCacheCounters() {}
127
133
128
	public IIndexFragmentFileSet createFileSet() {
134
	public IIndexFragmentFileSet createFileSet() {

Return to bug 287907