Skip to content

Commit 0b306fb

Browse files
committed
Cleaned up checking for interrupted thread.
1 parent 11c9a6f commit 0b306fb

19 files changed

+107
-154
lines changed

core/rubinius.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ def self.thread_state
219219
raise PrimitiveFailure, "Rubinius.thread_state primitive failed"
220220
end
221221

222-
def self.check_interrupts
223-
Rubinius.primitive :vm_check_interrupts
224-
raise PrimitiveFailure, "Rubinius.check_interrupts primitive failed"
225-
end
226-
227222
# Used to invoke a CompiledCode instance as a script body. Sets up the MAIN
228223
# object as self and bypasses JIT'ing (because why JIT a script you only run
229224
# once).

machine/builtin/block_environment.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -462,28 +462,18 @@ namespace rubinius {
462462

463463
OnStack<2> os(state, env, mod);
464464

465-
// Check the stack and interrupts here rather than in the interpreter
466-
// loop itself.
467-
if(state->check_interrupts(state)) {
468-
tooling::BlockEntry method(state, env, mod);
469-
value = (*mcode->run)(state, mcode);
470-
}
465+
tooling::BlockEntry method(state, env, mod);
466+
value = (*mcode->run)(state, mcode);
471467
} else {
472-
// Check the stack and interrupts here rather than in the interpreter
473-
// loop itself.
474-
if(state->check_interrupts(state)) {
475-
value = (*mcode->run)(state, mcode);
476-
}
477-
}
478-
#else
479-
// Check the stack and interrupts here rather than in the interpreter
480-
// loop itself.
481-
if(state->check_interrupts(state)) {
482468
value = (*mcode->run)(state, mcode);
483469
}
470+
#else
471+
value = (*mcode->run)(state, mcode);
484472
#endif
485473

486-
state->vm()->pop_call_frame(previous_frame);
474+
if(!state->vm()->pop_call_frame(state, previous_frame)) {
475+
return NULL;
476+
}
487477

488478
return value;
489479
}

machine/builtin/channel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace rubinius {
134134
ts.tv_nsec = nano % NANOSECONDS;
135135
}
136136

