Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2019-05-15 01:37:34 -0400
committerJonah Graham2019-05-22 14:14:51 -0400
commit58c267bd672e9b736d98cc7eabebbb6929ce5aa3 (patch)
tree3bcb23e678e3e39f6e17acdf962eb4ed2f97a5a4
parent41023cf7f91caeb8bd0e7f7039d47659c673dadc (diff)
downloadorg.eclipse.cdt-cdt_9_7.tar.gz
org.eclipse.cdt-cdt_9_7.tar.xz
org.eclipse.cdt-cdt_9_7.zip
Bug 547224 - Avoid concurrent access to AST type string cachescdt_9_7
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
-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 80a20e97e7..1e7b1d279b 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