mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Indexer watchdog patch
This commit is contained in:
parent
050a97e1c7
commit
85666c920f
8 changed files with 150 additions and 8 deletions
|
@ -1,3 +1,6 @@
|
|||
2004-04-12 Bogdan Gheorghe
|
||||
Added Indexer watchdog
|
||||
|
||||
2004-04-12 Bogdan Gheorghe
|
||||
Added Enumerator and Derived types to index
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AddCompilationUnitToIndex extends AddFileToIndex {
|
|||
}
|
||||
protected boolean indexDocument(IIndex index) throws IOException {
|
||||
if (!initializeContents()) return false;
|
||||
index.add(new IFileDocument(resource, this.contents), new SourceIndexer(resource));
|
||||
index.add(new IFileDocument(resource, this.contents), new SourceIndexer(resource, manager.getTimeout()));
|
||||
return true;
|
||||
}
|
||||
public boolean initializeContents() {
|
||||
|
|
|
@ -32,12 +32,14 @@ import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
|
|||
import org.eclipse.cdt.internal.core.search.processing.IJob;
|
||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||
import org.eclipse.cdt.internal.core.sourcedependency.UpdateDependency;
|
||||
import org.eclipse.cdt.utils.TimeOut;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
|
||||
|
||||
public class IndexManager extends JobManager implements IIndexConstants {
|
||||
|
@ -67,6 +69,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
|
||||
public static boolean VERBOSE = false;
|
||||
|
||||
private TimeOut timeoutThread = null;
|
||||
|
||||
public synchronized void aboutToUpdateIndex(IPath path, Integer newIndexState) {
|
||||
// newIndexState is either UPDATING_STATE or REBUILDING_STATE
|
||||
// must tag the index as inconsistent, in case we exit before the update job is started
|
||||
|
@ -410,8 +414,18 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
this.monitors = new HashMap(5);
|
||||
this.indexStates = null;
|
||||
}
|
||||
|
||||
if (this.timeoutThread == null){
|
||||
this.timeoutThread = new TimeOut("Indexer TimeOut Thread"); //$NON-NLS-1$
|
||||
this.timeoutThread.setThreadPriority(Thread.MAX_PRIORITY);
|
||||
|
||||
Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
|
||||
prefs.setDefault(SourceIndexer.CDT_INDEXER_TIMEOUT,20000);
|
||||
}
|
||||
|
||||
this.indexNames = new SimpleLookupTable();
|
||||
this.cCorePluginLocation = null;
|
||||
|
||||
}
|
||||
|
||||
public void saveIndex(IIndex index) throws IOException {
|
||||
|
@ -509,6 +523,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
}
|
||||
}
|
||||
|
||||
this.timeoutThread = null;
|
||||
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
|
@ -573,4 +589,11 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
JobManager.verbose("-> index state updated to: " + state + " for: "+indexName); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public TimeOut getTimeout() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.timeoutThread ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.model.CoreModel;
|
|||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
@ -34,6 +35,7 @@ import org.eclipse.cdt.core.parser.ParserUtil;
|
|||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.index.IDocument;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.utils.TimeOut;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -57,10 +59,18 @@ public class SourceIndexer extends AbstractIndexer {
|
|||
//public static final String[] FILE_TYPES= new String[] {"cpp","c", "cc", "cxx"}; //$NON-NLS-1$
|
||||
|
||||
//protected DefaultProblemFactory problemFactory= new DefaultProblemFactory(Locale.getDefault());
|
||||
IFile resourceFile;
|
||||
public static final String CDT_INDEXER_TIMEOUT= "CDT_INDEXER_TIMEOUT"; //$NON-NLS-1$
|
||||
|
||||
SourceIndexer(IFile resourceFile) {
|
||||
this.resourceFile = resourceFile;
|
||||
IFile resourceFile;
|
||||
TimeOut timeOut = null;
|
||||
|
||||
/**
|
||||
* @param resource
|
||||
* @param out
|
||||
*/
|
||||
public SourceIndexer(IFile resource, TimeOut timeOut) {
|
||||
this.resourceFile = resource;
|
||||
this.timeOut = timeOut;
|
||||
}
|
||||
/**
|
||||
* Returns the file types the <code>IIndexer</code> handles.
|
||||
|
@ -73,7 +83,7 @@ public class SourceIndexer extends AbstractIndexer {
|
|||
// Add the name of the file to the index
|
||||
output.addDocument(document);
|
||||
// Create a new Parser
|
||||
SourceIndexerRequestor requestor = new SourceIndexerRequestor(this, resourceFile);
|
||||
SourceIndexerRequestor requestor = new SourceIndexerRequestor(this, resourceFile, timeOut);
|
||||
//requestor.removeMarkers(resourceFile);
|
||||
|
||||
//Get the scanner info
|
||||
|
@ -105,6 +115,12 @@ public class SourceIndexer extends AbstractIndexer {
|
|||
}
|
||||
|
||||
try{
|
||||
|
||||
// start timer
|
||||
String timeOut = CCorePlugin.getDefault().getPluginPreferences().getString(CDT_INDEXER_TIMEOUT);
|
||||
Integer timeOutValue = new Integer(timeOut);
|
||||
requestor.setTimeout(timeOutValue.intValue());
|
||||
requestor.startTimer();
|
||||
boolean retVal = parser.parse();
|
||||
|
||||
if (!retVal)
|
||||
|
@ -122,11 +138,15 @@ public class SourceIndexer extends AbstractIndexer {
|
|||
org.eclipse.cdt.internal.core.model.Util.log(null, "Out Of Memory error: " + vmErr.getMessage() + " on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
catch (ParseError e){
|
||||
org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Timeout on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
catch ( Exception ex ){
|
||||
if (ex instanceof IOException)
|
||||
throw (IOException) ex;
|
||||
}
|
||||
finally{
|
||||
requestor.stopTimer();
|
||||
//Release all resources
|
||||
parser=null;
|
||||
currentProject = null;
|
||||
|
|
|
@ -61,10 +61,13 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
||||
import org.eclipse.cdt.utils.TimeOut;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
|
@ -85,10 +88,14 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
private IASTInclusion currentInclude = null;
|
||||
private LinkedList includeStack = new LinkedList();
|
||||
|
||||
public SourceIndexerRequestor(SourceIndexer indexer, IFile resourceFile) {
|
||||
private IProgressMonitor pm = new NullProgressMonitor();
|
||||
private TimeOut timeoutThread = null;
|
||||
|
||||
public SourceIndexerRequestor(SourceIndexer indexer, IFile resourceFile, TimeOut timeOut) {
|
||||
super();
|
||||
this.indexer = indexer;
|
||||
this.resourceFile = resourceFile;
|
||||
this.timeoutThread = timeOut;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
|
||||
|
@ -587,12 +594,42 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.text.contentassist.ITimeoutThreadOwner#setTimeout(int)
|
||||
*/
|
||||
public void setTimeout(int timeout) {
|
||||
timeoutThread.setTimeout(timeout);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.text.contentassist.ITimeoutThreadOwner#startTimer()
|
||||
*/
|
||||
public void startTimer() {
|
||||
createProgressMonitor();
|
||||
timeoutThread.startTimer();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.text.contentassist.ITimeoutThreadOwner#stopTimer()
|
||||
*/
|
||||
public void stopTimer() {
|
||||
timeoutThread.stopTimer();
|
||||
pm.setCanceled(false);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#parserTimeout()
|
||||
*/
|
||||
public boolean parserTimeout() {
|
||||
// TODO Auto-generated method stub
|
||||
if ((pm != null) && (pm.isCanceled()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* Creates a new progress monitor with each start timer
|
||||
*/
|
||||
private void createProgressMonitor() {
|
||||
pm.setCanceled(false);
|
||||
timeoutThread.setProgressMonitor(pm);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,11 +28,17 @@ public class TimeOut implements Runnable {
|
|||
// long timerTime=0;
|
||||
private int threadPriority = Thread.MIN_PRIORITY + 1;
|
||||
boolean debug = false;
|
||||
private String threadName = null;
|
||||
|
||||
public TimeOut(){
|
||||
reset();
|
||||
}
|
||||
|
||||
public TimeOut(String threadName){
|
||||
this.threadName = threadName;
|
||||
reset();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (this.thread != null) {
|
||||
try {
|
||||
|
@ -86,7 +92,12 @@ public class TimeOut implements Runnable {
|
|||
|
||||
public void reset() {
|
||||
enabled=false;
|
||||
thread = new Thread(this, "Time Out Thread"); //$NON-NLS-1$
|
||||
if (threadName!=null){
|
||||
thread = new Thread(this, threadName);
|
||||
}
|
||||
else{
|
||||
thread = new Thread(this, "Time Out Thread"); //$NON-NLS-1$
|
||||
}
|
||||
thread.setDaemon(true);
|
||||
thread.setPriority(threadPriority);
|
||||
thread.start();
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2004-04-12 Bogdan Gheorghe
|
||||
Added Indexer Timeout field to Work In Progress Preference page
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/preferences/WorkInProgressPreferencePage.java
|
||||
|
||||
2004-04-12 Hoda Amer
|
||||
Fix for bug#57692 : [Content Assist] CompletionEngine::completionOnSingleNameReference() behaviour incorrect
|
||||
|
||||
|
|
|
@ -8,9 +8,12 @@ package org.eclipse.cdt.internal.ui.preferences;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.SourceIndexer;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchPage;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
|
@ -24,6 +27,8 @@ import org.eclipse.swt.widgets.Combo;
|
|||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
||||
|
@ -39,8 +44,10 @@ public class WorkInProgressPreferencePage extends PreferencePage
|
|||
|
||||
private Combo fExternLinks;
|
||||
private Button fExternEnabled;
|
||||
private Button fIProblemMarkers;
|
||||
|
||||
protected OverlayPreferenceStore fOverlayStore;
|
||||
private Text fTextControl;
|
||||
|
||||
public WorkInProgressPreferencePage(){
|
||||
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
|
||||
|
@ -51,6 +58,7 @@ public class WorkInProgressPreferencePage extends PreferencePage
|
|||
ArrayList overlayKeys = new ArrayList();
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CSearchPage.EXTERNALMATCH_ENABLED));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, CSearchPage.EXTERNALMATCH_VISIBLE));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, SourceIndexer.CDT_INDEXER_TIMEOUT));
|
||||
|
||||
OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
|
||||
overlayKeys.toArray(keys);
|
||||
|
@ -107,6 +115,13 @@ public class WorkInProgressPreferencePage extends PreferencePage
|
|||
}
|
||||
});
|
||||
|
||||
Group indexerTimeoutGroup= new Group(result, SWT.NONE);
|
||||
indexerTimeoutGroup.setLayout(new GridLayout());
|
||||
indexerTimeoutGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
indexerTimeoutGroup.setText("Indexer Timeout"); //$NON-NLS-1$
|
||||
|
||||
fTextControl = (Text) addTextField( indexerTimeoutGroup, "Time out (ms)","TimeOut",6,0,true);
|
||||
|
||||
initialize();
|
||||
|
||||
return result;
|
||||
|
@ -120,6 +135,8 @@ public class WorkInProgressPreferencePage extends PreferencePage
|
|||
fExternLinks.select(fOverlayStore.getInt(CSearchPage.EXTERNALMATCH_VISIBLE));
|
||||
fExternLinks.setEnabled(extEnabled);
|
||||
|
||||
fTextControl.setText(fOverlayStore.getString(SourceIndexer.CDT_INDEXER_TIMEOUT));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -154,11 +171,36 @@ public class WorkInProgressPreferencePage extends PreferencePage
|
|||
button.setLayoutData( data );
|
||||
return button;
|
||||
}
|
||||
|
||||
private Control addTextField(Composite composite, String label, String key, int textLimit, int indentation, boolean isNumber) {
|
||||
|
||||
Label labelControl = new Label(composite, SWT.NONE);
|
||||
labelControl.setText(label);
|
||||
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.horizontalIndent = indentation;
|
||||
labelControl.setLayoutData(gd);
|
||||
|
||||
Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
|
||||
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.widthHint = convertWidthInCharsToPixels(textLimit + 1);
|
||||
textControl.setLayoutData(gd);
|
||||
textControl.setTextLimit(textLimit);
|
||||
|
||||
return textControl;
|
||||
}
|
||||
/*
|
||||
* @see IPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
fOverlayStore.setValue(SourceIndexer.CDT_INDEXER_TIMEOUT, fTextControl.getText());
|
||||
|
||||
fOverlayStore.propagate();
|
||||
|
||||
// Store IProblem Marker value in CCorePlugin Preferences
|
||||
Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
|
||||
prefs.setValue(SourceIndexer.CDT_INDEXER_TIMEOUT,fOverlayStore.getString(SourceIndexer.CDT_INDEXER_TIMEOUT));
|
||||
CCorePlugin.getDefault().savePluginPreferences();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -168,6 +210,7 @@ public class WorkInProgressPreferencePage extends PreferencePage
|
|||
public static void initDefaults(IPreferenceStore store) {
|
||||
store.setDefault(CSearchPage.EXTERNALMATCH_ENABLED, false);
|
||||
store.setDefault(CSearchPage.EXTERNALMATCH_VISIBLE, 0);
|
||||
store.setDefault(SourceIndexer.CDT_INDEXER_TIMEOUT, "20000");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue