|
20 | 20 |
|
21 | 21 | import org.truffleruby.Layouts;
|
22 | 22 | import org.truffleruby.RubyLanguage;
|
| 23 | +import org.truffleruby.collections.ConcurrentOperations; |
23 | 24 | import org.truffleruby.RubyContext;
|
24 | 25 | import org.truffleruby.core.klass.ClassNodes;
|
25 | 26 | import org.truffleruby.core.method.MethodFilter;
|
@@ -333,18 +334,22 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
|
333 | 334 |
|
334 | 335 | SharedObjects.propagate(context, rubyModuleObject, value);
|
335 | 336 |
|
336 |
| - while (true) { |
337 |
| - final RubyConstant previous = constants.get(name); |
338 |
| - final boolean isPrivate = previous != null && previous.isPrivate(); |
339 |
| - final boolean isDeprecated = previous != null && previous.isDeprecated(); |
340 |
| - final SourceSection sourceSection = currentNode != null ? currentNode.getSourceSection() : null; |
341 |
| - final RubyConstant newValue = new RubyConstant(rubyModuleObject, value, isPrivate, autoload, isDeprecated, sourceSection); |
| 337 | + RubyConstant previous; |
| 338 | + RubyConstant newConstant; |
| 339 | + do { |
| 340 | + previous = constants.get(name); |
| 341 | + newConstant = newConstant(currentNode, value, autoload, previous); |
| 342 | + } while (!ConcurrentOperations.replace(constants, name, previous, newConstant)); |
342 | 343 |
|
343 |
| - if (previous == null ? constants.putIfAbsent(name, newValue) == null : constants.replace(name, previous, newValue)) { |
344 |
| - newConstantsVersion(); |
345 |
| - return previous; |
346 |
| - } |
347 |
| - } |
| 344 | + newConstantsVersion(); |
| 345 | + return previous; |
| 346 | + } |
| 347 | + |
| 348 | + private RubyConstant newConstant(Node currentNode, Object value, boolean autoload, RubyConstant previous) { |
| 349 | + final boolean isPrivate = previous != null && previous.isPrivate(); |
| 350 | + final boolean isDeprecated = previous != null && previous.isDeprecated(); |
| 351 | + final SourceSection sourceSection = currentNode != null ? currentNode.getSourceSection() : null; |
| 352 | + return new RubyConstant(rubyModuleObject, value, isPrivate, autoload, isDeprecated, sourceSection); |
348 | 353 | }
|
349 | 354 |
|
350 | 355 | @TruffleBoundary
|
|
0 commit comments