Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 567ae1d5c9e5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64a4164c2a88
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Jul 25, 2015

  1. Copy the full SHA
    98fc73c View commit details
  2. Copy the full SHA
    37726b3 View commit details
  3. Copy the full SHA
    64a4164 View commit details
3 changes: 0 additions & 3 deletions spec/truffle/tags/library/timeout/timeout_tags.txt

This file was deleted.

48 changes: 48 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/QueueNodes.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.*;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.BooleanCastWithDefaultNodeGen;
import org.jruby.truffle.nodes.objects.Allocator;
@@ -31,6 +33,7 @@
import java.util.EnumSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

@@ -126,6 +129,51 @@ public Object popNonBlock(RubyBasicObject self, boolean nonBlocking) {

}

@RubiniusOnly
@CoreMethod(names = "receive_timeout", required = 1, visibility = Visibility.PRIVATE)
@NodeChildren({
@NodeChild(type = RubyNode.class, value = "queue"),
@NodeChild(type = RubyNode.class, value = "duration")
})
public abstract static class ReceiveTimeoutNode extends CoreMethodNode {

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

@Specialization
public Object receiveTimeout(RubyBasicObject self, int duration) {
return receiveTimeout(self, (double) duration);
}

@Specialization
public Object receiveTimeout(RubyBasicObject self, double duration) {
final BlockingQueue<Object> queue = getQueue(self);

final long durationInMillis = (long) (duration * 1000.0);
final long start = System.currentTimeMillis();

return getContext().getThreadManager().runUntilResult(new BlockingAction<Object>() {
@Override
public Object block() throws InterruptedException {
long now = System.currentTimeMillis();
long waited = now - start;
if (waited >= durationInMillis) {
return false;
}

final Object result = queue.poll(durationInMillis, TimeUnit.MILLISECONDS);
if (result == null) {
return false;
} else {
return result;
}
}
});
}

}

@CoreMethod(names = "empty?")
public abstract static class EmptyNode extends CoreMethodArrayArgumentsNode {

This file was deleted.

Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@ public void addAnnotatedPrimitives() {
nodeFactories.addAll(IOPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(IOBufferPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ExceptionPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ChannelPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ThreadPrimitiveNodesFactory.getFactories());

// This comes last as a catch-all
3 changes: 2 additions & 1 deletion truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@ def self.omit(reason)
#require_relative 'core/rubinius/bootstrap/byte_array'
#require_relative 'core/rubinius/bootstrap/call_site'
#require_relative 'core/rubinius/bootstrap/call_custom_cache'
require_relative 'core/rubinius/bootstrap/channel'
#require_relative 'core/rubinius/bootstrap/channel'
require_relative 'core/rubinius/api/shims/channel'
require_relative 'core/rubinius/bootstrap/character'
#require_relative 'core/rubinius/bootstrap/class'
#require_relative 'core/rubinius/bootstrap/compact_lookup_table'
39 changes: 39 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Implementation of Rubinius::Channel using a Queue
module Rubinius
class Channel
def initialize
@queue = Queue.new
end

def send(obj)
@queue << obj
end
alias_method :<<, :send

def receive
@queue.pop
end

def receive_timeout(duration)
Rubinius.privately do
@queue.receive_timeout(duration)
end
end

def try_receive
begin
@queue.pop(true)
rescue ThreadError # queue empty
nil
end
end
end
end
101 changes: 0 additions & 101 deletions truffle/src/main/ruby/core/rubinius/bootstrap/channel.rb

This file was deleted.