Skip to content

Commit

Permalink
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -23,10 +23,10 @@ DynamicObjectFactory createConditionVariableShape(

DynamicObject createConditionVariable(
DynamicObjectFactory factory,
Object condition);
ConditionVariableObject condition);

boolean isConditionVariable(DynamicObject object);

Object getCondition(DynamicObject object);
ConditionVariableObject getCondition(DynamicObject object);

}
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
@CoreClass("ConditionVariable")
public abstract class ConditionVariableNodes {

private static Object getCondition(DynamicObject conditionVariable) {
private static ConditionVariableObject getCondition(DynamicObject conditionVariable) {
return Layouts.CONDITION_VARIABLE.getCondition(conditionVariable);
}

@@ -50,7 +50,7 @@ public AllocateNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
return allocateNode.allocate(rubyClass, new Object());
return allocateNode.allocate(rubyClass, new ConditionVariableObject());
}

}
@@ -72,7 +72,7 @@ public RubyNode coerceDuration(RubyNode duration) {
public DynamicObject wait(DynamicObject conditionVariable, DynamicObject mutex, long timeoutInMillis) {
final ReentrantLock lock = Layouts.MUTEX.getLock(mutex);
final DynamicObject thread = getContext().getThreadManager().getCurrentThread();
final Object condition = getCondition(conditionVariable);
final ConditionVariableObject condition = getCondition(conditionVariable);

doWait(timeoutInMillis, lock, thread, condition);

@@ -130,7 +130,7 @@ public abstract static class SignalNode extends UnaryCoreMethodNode {
@TruffleBoundary
@Specialization
public DynamicObject doSignal(DynamicObject conditionVariable) {
final Object condition = getCondition(conditionVariable);
final ConditionVariableObject condition = getCondition(conditionVariable);
synchronized (condition) {
condition.notify();
}
@@ -145,7 +145,7 @@ public abstract static class BroadcastNode extends UnaryCoreMethodNode {
@TruffleBoundary
@Specialization
public DynamicObject doBroadcast(DynamicObject conditionVariable) {
final Object condition = getCondition(conditionVariable);
final ConditionVariableObject condition = getCondition(conditionVariable);
synchronized (condition) {
condition.notifyAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2016 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
*/
package org.jruby.truffle.core.mutex;

public class ConditionVariableObject {
}

2 comments on commit 64cb1a9

@chrisseaton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're doing this just for the monitor aren't you? Is there no explicit monitor or condition variable class that has the functionality we want as methods?

@eregon
Copy link
Member

@eregon eregon commented on 64cb1a9 Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisseaton Not really, the only way to get one is with an explicit and extra Lock object and calling newCondition().

Please sign in to comment.