[r=Dmitry.Avdeev] Use volatile refs and synchronized methods to ensure data visibility between threads

This commit is contained in:
Eugene Zhuravlev
2010-12-06 13:30:00 +03:00
parent ae14a0c5f7
commit 70bf1cd7df
2 changed files with 12 additions and 11 deletions
@@ -112,19 +112,19 @@ public class BackwardDependenciesStorage implements Flushable, Disposable {
}
}
public void addClassReferencer(Integer qName, int referencerQName) {
public synchronized void addClassReferencer(Integer qName, int referencerQName) {
myCache.get(qName).addReferencer(new ReferencerItem(referencerQName));
}
public void addFieldReferencer(Integer qName, int referencerQName, int fieldName) {
public synchronized void addFieldReferencer(Integer qName, int referencerQName, int fieldName) {
myCache.get(qName).addReferencer(new FieldReferencerItem(referencerQName, fieldName));
}
public void addMethodReferencer(Integer qName, int referencerQName, int methodName, int descriptor) {
public synchronized void addMethodReferencer(Integer qName, int referencerQName, int methodName, int descriptor) {
myCache.get(qName).addReferencer(new MethodReferencerItem(referencerQName, methodName, descriptor));
}
public Dependency[] getDependencies(Integer classQName) throws CacheCorruptedException {
public synchronized Dependency[] getDependencies(Integer classQName) throws CacheCorruptedException {
try {
if (!myMap.containsMapping(classQName)) {
return Dependency.EMPTY_ARRAY;
@@ -46,22 +46,23 @@ import java.util.*;
public class DependencyCache {
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.make.DependencyCache");
private Cache myCache;
private Cache myNewClassesCache;
private volatile Cache myCache;
private volatile Cache myNewClassesCache;
private static final String REMOTE_INTERFACE_NAME = Remote.class.getName();
private TIntHashSet myToUpdate = new TIntHashSet(); // qName strings to be updated.
private final TIntHashSet myToUpdate = new TIntHashSet(); // qName strings to be updated.
private final TIntHashSet myTraverseRoots = new TIntHashSet(); // Dependencies are calculated from these clasess
private final TIntHashSet myClassesWithSourceRemoved = new TIntHashSet();
private final TIntHashSet myPreviouslyRemoteClasses = new TIntHashSet(); // classes that were Remote, but became non-Remote for some reason
private final TIntHashSet myMarkedInfos = new TIntHashSet(); // classes to be recompiled
private final Set<VirtualFile> myMarkedFiles = new HashSet<VirtualFile>();
private DependencyCacheNavigator myCacheNavigator;
private SymbolTable mySymbolTable;
private volatile DependencyCacheNavigator myCacheNavigator;
private volatile SymbolTable mySymbolTable;
private final String mySymbolTableFilePath;
private final String myStoreDirectoryPath;
@NonNls private static final String SYMBOLTABLE_FILE_NAME = "symboltable.dat";
@NonNls
private static final String SYMBOLTABLE_FILE_NAME = "symboltable.dat";
public DependencyCache(@NonNls String storeDirectoryPath) {
myStoreDirectoryPath = storeDirectoryPath;
@@ -225,7 +226,7 @@ public class DependencyCache {
for (final int qName : myClassesWithSourceRemoved.toArray()) {
cache.removeClass(qName);
}
myToUpdate = new TIntHashSet();
myToUpdate.clear();
//pause();
}