From fbe1491ad49286dcce3b63d809b08fa259c50d6e Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 26 Jul 2013 19:29:14 +0400 Subject: [PATCH] Lock based binding context --- .../lazy/storage/LockBasedStorageManager.java | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/storage/LockBasedStorageManager.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/storage/LockBasedStorageManager.java index e022979d5cd..9a168659163 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/storage/LockBasedStorageManager.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/storage/LockBasedStorageManager.java @@ -16,12 +16,14 @@ package org.jetbrains.jet.lang.resolve.lazy.storage; +import com.google.common.collect.ImmutableMap; import com.intellij.openapi.util.Computable; import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.containers.ConcurrentWeakValueHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.resolve.BindingContext; 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 getDiagnostics() { + synchronized (lock) { + return context.getDiagnostics(); + } + } + + @Nullable + @Override + public V get(ReadOnlySlice slice, K key) { + synchronized (lock) { + return context.get(slice, key); + } + } + + @NotNull + @Override + public Collection getKeys(WritableSlice slice) { + synchronized (lock) { + return context.getKeys(slice); + } + } + + @NotNull + @Override + @TestOnly + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + synchronized (lock) { + return context.getSliceContents(slice); + } + } + } + private static class LockProtectedTrace implements BindingTrace { private final Object lock; private final BindingTrace trace; + private final BindingContext context; public LockProtectedTrace(@NotNull Object lock, @NotNull BindingTrace trace) { this.lock = lock; this.trace = trace; + this.context = new LockProtectedContext(lock, trace.getBindingContext()); } @Override public BindingContext getBindingContext() { - synchronized (lock) { - return trace.getBindingContext(); - } + return context; } @Override