зеркало из https://github.com/github/ruby.git
Fix process not waking up on signals on OpenBSD
When using UBF_TIMER_PTHREAD (the UBF handler on OpenBSD), the timer_pthread_fn function will not signal the main thread with SIGVTALRM in cases where timer_pthread is armed before consume_communication_pipe is called. This is because consume_communication_pipe will unarm the timer. Fix this by checking the return value of consume_communication_pipe. If it returns TRUE and the timer_pthread is disarmed, then signal the main thread with SIGVTALRM. On OpenBSD, this fixes TestThread#test_thread_timer_and_interrupt, and fixes hangs in TestProcess#test_execopts_redirect_open_fifo_interrupt_raise and TestProcess#test_execopts_redirect_open_fifo_interrupt_print. It also fixes the use of Ctrl+C/SIGINT in irb on OpenBSD. It does not cause any test failures on Linux when UBF_TIMER_PTHREAD is forced as the UBF handler. Fixes [Bug #15798]
This commit is contained in:
Родитель
19430b776c
Коммит
1ef39d8d09
|
@ -2187,25 +2187,33 @@ timer_pthread_fn(void *p)
|
|||
pthread_t main_thread_id = vm->main_thread->thread_id;
|
||||
struct pollfd pfd;
|
||||
int timeout = -1;
|
||||
int ccp;
|
||||
|
||||
pfd.fd = timer_pthread.low[0];
|
||||
pfd.events = POLLIN;
|
||||
|
||||
while (system_working > 0) {
|
||||
(void)poll(&pfd, 1, timeout);
|
||||
(void)consume_communication_pipe(pfd.fd);
|
||||
ccp = consume_communication_pipe(pfd.fd);
|
||||
|
||||
if (system_working > 0 && ATOMIC_CAS(timer_pthread.armed, 1, 1)) {
|
||||
pthread_kill(main_thread_id, SIGVTALRM);
|
||||
if (system_working > 0) {
|
||||
if (ATOMIC_CAS(timer_pthread.armed, 1, 1)) {
|
||||
pthread_kill(main_thread_id, SIGVTALRM);
|
||||
|
||||
if (rb_signal_buff_size() || !ubf_threads_empty()) {
|
||||
timeout = TIME_QUANTUM_MSEC;
|
||||
}
|
||||
else {
|
||||
ATOMIC_SET(timer_pthread.armed, 0);
|
||||
timeout = -1;
|
||||
}
|
||||
}
|
||||
if (rb_signal_buff_size() || !ubf_threads_empty()) {
|
||||
timeout = TIME_QUANTUM_MSEC;
|
||||
}
|
||||
else {
|
||||
ATOMIC_SET(timer_pthread.armed, 0);
|
||||
timeout = -1;
|
||||
}
|
||||
}
|
||||
else if (ccp) {
|
||||
pthread_kill(main_thread_id, SIGVTALRM);
|
||||
ATOMIC_SET(timer_pthread.armed, 0);
|
||||
timeout = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Загрузка…
Ссылка в новой задаче