[Swift-commit] r6020 - trunk/src/org/griphyn/vdl/mapping
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Fri Nov 9 23:33:48 CST 2012
Author: hategan
Date: 2012-11-09 23:33:48 -0600 (Fri, 09 Nov 2012)
New Revision: 6020
Modified:
trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
Log:
fixed a race condition where a procedure like readData would create a struct in an array before populating the fields; the array would notify listeners of the newly created array element, and code trying to access fields would fail because the fields are not there yet. The fix changes the behaviour of createField as follows: if the new field is a struct, then its fields are also automatically created so that concurrent threads writing and reading on those fields can work with the same objects
Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java 2012-11-10 05:28:59 UTC (rev 6019)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java 2012-11-10 05:33:48 UTC (rev 6020)
@@ -95,6 +95,18 @@
}
}
+ protected void populateStructFields() {
+ for (String name : getType().getFieldNames()) {
+ try {
+ createField(name);
+ }
+ catch (NoSuchFieldException e) {
+ throw new RuntimeException("Internal inconsistency found: field '" + name
+ + "' is listed by the type but createField() claims it is invalid");
+ }
+ }
+ }
+
public void init(MappingParamSet params) {
throw new UnsupportedOperationException();
}
@@ -214,6 +226,26 @@
}
return prefix;
}
+
+ public String getDeclarationLine() {
+ String line = getRoot().getParam(MappingParam.SWIFT_LINE);
+ if (line == null || line.length() == 0) {
+ return null;
+ }
+ else {
+ return line;
+ }
+ }
+
+ public String getThread() {
+ String restartId = getRoot().getParam(MappingParam.SWIFT_RESTARTID);
+ if (restartId != null) {
+ return restartId.substring(0, restartId.lastIndexOf(":"));
+ }
+ else {
+ return null;
+ }
+ }
public DSHandle getField(Path path) throws InvalidPathException {
if (path.isEmpty()) {
@@ -230,7 +262,6 @@
}
}
catch (NoSuchFieldException e) {
- logger.warn("could not find variable: " + field.getId() + " " + path);
throw new InvalidPathException(path, this);
}
}
@@ -316,7 +347,11 @@
return new ArrayDataNode(f, getRoot(), this);
}
else {
- return new DataNode(f, getRoot(), this);
+ DataNode dn = new DataNode(f, getRoot(), this);
+ if (field.getType().isComposite()) {
+ dn.populateStructFields();
+ }
+ return dn;
}
}
More information about the Swift-commit
mailing list