1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

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
This commit is contained in:
Nathan Ridge 2019-05-15 01:37:34 -04:00
parent 2734b7ae82
commit 8e1059c5b8

View file

@ -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();
}
}