diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-11 07:54:26 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-11 07:54:26 +0000 |
commit | 76f9281b925680a49103e344b44fc1dc4a356721 (patch) | |
tree | 889331c73a6e463e265b7c7abe219b08405a38b1 /vm_trace.c | |
parent | 19ae2748c7da2eaba7a62c07c242230731cf56b2 (diff) | |
download | ruby-76f9281b925680a49103e344b44fc1dc4a356721.tar.gz |
* vm_trace.c (rb_postponed_job_flush): simplify.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_trace.c')
-rw-r--r-- | vm_trace.c | 57 |
1 files changed, 18 insertions, 39 deletions
diff --git a/vm_trace.c b/vm_trace.c index a8ae1d3795..52afb2bb5d 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -1444,46 +1444,25 @@ rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void rb_postponed_job_flush(rb_vm_t *vm) { - 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.index = index; - save.interrupt_mask = cur_th->interrupt_mask; - - cur_th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK; - TH_PUSH_TAG(cur_th); - 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; + rb_thread_t *th = GET_THREAD(); + unsigned long saved_postponed_job_interrupt_mask = th->interrupt_mask & POSTPONED_JOB_INTERRUPT_MASK; + + /* mask POSTPONED_JOB dispatch */ + th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK; + { + TH_PUSH_TAG(th); + EXEC_TAG(); + { + int index; + while ((index = vm->postponed_job_index) > 0) { + if (ATOMIC_CAS(vm->postponed_job_index, index, index-1) == index) { + rb_postponed_job_t *pjob = &vm->postponed_job_buffer[index-1]; + (*pjob->func)(pjob->data); + } } } - save.index = index; - save.old_index = old_index; - if (func) { - /* do postponed job */ - (*func)(data); - } + TH_POP_TAG(); } - TH_POP_TAG(); - cur_th->interrupt_mask = save.interrupt_mask; + /* restore POSTPONED_JOB mask */ + th->interrupt_mask &= ~saved_postponed_job_interrupt_mask; } |