From: Hannu Niemistö Date: Tue, 3 Apr 2018 07:52:58 +0000 (+0300) Subject: Race condition fix caused deadlock, allow parallel recomputation X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=bce5f7482d0c9bde9ed26d8c76638603f925c820;p=simantics%2Fplatform.git Race condition fix caused deadlock, allow parallel recomputation refs #7826 Change-Id: Ib0515c2ae7d3e6d1474f991965307969a439baf7 (cherry picked from commit 1c75fce06a3e89c74d3dccd055a7082e9d0375d7) --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java index ce3b7cc5f..41aff8d31 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; @@ -64,11 +63,15 @@ public abstract class LazyModule implements Module { public void findValuesForPrefix(final Collection values, final String prefix) { } - private final Function createValue = this::createValue; - @Override public SCLValue getValue(String name) { - return values.computeIfAbsent(name, createValue); + if(values.containsKey(name)) + return values.get(name); + else { + SCLValue value = createValue(name); + values.put(name, value); + return value; + } } @Override @@ -76,16 +79,24 @@ public abstract class LazyModule implements Module { return null; } - private final Function createRelation = this::createRelation; - public SCLRelation getRelation(String name) { - return relations.computeIfAbsent(name, createRelation); + if(relations.containsKey(name)) + return relations.get(name); + else { + SCLRelation relation = createRelation(name); + relations.put(name, relation); + return relation; + } } - private final Function createEntityType = this::createEntityType; - public SCLEntityType getEntityType(String name) { - return entityTypes.computeIfAbsent(name, createEntityType); + if(entityTypes.containsKey(name)) + return entityTypes.get(name); + else { + SCLEntityType entityType = createEntityType(name); + entityTypes.put(name, entityType); + return entityType; + } } @Override