Lock based binding context

This commit is contained in:
Nikolay Krasko
2013-07-26 19:29:14 +04:00
parent 39b091ddaf
commit fbe1491ad4
@@ -16,12 +16,14 @@
package org.jetbrains.jet.lang.resolve.lazy.storage; package org.jetbrains.jet.lang.resolve.lazy.storage;
import com.google.common.collect.ImmutableMap;
import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Computable;
import com.intellij.util.Consumer; import com.intellij.util.Consumer;
import com.intellij.util.Function; import com.intellij.util.Function;
import com.intellij.util.containers.ConcurrentWeakValueHashMap; import com.intellij.util.containers.ConcurrentWeakValueHashMap;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
@@ -215,20 +217,62 @@ public class LockBasedStorageManager implements StorageManager {
} }
} }
private static class LockProtectedContext implements BindingContext {
private final Object lock;
private final BindingContext context;
private LockProtectedContext(Object lock, BindingContext context) {
this.lock = lock;
this.context = context;
}
@Override
public Collection<Diagnostic> getDiagnostics() {
synchronized (lock) {
return context.getDiagnostics();
}
}
@Nullable
@Override
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
synchronized (lock) {
return context.get(slice, key);
}
}
@NotNull
@Override
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
synchronized (lock) {
return context.getKeys(slice);
}
}
@NotNull
@Override
@TestOnly
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
synchronized (lock) {
return context.getSliceContents(slice);
}
}
}
private static class LockProtectedTrace implements BindingTrace { private static class LockProtectedTrace implements BindingTrace {
private final Object lock; private final Object lock;
private final BindingTrace trace; private final BindingTrace trace;
private final BindingContext context;
public LockProtectedTrace(@NotNull Object lock, @NotNull BindingTrace trace) { public LockProtectedTrace(@NotNull Object lock, @NotNull BindingTrace trace) {
this.lock = lock; this.lock = lock;
this.trace = trace; this.trace = trace;
this.context = new LockProtectedContext(lock, trace.getBindingContext());
} }
@Override @Override
public BindingContext getBindingContext() { public BindingContext getBindingContext() {
synchronized (lock) { return context;
return trace.getBindingContext();
}
} }
@Override @Override