Skip to content

Commit

Permalink
* eval.c (stack_check): made flag per threads.
Browse files Browse the repository at this point in the history
* thread.c (rb_thread_set_raised, rb_thread_reset_raised): prefixed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Feb 28, 2008
1 parent 5848032 commit ecd35c0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Thu Feb 28 13:51:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* eval.c (stack_check): made flag per threads.

* thread.c (rb_thread_set_raised, rb_thread_reset_raised): prefixed.

Thu Feb 28 11:43:56 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* file.c (rb_file_flock): immediately returns on EAGAIN if
Expand Down
16 changes: 9 additions & 7 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ rb_longjmp(int tag, VALUE mesg)
const char *file;
int line = 0;

if (thread_set_raised(th)) {
if (rb_thread_set_raised(th)) {
th->errinfo = exception_error;
JUMP_TAG(TAG_FATAL);
}
Expand Down Expand Up @@ -703,7 +703,7 @@ rb_longjmp(int tag, VALUE mesg)
th->errinfo = mesg;
}
else if (status) {
thread_reset_raised(th);
rb_thread_reset_raised(th);
JUMP_TAG(status);
}
}
Expand All @@ -715,7 +715,7 @@ rb_longjmp(int tag, VALUE mesg)
0 /* TODO: id */, 0 /* TODO: klass */);
}

thread_reset_raised(th);
rb_thread_reset_raised(th);
JUMP_TAG(tag);
}

Expand Down Expand Up @@ -1241,17 +1241,17 @@ rb_with_disable_interrupt(VALUE (*proc)(ANYARGS), VALUE data)
static inline void
stack_check(void)
{
static int overflowing = 0;
rb_thread_t *th = GET_THREAD();

if (!overflowing && ruby_stack_check()) {
if (!rb_thread_stack_overflowing_p(th) && ruby_stack_check()) {
int state;
overflowing = 1;
rb_thread_set_stack_overflow(th);
PUSH_TAG();
if ((state = EXEC_TAG()) == 0) {
rb_exc_raise(sysstack_error);
}
POP_TAG();
overflowing = 0;
rb_thread_reset_stack_overflow(th);
JUMP_TAG(state);
}
}
Expand Down Expand Up @@ -1427,6 +1427,8 @@ rb_call0(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope
}
}

stack_check();

{
VALUE val;
/*
Expand Down
12 changes: 10 additions & 2 deletions eval_intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,16 @@ while (0)
void rb_thread_cleanup(void);
void rb_thread_wait_other_threads(void);

int thread_set_raised(rb_thread_t *th);
int thread_reset_raised(rb_thread_t *th);
#define RAISED_EXCEPTION 1
#define RAISED_STACKOVERFLOW 2
int rb_thread_set_raised(rb_thread_t *th);
int rb_thread_reset_raised(rb_thread_t *th);
#define rb_thread_set_stack_overflow(th) \
((th)->raised_flag |= RAISED_STACKOVERFLOW)
#define rb_thread_reset_stack_overflow(th) \
((th)->raised_flag &= ~RAISED_STACKOVERFLOW)
#define rb_thread_stack_overflowing_p(th) \
(((th)->raised_flag & RAISED_STACKOVERFLOW) != 0)

VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
VALUE rb_make_exception(int argc, VALUE *argv);
Expand Down
16 changes: 8 additions & 8 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,22 +845,22 @@ rb_thread_signal_exit(void *thptr)
}

int
thread_set_raised(rb_thread_t *th)
rb_thread_set_raised(rb_thread_t *th)
{
if (th->raised_flag) {
if (th->raised_flag & RAISED_EXCEPTION) {
return 1;
}
th->raised_flag = 1;
th->raised_flag |= RAISED_EXCEPTION;
return 0;
}

int
thread_reset_raised(rb_thread_t *th)
rb_thread_reset_raised(rb_thread_t *th)
{
if (th->raised_flag == 0) {
if (!(th->raised_flag & RAISED_EXCEPTION)) {
return 0;
}
th->raised_flag = 0;
th->raised_flag &= ~RAISED_EXCEPTION;
return 1;
}

Expand Down Expand Up @@ -3005,15 +3005,15 @@ ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always)
th->tracing = 1;
}

raised = thread_reset_raised(th);
raised = rb_thread_reset_raised(th);

PUSH_TAG();
if ((state = EXEC_TAG()) == 0) {
result = (*func)(arg, tracing);
}

if (raised) {
thread_set_raised(th);
rb_thread_set_raised(th);
}
POP_TAG();

Expand Down

0 comments on commit ecd35c0

Please sign in to comment.