Bug #15263 ยป 0001-vm_trace.c-postponed_job_register-only-hit-main-thre.patch
cont.c | ||
---|---|---|
261 | 261 |
{ |
262 | 262 |
rb_execution_context_t *ec = &fib->cont.saved_ec; |
263 | 263 | |
264 |
ruby_current_execution_context_ptr = th->ec = ec; |
|
264 |
if (th->vm->main_thread == th) { |
|
265 |
/* |
|
266 |
* Other thread may set interrupt on previous th->ec at any time; |
|
267 |
* ensure we do not delay (or lose) the trap interrupt handling. |
|
268 |
*/ |
|
269 |
rb_atomic_t old_fl, new_fl; |
|
270 |
rb_execution_context_t *prev_ec = ruby_current_execution_context_ptr; |
|
265 | 271 | |
266 |
/* |
|
267 |
* timer-thread may set trap interrupt on previous th->ec at any time; |
|
268 |
* ensure we do not delay (or lose) the trap interrupt handling. |
|
269 |
*/ |
|
270 |
if (th->vm->main_thread == th && rb_signal_buff_size() > 0) { |
|
271 |
RUBY_VM_SET_TRAP_INTERRUPT(ec); |
|
272 |
ruby_current_execution_context_ptr = th->ec = ec; |
|
273 |
old_fl = ATOMIC_EXCHANGE(prev_ec->interrupt_flag, 0); |
|
274 | ||
275 |
/* migrate interrupts from the previous EC to the current EC */ |
|
276 |
new_fl = old_fl & (TIMER_INTERRUPT_MASK | |
|
277 |
POSTPONED_JOB_INTERRUPT_MASK | |
|
278 |
TRAP_INTERRUPT_MASK); |
|
279 | ||
280 |
if (new_fl) ATOMIC_OR(ec->interrupt_flag, new_fl); |
|
281 | ||
282 |
/* Pending-interrupts stay with the previous EC */ |
|
283 |
old_fl &= PENDING_INTERRUPT_MASK; |
|
284 |
if (old_fl) ATOMIC_OR(prev_ec->interrupt_flag, old_fl); |
|
285 |
} |
|
286 |
else { |
|
287 |
ruby_current_execution_context_ptr = th->ec = ec; |
|
272 | 288 |
} |
273 | 289 | |
274 | 290 |
VM_ASSERT(ec->fiber_ptr->cont.self == 0 || ec->vm_stack != NULL); |
vm_trace.c | ||
---|---|---|
1596 | 1596 | |
1597 | 1597 |
/* Async-signal-safe */ |
1598 | 1598 |
static enum postponed_job_register_result |
1599 |
postponed_job_register(rb_execution_context_t *ec, rb_vm_t *vm,
|
|
1599 |
postponed_job_register(rb_vm_t *vm, |
|
1600 | 1600 |
unsigned int flags, rb_postponed_job_func_t func, void *data, int max, int expected_index) |
1601 | 1601 |
{ |
1602 | 1602 |
rb_postponed_job_t *pjob; |
... | ... | |
1614 | 1614 |
pjob->func = func; |
1615 | 1615 |
pjob->data = data; |
1616 | 1616 | |
1617 |
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec); |
|
1617 |
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(vm->main_thread->ec);
|
|
1618 | 1618 | |
1619 | 1619 |
return PJRR_SUCCESS; |
1620 | 1620 |
} |
... | ... | |
1626 | 1626 |
int |
1627 | 1627 |
rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data) |
1628 | 1628 |
{ |
1629 |
rb_execution_context_t *ec = GET_EC(); |
|
1630 |
rb_vm_t *vm = rb_ec_vm_ptr(ec); |
|
1629 |
rb_vm_t *vm = GET_VM(); |
|
1631 | 1630 | |
1632 | 1631 |
begin: |
1633 |
switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) {
|
|
1632 |
switch (postponed_job_register(vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) { |
|
1634 | 1633 |
case PJRR_SUCCESS : return 1; |
1635 | 1634 |
case PJRR_FULL : return 0; |
1636 | 1635 |
case PJRR_INTERRUPTED: goto begin; |
... | ... | |
1645 | 1644 |
int |
1646 | 1645 |
rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data) |
1647 | 1646 |
{ |
1648 |
rb_execution_context_t *ec = GET_EC(); |
|
1649 |
rb_vm_t *vm = rb_ec_vm_ptr(ec); |
|
1647 |
rb_vm_t *vm = GET_VM(); |
|
1650 | 1648 |
rb_postponed_job_t *pjob; |
1651 | 1649 |
int i, index; |
1652 | 1650 | |
... | ... | |
1655 | 1653 |
for (i=0; i<index; i++) { |
1656 | 1654 |
pjob = &vm->postponed_job_buffer[i]; |
1657 | 1655 |
if (pjob->func == func) { |
1658 |
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec); |
|
1656 |
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(vm->main_thread->ec);
|
|
1659 | 1657 |
return 2; |
1660 | 1658 |
} |
1661 | 1659 |
} |
1662 |
switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB + MAX_POSTPONED_JOB_SPECIAL_ADDITION, index)) {
|
|
1660 |
switch (postponed_job_register(vm, flags, func, data, MAX_POSTPONED_JOB + MAX_POSTPONED_JOB_SPECIAL_ADDITION, index)) { |
|
1663 | 1661 |
case PJRR_SUCCESS : return 1; |
1664 | 1662 |
case PJRR_FULL : return 0; |
1665 | 1663 |
case PJRR_INTERRUPTED: goto begin; |
1666 |
- |