]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Race condition fix caused deadlock, allow parallel recomputation 76/1676/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 3 Apr 2018 07:52:58 +0000 (10:52 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 3 Apr 2018 07:52:58 +0000 (10:52 +0300)
refs #7826

Change-Id: Ib0515c2ae7d3e6d1474f991965307969a439baf7

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java

index ce3b7cc5fd22ff49fd4b2a01c5205d3647c2f82e..41aff8d3122813cf153cdd43e36e5dea197ccd36 100644 (file)
@@ -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<SCLValue> values, final String prefix) {          
     }
 
-    private final Function<String, SCLValue> 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<String, SCLRelation> 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<String, SCLEntityType> 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