File tree Expand file tree Collapse file tree 3 files changed +42
-10
lines changed
core/src/main/java/org/jruby/truffle Expand file tree Collapse file tree 3 files changed +42
-10
lines changed Original file line number Diff line number Diff line change 1919import org .jruby .truffle .runtime .core .RubyProc ;
2020import org .jruby .truffle .runtime .core .RubyString ;
2121import org .jruby .truffle .runtime .core .RubyThread ;
22+ import org .jruby .truffle .runtime .util .Consumer ;
2223
2324@ CoreClass (name = "Thread" )
2425public abstract class ThreadNodes {
@@ -97,6 +98,35 @@ public RubyNilClass exit() {
9798
9899 }
99100
101+ @ CoreMethod (names = "kill" )
102+ public abstract static class KillNode extends CoreMethodNode {
103+
104+ public KillNode (RubyContext context , SourceSection sourceSection ) {
105+ super (context , sourceSection );
106+ }
107+
108+ public KillNode (KillNode prev ) {
109+ super (prev );
110+ }
111+
112+ @ Specialization
113+ public RubyThread kill (final RubyThread thread ) {
114+ getContext ().getSafepointManager ().pauseAllThreadsAndExecute (new Consumer <Boolean >() {
115+
116+ @ Override
117+ public void accept (Boolean isPausingThread ) {
118+ if (getContext ().getThreadManager ().getCurrentThread () == thread ) {
119+ throw new ThreadExitException ();
120+ }
121+ }
122+
123+ });
124+
125+ return thread ;
126+ }
127+
128+ }
129+
100130 @ CoreMethod (names = "initialize" , needsBlock = true )
101131 public abstract static class InitializeNode extends CoreMethodNode {
102132
Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ public boolean visit(RubyBasicObject object) {
219219 context .getSafepointManager ().pauseAllThreadsAndExecute (new Consumer <Boolean >() {
220220
221221 @ Override
222- public void accept (Boolean pausingThread ) {
222+ public void accept (Boolean isPausingThread ) {
223223 synchronized (liveObjects ) {
224224 context .getCoreLibrary ().getGlobalVariablesObject ().visitObjectGraph (visitor );
225225 context .getCoreLibrary ().getMainObject ().visitObjectGraph (visitor );
Original file line number Diff line number Diff line change @@ -66,13 +66,13 @@ public void poll() {
6666 try {
6767 assumption .check ();
6868 } catch (InvalidAssumptionException e ) {
69-
7069 waitOnBarrier ();
7170
72- action .accept (false );
73-
74-
75- waitOnBarrier ();
71+ try {
72+ action .accept (false );
73+ } finally {
74+ waitOnBarrier ();
75+ }
7676 }
7777 }
7878
@@ -90,11 +90,13 @@ public void pauseAllThreadsAndExecute(final Consumer<Boolean> action) {
9090
9191 waitOnBarrier ();
9292
93- action .accept (true );
94-
95- waitOnBarrier ();
96-
9793 assumption = Truffle .getRuntime ().createAssumption ();
94+
95+ try {
96+ action .accept (true );
97+ } finally {
98+ waitOnBarrier ();
99+ }
98100 } finally {
99101 lock .unlock ();
100102 }
You can’t perform that action at this time.
0 commit comments