summaryrefslogtreecommitdiff
path: root/vm_trace.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-10 18:36:54 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-10 18:36:54 (GMT)
commit53861b8acd18cc5241d044f6246568cbac6a31cf (patch)
tree19a9e2139e2e72178b42f7b2887be8d216210ebc /vm_trace.c
parentabd6dc8c10dc8dc8f19898cef507be2e13ed1d0e (diff)
vm_trace.c: fix infinite hook
* thread.c (rb_threadptr_execute_interrupts): flush postponed job only once at last. * vm_trace.c (rb_postponed_job_flush): defer calling postponed jobs registered while flushing to get rid of infinite reentrance of ObjectSpace.after_gc_start_hook. [ruby-dev:47400] [Bug #8492] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_trace.c')
-rw-r--r--vm_trace.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/vm_trace.c b/vm_trace.c
index e590583..063bd82 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -1444,19 +1444,46 @@ rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func,
void
rb_postponed_job_flush(rb_vm_t *vm)
{
- rb_postponed_job_t *pjob;
-
- while (1) {
- int index = vm->postponed_job_index;
-
- if (index <= 0) {
- return; /* finished */
+ rb_thread_t *cur_th = GET_THREAD();
+ volatile struct {
+ rb_thread_t *thread;
+ unsigned long interrupt_mask;
+ int index, old_index;
+ } save;
+ int index = vm->postponed_job_index, old_index = index;
+
+ save.thread = cur_th;
+ save.interrupt_mask = cur_th->interrupt_mask;
+
+ cur_th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK;
+ TH_PUSH_TAG(cur_th);
+ if (EXEC_TAG()) {
+ /* ignore all jumps, just continue */
+ cur_th = save.thread;
+ index = save.index;
+ old_index = save.old_index;
+ }
+ while (index > 0) {
+ rb_postponed_job_t *pjob = &vm->postponed_job_buffer[--index];
+ void *data = pjob->data;
+ rb_postponed_job_func_t func = pjob->func;
+
+ pjob->func = 0; /* not to execute again */
+ if (old_index > 0) {
+ if (ATOMIC_CAS(vm->postponed_job_index, old_index, index) == old_index) {
+ old_index = index;
+ }
+ else {
+ old_index = 0;
+ }
}
-
- if (ATOMIC_CAS(vm->postponed_job_index, index, index-1) == index) {
- pjob = &vm->postponed_job_buffer[index-1];
+ save.index = index;
+ save.old_index = old_index;
+ if (func) {
/* do postponed job */
- pjob->func(pjob->data);
+ (*func)(data);
}
}
+ TH_POP_TAG();
+ cur_th->interrupt_mask = save.interrupt_mask;
}