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: 169369049d04
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64bf82244fa6
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on Nov 6, 2014

  1. Copy the full SHA
    379a5dc View commit details
  2. When setting SizedQueue#max=, drain the previous queue to the new res…

    …ized queue.
    
    This has the effect of preserving items in the queue, and prevents the MRI test from hanging.
    cheald committed Nov 6, 2014
    Copy the full SHA
    b03e3dc View commit details
  3. Support the second optional arg for Queue#push, which throws an excep…

    …tion
    
    if the queue is full.
    cheald committed Nov 6, 2014

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a3d2094 View commit details
  4. Merge pull request #2117 from cheald/queue_fixes

    Queue fixes
    enebo committed Nov 6, 2014
    Copy the full SHA
    64bf822 View commit details
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new ConditionVariable(runtime, klass);
}
});
cConditionVariable.undefineMethod("initialize_copy");
cConditionVariable.setReifiedClass(ConditionVariable.class);
cConditionVariable.defineAnnotatedMethods(ConditionVariable.class);
}
18 changes: 11 additions & 7 deletions core/src/main/java/org/jruby/ext/thread/Queue.java
Original file line number Diff line number Diff line change
@@ -65,16 +65,19 @@ public void wakeup(RubyThread thread, Queue data) {
}
};

final RubyThread.Task<IRubyObject, IRubyObject> putTask = new RubyThread.Task<IRubyObject, IRubyObject>() {
final RubyThread.Task<IRubyObject[], IRubyObject> putTask = new RubyThread.Task<IRubyObject[], IRubyObject>() {
@Override
public IRubyObject run(ThreadContext context, IRubyObject data) throws InterruptedException {
public IRubyObject run(ThreadContext context, IRubyObject[] args) throws InterruptedException {
final BlockingQueue<IRubyObject> queue = getQueueSafe();
queue.put(data);
if(args.length == 2 && args[1].isTrue() && queue.remainingCapacity() == 0) {
throw context.runtime.newThreadError("queue full");
}
queue.put(args[0]);
return context.nil;
}

@Override
public void wakeup(RubyThread thread, IRubyObject data) {
public void wakeup(RubyThread thread, IRubyObject[] data) {
thread.getNativeThread().interrupt();
}
};
@@ -90,6 +93,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new Queue(runtime, klass);
}
});
cQueue.undefineMethod("initialize_copy");
cQueue.setReifiedClass(Queue.class);
cQueue.defineAnnotatedMethods(Queue.class);
}
@@ -165,11 +169,11 @@ public IRubyObject pop(ThreadContext context, IRubyObject arg0) {
return pop(context, !arg0.isTrue());
}

@JRubyMethod(name = {"push", "<<", "enq"})
public IRubyObject push(ThreadContext context, final IRubyObject value) {
@JRubyMethod(name = {"push", "<<", "enq"}, required = 1, optional = 1)
public IRubyObject push(ThreadContext context, final IRubyObject[] args) {
checkShutdown();
try {
context.getThread().executeTask(context, value, putTask);
context.getThread().executeTask(context, args, putTask);
return this;
} catch (InterruptedException ie) {
throw context.runtime.newThreadError("interrupted in " + getMetaClass().getName() + "#push");
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/ext/thread/SizedQueue.java
Original file line number Diff line number Diff line change
@@ -82,8 +82,10 @@ public RubyNumeric max(ThreadContext context) {
}

@JRubyMethod(name = "max=")
public IRubyObject max_set(ThreadContext context, IRubyObject arg) {
public synchronized IRubyObject max_set(ThreadContext context, IRubyObject arg) {
BlockingQueue<IRubyObject> oldQueue = this.queue;
initialize(context, arg);
oldQueue.drainTo(this.queue);
return arg;
}

5 changes: 4 additions & 1 deletion test/mri/excludes/TestQueue.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
exclude :test_sized_queue_assign_max, "hangs"
exclude :test_thr_kill, "needs investigation"
exclude :test_thr_kill, "needs investigation"
exclude :test_dump, "tests MRI-specific exception"
exclude :test_queue_initialized, "tests MRI-specific failure"
exclude :test_sized_queue_initialized, "tests MRI-specific failure"