Skip to content

Commit

Permalink
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -29,13 +31,16 @@ public abstract class MutexNodes {
@CoreMethod(names = "allocate", constructor = true)
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {

@Child private AllocateObjectNode allocateNode;

public AllocateNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
return Layouts.MUTEX.createMutex(Layouts.CLASS.getInstanceFactory(rubyClass), new ReentrantLock());
return allocateNode.allocate(rubyClass, new ReentrantLock());
}

}
Original file line number Diff line number Diff line change
@@ -15,22 +15,29 @@
import org.jruby.truffle.nodes.core.CoreClass;
import org.jruby.truffle.nodes.core.CoreMethod;
import org.jruby.truffle.nodes.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

import java.util.concurrent.atomic.AtomicReference;

@CoreClass(name = "Rubinius::AtomicReference")
public abstract class AtomicReferenceNodes {

@CoreMethod(names = "allocate", constructor = true)
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {

@Child private AllocateObjectNode allocateNode;

public AllocateNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
return Layouts.ATOMIC_REFERENCE.createAtomicReference(Layouts.CLASS.getInstanceFactory(rubyClass), nil());
return allocateNode.allocate(rubyClass, new AtomicReference<Object>(nil()));

This comment has been minimized.

Copy link
@eregon

eregon Nov 20, 2015

Member

This seems strange, but it seems necessary indeed.
Mmh, @Volatile is not so transparent.

This comment has been minimized.

Copy link
@pitr-ch

pitr-ch Nov 23, 2015

Author Member

Yeah, I should have added a TODO at least to track it. The @Volatile should not leak here.

}

}

0 comments on commit 43c8e4b

Please sign in to comment.