Visitar URL original
Merge pull request #9948 from headius/regexp_no_sleep · jruby/jruby@2916dda · GitHub
Skip to content

Commit 2916dda

Browse files
authored
Merge pull request #9948 from headius/regexp_no_sleep
Remove SLEEP status update from Regexp matches
2 parents 07e498e + 36d3775 commit 2916dda

2 files changed

Lines changed: 49 additions & 14 deletions

File tree

‎core/src/main/java/org/jruby/RubyThread.java‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,34 +2072,29 @@ public default int run(ThreadContext context, Data data, byte[] bytes, int start
20722072
}
20732073

20742074
/**
2075-
* Execute an interruptible regexp operation with the given function and bytess.
2076-
* @param context
2077-
* @param matcher
2078-
* @param start
2079-
* @param range
2080-
* @param option
2081-
* @param task
2082-
* @return ""
2083-
* @param <Data>
2075+
* Execute an interruptible {@link RegexMatch} with the given parameters.
2076+
* @param context the current context
2077+
* @param matcher the matcher with which to perform the matching operation
2078+
* @param start the start of the match
2079+
* @param range the range of the match
2080+
* @param option option for the match
2081+
* @param task the interruptible match task to call
2082+
* @return an int result of the match operation
20842083
* @throws InterruptedException when interrupted
20852084
*/
2086-
public <Data> int executeRegexp(
2085+
public int executeRegexp(
20872086
ThreadContext context,
20882087
Matcher matcher, int start, int range, int option,
20892088
RegexMatch task) throws InterruptedException {
2090-
Status oldStatus = STATUS.get(this);
20912089
try {
20922090
this.unblockArg = matcher;
20932091
this.unblockFunc = task;
20942092

20952093
// check for interrupt before going into blocking call
20962094
blockingThreadPoll(context);
20972095

2098-
STATUS.set(this, Status.SLEEP);
2099-
21002096
return task.run(matcher, start, range, option);
21012097
} finally {
2102-
STATUS.set(this, oldStatus);
21032098
this.unblockFunc = null;
21042099
this.unblockArg = null;
21052100
pollThreadEvents(context);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "Regexp matching" do
4+
before :each do
5+
ready = Queue.new
6+
input = 'a' * 1000 + '!'
7+
@thread = Thread.new do
8+
ready << true
9+
# The backreference prevents caching from eliminating the backtracking.
10+
/\A(a|aa)+\1\z/.match(input)
11+
rescue RuntimeError => error
12+
error
13+
end
14+
15+
ready.pop
16+
sleep 0.01 # Allow the thread to enter the regexp match.
17+
end
18+
19+
after :each do
20+
@thread.kill
21+
@thread.join
22+
end
23+
24+
it "keeps the thread status as run during a long match" do
25+
@thread.status.should == 'run'
26+
end
27+
28+
it "can be interrupted by Thread#raise during a long match" do
29+
@thread.raise RuntimeError, 'interrupted'
30+
@thread.join(5).should == @thread
31+
@thread.value.should.is_a?(RuntimeError)
32+
@thread.value.message.should == 'interrupted'
33+
end
34+
35+
it "can be interrupted by Thread#kill during a long match" do
36+
@thread.kill
37+
@thread.join(5).should == @thread
38+
@thread.status.should == false
39+
end
40+
end

0 commit comments

Comments
 (0)