Skip to content

Commit 473f48e

Browse files
committed
Minor cleanup
1 parent 4dfcabd commit 473f48e

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

spec/ruby/shared/sizedqueue/enque.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
q << 1
3838

3939
t = Thread.new {
40-
-> { q.send(@method, 2) }.should raise_error(ClosedQueueError)
40+
-> { q.send(@method, 2) }.should raise_error(ClosedQueueError, "queue closed")
4141
}
4242

4343
Thread.pass until q.num_waiting == 1
@@ -115,17 +115,20 @@
115115
-> { q.send(@method, 2, timeout: 1) }.should raise_error(ClosedQueueError, "queue closed")
116116
end
117117

118-
it "raise ClosedQueueError when getting closed during wait" do
118+
it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do
119119
q = @object.call(1)
120-
q.push(1)
120+
q << 1
121121

122122
t = Thread.new {
123-
-> { q.push(1, timeout: 0.1) }.should raise_error(ClosedQueueError, "queue closed")
123+
-> { q.send(@method, 1, timeout: 0.1) }.should raise_error(ClosedQueueError, "queue closed")
124124
}
125125

126-
sleep(0.05)
126+
Thread.pass until q.num_waiting == 1
127+
127128
q.close
129+
128130
t.join
131+
q.pop.should == 1
129132
end
130133
end
131134
end

spec/truffleruby.next-specs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ spec/ruby/core/queue/shift_spec.rb
2929
spec/ruby/core/sizedqueue/deq_spec.rb
3030
spec/ruby/core/sizedqueue/pop_spec.rb
3131
spec/ruby/core/sizedqueue/shift_spec.rb
32+
spec/ruby/core/sizedqueue/append_spec.rb
33+
spec/ruby/core/sizedqueue/enq_spec.rb
34+
spec/ruby/core/sizedqueue/push_spec.rb
3235

3336
spec/ruby/core/module/refinements_spec.rb
3437
spec/ruby/core/refinement/refined_class_spec.rb
3538
spec/ruby/core/module/used_refinements_spec.rb
3639
spec/ruby/optional/capi/hash_spec.rb
37-
spec/ruby/core/sizedqueue/append_spec.rb
38-
spec/ruby/core/sizedqueue/enq_spec.rb
39-
spec/ruby/core/sizedqueue/push_spec.rb

src/main/java/org/truffleruby/core/queue/SizedQueueNodes.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ private static void doPushBlocking(Node node, final Object value, final SizedQue
144144
}
145145

146146
@Specialization(guards = "!nonBlocking")
147-
protected static Object pushBlocking(
147+
protected static Object pushTimeout(
148148
Node node, RubySizedQueue self, final Object value, boolean nonBlocking, long timeoutMilliseconds,
149149
@Cached @Shared PropagateSharingNode propagateSharingNode) {
150150
final SizedQueue queue = self.queue;
151151
propagateSharingNode.execute(node, self, value);
152152
final long deadline = System.currentTimeMillis() + timeoutMilliseconds;
153153

154-
var success = getContext(node).getThreadManager().runUntilResult(node, () -> {
154+
boolean success = getContext(node).getThreadManager().runUntilResult(node, () -> {
155155
final long currentTimeout = deadline - System.currentTimeMillis();
156156
final Object result;
157157

@@ -164,11 +164,14 @@ protected static Object pushBlocking(
164164
if (result == SizedQueue.CLOSED) {
165165
throw new RaiseException(getContext(node), coreExceptions(node).closedQueueError(node));
166166
}
167-
return result;
167+
168+
return (boolean) result;
168169
});
169-
if ((boolean) success) {
170+
171+
if (success) {
170172
return self;
171173
}
174+
172175
return nil;
173176
}
174177

0 commit comments

Comments
 (0)