Skip to content

Commit

Permalink
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -15,8 +15,10 @@
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.Ruby;
import org.jruby.RubyGC;
import org.jruby.ext.rbconfig.RbConfigLibrary;
@@ -520,4 +522,20 @@ protected static boolean canLower(long value) {

}

@CoreMethod(names = "synchronized", isModuleFunction = true, required = 1, needsBlock = true)
public abstract static class SynchronizedPrimitiveNode extends YieldingCoreMethodNode {

public SynchronizedPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

// We must not allow to synchronize on boxed primitives.
@Specialization(guards = "isRubyProc(block)")
public Object synchronize(VirtualFrame frame, RubyBasicObject self, RubyBasicObject block) {
synchronized (self) {
return yield(frame, block);
}
}
}

}
6 changes: 2 additions & 4 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -152,12 +152,10 @@ class Rubinius::ByteArray

end

# Don't apply any synchronization at the moment

module Rubinius

def self.synchronize(object)
yield
def self.synchronize(object, &block)
Truffle::Primitive.synchronized(object, &block)
end

end

0 comments on commit 27e8286

Please sign in to comment.