Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2007-02-06 15:09:11 -0500
committerDoug Schaefer2007-02-06 15:09:11 -0500
commit0850a4cb23216f96df916062723f620f4b3fa215 (patch)
treee4a54190b6d44ef0ed45ea11c671f25506cccf47
parentaee1e8c34ee7c840bbb28d575576af3c15eff9f9 (diff)
downloadorg.eclipse.cdt-0850a4cb23216f96df916062723f620f4b3fa215.tar.gz
org.eclipse.cdt-0850a4cb23216f96df916062723f620f4b3fa215.tar.xz
org.eclipse.cdt-0850a4cb23216f96df916062723f620f4b3fa215.zip
Put a mutex around lru cache operations in the PDOM database. Made open declarations less dumb by getting it to do a full parse again.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java81
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java3
2 files changed, 43 insertions, 41 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
index b90395c433..d4a4375245 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
@@ -292,6 +292,7 @@ public class Database {
}
// Chunk management
+ static private Object lruMutex = new Object();
static private Chunk lruFirst;
static private Chunk lruLast;
static private int lruSize;
@@ -316,65 +317,67 @@ public class Database {
}
static private final void lruPutFirst(Chunk chunk, boolean isNew) throws CoreException {
- // If this chunk is already first, we're good
- if (chunk == lruFirst)
- return;
-
- if (!isNew) {
- // Remove from current position in cache
- if (chunk.lruPrev != null) {
- chunk.lruPrev.lruNext = chunk.lruNext;
- }
- if (chunk.lruNext != null) {
- chunk.lruNext.lruPrev = chunk.lruPrev;
- } else {
- // No next => New last
- lruLast = chunk.lruPrev;
+ synchronized (lruMutex) {
+ // If this chunk is already first, we're good
+ if (chunk == lruFirst)
+ return;
+
+ if (!isNew) {
+ // Remove from current position in cache
+ if (chunk.lruPrev != null) {
+ chunk.lruPrev.lruNext = chunk.lruNext;
+ }
+ if (chunk.lruNext != null) {
+ chunk.lruNext.lruPrev = chunk.lruPrev;
+ } else {
+ // No next => New last
+ lruLast = chunk.lruPrev;
+ }
}
- }
-
- // Insert at front of cache
- chunk.lruNext = lruFirst;
- chunk.lruPrev = null;
- if (lruFirst != null)
- lruFirst.lruPrev = chunk;
- lruFirst = chunk;
- if (lruLast == null)
- lruLast = chunk;
-
- if (isNew) {
- // New chunk, see if we need to release one
- if (lruSize == lruMax) {
- Chunk last = lruLast;
- lruLast = last.lruPrev;
- lruLast.lruNext = null;
- last.free();
- } else {
- ++lruSize;
+
+ // Insert at front of cache
+ chunk.lruNext = lruFirst;
+ chunk.lruPrev = null;
+ if (lruFirst != null)
+ lruFirst.lruPrev = chunk;
+ lruFirst = chunk;
+ if (lruLast == null)
+ lruLast = chunk;
+
+ if (isNew) {
+ // New chunk, see if we need to release one
+ if (lruSize == lruMax) {
+ Chunk last = lruLast;
+ lruLast = last.lruPrev;
+ lruLast.lruNext = null;
+ last.free();
+ } else {
+ ++lruSize;
+ }
}
}
}
- private Object mutex = new Object();
+ private Object lockMutex = new Object();
private Thread lockOwner;
private int lockCount;
public void acquireLock() throws InterruptedException {
- synchronized (mutex) {
+ synchronized (lockMutex) {
if (lockOwner != Thread.currentThread())
while (lockCount > 0)
- mutex.wait();
+ lockMutex.wait();
++lockCount;
lockOwner = Thread.currentThread();
}
}
public void releaseLock() {
- synchronized (mutex) {
+ synchronized (lockMutex) {
--lockCount;
if (lockCount == 0) {
lockOwner = null;
- mutex.notify();
+ lockMutex.notify();
}
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
index 1205568e75..b080659939 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
@@ -66,8 +66,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
pdom.acquireReadLock();
try {
- IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy,
- ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
+ IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_USE_INDEX);
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // got a name

Back to the top