aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-05-24 16:34:34 -0700
committerJeremy Evans <code@jeremyevans.net>2019-05-24 17:50:23 -0700
commit1ef39d8d099f145222b9352423af16a2bab6e05b (patch)
treec41c2dfcc16a9325d8cd6c44945d6bed969b8107 /thread_pthread.c
parent19430b776c3ebae1adfdc5cbe6cdf69a92e37253 (diff)
downloadruby-1ef39d8d099f145222b9352423af16a2bab6e05b.tar.gz
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]
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 499da0b9ca..2e5be35c11 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -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 (rb_signal_buff_size() || !ubf_threads_empty()) {
- timeout = TIME_QUANTUM_MSEC;
- }
- else {
- ATOMIC_SET(timer_pthread.armed, 0);
- timeout = -1;
- }
- }
+ 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;
+ }
+ }
+ else if (ccp) {
+ pthread_kill(main_thread_id, SIGVTALRM);
+ ATOMIC_SET(timer_pthread.armed, 0);
+ timeout = -1;
+ }
+ }
}
return 0;