When trying ... I realized that we don't yet have a straightforward mechanism for saying "Bind this object to this name, but only if there isn't already an object bound there". This is the sort of thing that is supposed to be done as
ns.bind(name, obj, Prior.wasUnbound());
but the implementation of RecordTypeProxy.bindIn(ns,name,va,prior) ignores prior, and, anyway, namespace_handle::bind_new() and the like simply throw core::unimplemented.
As a stopgap, this can probably be done as something like
R val = ns.lookup(name, R.type);
if (val == null) {
val = isolated(() -> {
R v2 = ns.lookup(name, R.type);
if (v2 != null) { return v2; }
return ns.bind(name, R.create.record());
});
}
This checks first. If it's null, it goes into an isolated block and checks again, freezing. If the value is still null, it sets it and then publishes. If the publish fails, it's because somebody else set the value, which we'll find the next time through the block. Otherwise, we succeed in setting the value.
[imported from HPE issue 253]
When trying ... I realized that we don't yet have a straightforward mechanism for saying "Bind this object to this name, but only if there isn't already an object bound there". This is the sort of thing that is supposed to be done as
but the implementation of
RecordTypeProxy.bindIn(ns,name,va,prior)
ignoresprior
, and, anyway,namespace_handle::bind_new()
and the like simply throwcore::unimplemented
.As a stopgap, this can probably be done as something like
This checks first. If it's null, it goes into an isolated block and checks again, freezing. If the value is still null, it sets it and then publishes. If the publish fails, it's because somebody else set the value, which we'll find the next time through the block. Otherwise, we succeed in setting the value.