137-
if(!state->check_async(state)) {
137+
if(state->vm()->thread_interrupted_p(state)) {
138138
return NULL;
139139
}
140140

@@ -161,7 +161,7 @@ namespace rubinius {
161161

162162
// or there are values available.
163163
if(self->semaphore_count() > 0 || !self->value()->empty_p()) break;
164-
if(!state->check_async(state)) {
164+
if(state->vm()->thread_interrupted_p(state)) {
165165
exception = true;
166166
break;
167167
}
@@ -173,7 +173,7 @@ namespace rubinius {
173173
self->unpin();
174174
self->_waiters_--;
175175

176-
if(exception || !state->check_async(state)) return NULL;
176+
if(exception) return NULL;
177177

178178
if(self->semaphore_count() > 0) {
179179
self->dec_semaphore_count();

machine/builtin/fiber.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ namespace rubinius {
155155

156156
cur = Fiber::current(state);
157157

158+
// TODO: clean up this and the following conditional.
159+
if(state->vm()->thread_interrupted_p(state)) {
160+
return NULL;
161+
}
162+
158163
if(!cur->exception()->nil_p()) {
159164
state->raise_exception(cur->exception());
160165
cur->exception(state, nil<Exception>());
161-
return 0;
166+
return NULL;
162167
}
163168

164169
Array* ret = cur->value();

machine/builtin/io.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace rubinius {
288288

289289
if(events == -1) {
290290
if(errno == EAGAIN || errno == EINTR) {
291-
if(!state->check_async(state)) return NULL;
291+
if(state->vm()->thread_interrupted_p(state)) return NULL;
292292

293293
// Recalculate the limit and go again.
294294
if(maybe_limit) {
@@ -678,7 +678,7 @@ namespace rubinius {
678678

679679
if(bytes_read == -1) {
680680
if(errno == EAGAIN || errno == EINTR) {
681-
if(!state->check_async(state)) {
681+
if(state->vm()->thread_interrupted_p(state)) {
682682
if(malloc_buf) free(malloc_buf);
683683
return NULL;
684684
}
@@ -967,7 +967,7 @@ namespace rubinius {
967967

968968
if(bytes_read == -1) {
969969
if(errno == EINTR) {
970-
if(!state->check_async(state)) return NULL;
970+
if(state->vm()->thread_interrupted_p(state)) return NULL;
971971
ensure_open(state);
972972
goto retry;
973973
} else {
@@ -1321,7 +1321,7 @@ namespace rubinius {
13211321

13221322
if(code == -1) {
13231323
if(errno == EAGAIN || errno == EINTR) {
1324-
if(!state->check_async(state)) return NULL;
1324+
if(state->vm()->thread_interrupted_p(state)) return NULL;
13251325
ensure_open(state);
13261326
goto retry;
13271327
}
@@ -1429,7 +1429,7 @@ namespace rubinius {
14291429
break;
14301430
case EAGAIN:
14311431
case EINTR:
1432-
if(!state->check_async(state)) return NULL;
1432+
if(state->vm()->thread_interrupted_p(state)) return NULL;
14331433
io->ensure_open(state);
14341434
goto retry;
14351435
default:

machine/builtin/native_method.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ namespace rubinius {
741741
} catch(const RubyException& exc) {
742742
LEAVE_CAPI(state);
743743

744-
state->vm()->pop_call_frame(previous_frame);
744+
state->vm()->pop_call_frame(state, previous_frame);
745745
env->set_current_call_frame(saved_frame);
746746
env->set_current_native_frame(nmf.previous());
747747
ep.pop(env);
@@ -751,15 +751,14 @@ namespace rubinius {
751751

752752
LEAVE_CAPI(state);
753753

754-
state->vm()->pop_call_frame(previous_frame);
754+
if(!state->vm()->pop_call_frame(state, previous_frame)) {
755+
value = NULL;
756+
}
757+
755758
env->set_current_call_frame(saved_frame);
756759
env->set_current_native_frame(nmf.previous());
757760
ep.pop(env);
758761

759-
// Handle any signals that occurred while the native method
760-
// was running.
761-
if(!state->check_async(state)) return NULL;
762-
763762
return value;
764763
}
765764

machine/builtin/system.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ namespace rubinius {
657657
switch(errno) {
658658
case EAGAIN:
659659
case EINTR:
660-
if(!state->check_async(state)) {
660+
if(state->vm()->thread_interrupted_p(state)) {
661661
close(output[0]);
662662
return NULL;
663663
}
@@ -783,7 +783,7 @@ namespace rubinius {
783783
if(pid == -1) {
784784
if(errno == ECHILD) return cFalse;
785785
if(errno == EINTR) {
786-
if(!state->check_async(state)) return NULL;
786+
if(state->vm()->thread_interrupted_p(state)) return NULL;
787787
goto retry;
788788
}
789789

@@ -1091,19 +1091,11 @@ namespace rubinius {
10911091
if(!state->park(state)) return NULL;
10921092
}
10931093

1094-
if(!state->check_async(state)) return NULL;
1094+
if(state->vm()->thread_interrupted_p(state)) return NULL;
10951095

10961096
return Fixnum::from(time(0) - start);
10971097
}
10981098

1099-
Object* System::vm_check_interrupts(STATE) {
1100-
if(state->check_async(state)) {
1101-
return cNil;
1102-
} else {
1103-
return NULL;
1104-
}
1105-
}
1106-
11071099
static inline double tv_to_dbl(struct timeval* tv) {
11081100
return (double)tv->tv_sec + ((double)tv->tv_usec / 1000000.0);
11091101
}

machine/builtin/system.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ namespace rubinius {
167167
// Rubinius.primitive :vm_sleep
168168
static Object* vm_sleep(STATE, Object* duration);
169169

170-
// Rubinius.primitive :vm_check_interrupts
171-
static Object* vm_check_interrupts(STATE);
172-
173170
// Rubinius.primitive :vm_times
174171
static Array* vm_times(STATE);
175172

machine/capi/capi.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ namespace rubinius {
5858
return false;
5959
}
6060

61-
if(unlikely(state->check_local_interrupts())) {
62-
if(!state->process_async(state)) return false;
61+
if(unlikely(state->vm()->check_local_interrupts())) {
62+
return state->vm()->check_thread_raise_or_kill(state);
6363
}
64+
6465
return true;
6566
}
6667

machine/capi/thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C" {
6363
ret = select(max, read, write, except, tvp);
6464
}
6565

66-
bool ok = env->state()->check_async(env->state());
66+
bool ok = !env->state()->vm()->thread_interrupted_p(env->state());
6767

6868
ENTER_CAPI(env->state());
6969

@@ -199,7 +199,7 @@ extern "C" {
199199
State* state = env->state();
200200
void* ret = NULL;
201201

202-
if(!state->check_async(env->state())) {
202+
if(state->vm()->thread_interrupted_p(state)) {
203203
return ret;
204204
}
205205
if(ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {

machine/instructions.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,8 +1766,6 @@ instruction check_interrupts() [ -- ]
17661766
mcode->call_count++;
17671767
}
17681768

1769-
if(!state->check_async(state)) RUN_EXCEPTION();
1770-
17711769
state->vm()->checkpoint(state);
17721770
end
17731771

machine/jit/llvm/util.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extern "C" {
179179
}
180180

181181
void rbx_pop_call_frame(STATE) {
182-
state->vm()->pop_call_frame(state->vm()->call_frame()->previous);
182+
state->vm()->pop_call_frame(state, state->vm()->call_frame()->previous);
183183
}
184184

185185
Object* rbx_splat_send(STATE, CallSite* call_site,
@@ -1007,20 +1007,10 @@ extern "C" {
10071007
}
10081008

10091009
Object* rbx_prologue_check(STATE) {
1010-
if(!state->check_interrupts(state)) return NULL;
1011-
1012-
// TODO: ensure no stack references exist at this point
1013-
// state->vm()->checkpoint(state);
1014-
10151010
return cTrue;
10161011
}
10171012

10181013
Object* rbx_check_interrupts(STATE) {
1019-
if(!state->check_async(state)) return NULL;
1020-
1021-
// TODO: ensure no stack references exist at this point
1022-
// state->vm()->checkpoint(state);
1023-
10241014
return cTrue;
10251015
}
10261016

machine/machine_code.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -792,29 +792,25 @@ namespace rubinius {
792792
// Check the stack and interrupts here rather than in the interpreter
793793
// loop itself.
794794
OnStack<2> os(state, exec, code);
795-
if(state->check_interrupts(state)) {
796-
tooling::MethodEntry method(state, exec, scope->module(), args, code);
795+
tooling::MethodEntry method(state, exec, scope->module(), args, code);
797796

798-
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
799-
value = (*mcode->run)(state, mcode);
800-
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
801-
}
797+
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
798+
value = (*mcode->run)(state, mcode);
799+
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
802800
} else {
803-
if(state->check_interrupts(state)) {
804-
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
805-
value = (*mcode->run)(state, mcode);
806-
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
807-
}
808-
}
809-
#else
810-
if(state->check_interrupts(state)) {
811801
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
812802
value = (*mcode->run)(state, mcode);
813803
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
814804
}
805+
#else
806+
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
807+
value = (*mcode->run)(state, mcode);
808+
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
815809
#endif
816810

817-
state->vm()->pop_call_frame(previous_frame);
811+
if(!state->vm()->pop_call_frame(state, previous_frame)) {
812+
return NULL;
813+
}
818814

819815
return value;
820816
}
@@ -857,21 +853,16 @@ namespace rubinius {
857853
return NULL;
858854
}
859855

860-
// Do NOT check if we should JIT this. We NEVER want to jit a script.
861-
862-
// Check the stack and interrupts here rather than in the interpreter
863-
// loop itself.
864-
865-
if(!state->check_interrupts(state)) return NULL;
866-
867856
state->vm()->checkpoint(state);
868857

869858
// Don't generate profiling info here, it's expected
870859
// to be done by the caller.
871860

872861
Object* value = (*mcode->run)(state, mcode);
873862

874-
state->vm()->pop_call_frame(previous_frame);
863+
if(!state->vm()->pop_call_frame(state, previous_frame)) {
864+
return NULL;
865+
}
875866

876867
return value;
877868
}

machine/memory/finalizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ namespace memory {
225225
(*process_item_->finalizer)(state, process_item_->object);
226226
}
227227

228-
state->vm()->pop_call_frame(previous_frame);
228+
state->vm()->pop_call_frame(state, previous_frame);
229229
env->set_current_call_frame(0);
230230
env->set_current_native_frame(0);
231231
} else {

machine/park.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace rubinius {
1111
Object* Park::park(STATE) {
12-
if(!state->check_async(state)) return NULL;
12+
if(state->vm()->thread_interrupted_p(state)) return NULL;
1313

1414
utilities::thread::Mutex::LockGuard lg(mutex_);
1515

@@ -25,7 +25,7 @@ namespace rubinius {
2525
cond_.wait(mutex_);
2626
}
2727
mutex_.unlock();
28-
if(!state->check_async(state)) {
28+
if(state->vm()->thread_interrupted_p(state)) {
2929
mutex_.lock();
3030
result = NULL;
3131
break;
@@ -40,7 +40,7 @@ namespace rubinius {
4040

4141
Object* Park::park_timed(STATE, struct timespec* ts) {
4242
utilities::thread::Mutex::LockGuard lg(mutex_);
43-
if(!state->check_async(state)) return NULL;
43+
if(state->vm()->thread_interrupted_p(state)) return NULL;
4444

4545
wake_ = false;
4646
sleeping_ = true;
@@ -59,7 +59,7 @@ namespace rubinius {
5959
}
6060
}
6161
mutex_.unlock();
62-
if(!state->check_async(state)) {
62+
if(state->vm()->thread_interrupted_p(state)) {
6363
mutex_.lock();
6464
timeout = NULL;
6565
break;

0 commit comments

Comments
 (0)