Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2019-05-15 05:37:34 +0000
committerNathan Ridge2019-05-21 17:00:15 +0000
commit8e1059c5b8e580808bdf335271f7466a08d4e414 (patch)
tree0903cab3c5222b31904fb782e52f7ec5a8652c81 /core/org.eclipse.cdt.core/parser/org
parent2734b7ae8295dd4dde0d4383b2bcf7dc708a072a (diff)
downloadorg.eclipse.cdt-8e1059c5b8e580808bdf335271f7466a08d4e414.tar.gz
org.eclipse.cdt-8e1059c5b8e580808bdf335271f7466a08d4e414.tar.xz
org.eclipse.cdt-8e1059c5b8e580808bdf335271f7466a08d4e414.zip
Bug 547224 - Avoid concurrent access to AST type string caches
The caches used to be thread-local, but that did not survive the refactoring in bug 512297. This patch makes them thread-local again. Change-Id: Iffe37aef292e4efb05e30af2a251a71fb57b343d
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java
index 80a20e97e75..1e7b1d279b9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java
@@ -95,8 +95,18 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
private IBuiltinBindingsProvider fBuiltinBindingsProvider;
// Caches
- private final WeakHashMap<IType, String> fUnnormalizedTypeStringCache = new WeakHashMap<>();
- private final WeakHashMap<IType, String> fNormalizedTypeStringCache = new WeakHashMap<>();
+ private final ThreadLocal<WeakHashMap<IType, String>> fUnnormalizedTypeStringCache = new ThreadLocal<WeakHashMap<IType, String>>() {
+ @Override
+ protected WeakHashMap<IType, String> initialValue() {
+ return new WeakHashMap<>();
+ }
+ };
+ private final ThreadLocal<WeakHashMap<IType, String>> fNormalizedTypeStringCache = new ThreadLocal<WeakHashMap<IType, String>>() {
+ @Override
+ protected WeakHashMap<IType, String> initialValue() {
+ return new WeakHashMap<>();
+ }
+ };
@Override
public final IASTTranslationUnit getTranslationUnit() {
@@ -585,6 +595,6 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
}
public Map<IType, String> getTypeStringCache(boolean normalized) {
- return normalized ? fNormalizedTypeStringCache : fUnnormalizedTypeStringCache;
+ return normalized ? fNormalizedTypeStringCache.get() : fUnnormalizedTypeStringCache.get();
}
}

Back to the top