From 4bf8834dc8e124446bd2447ad38c96d677eceb59 Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 29 Jun 2018 22:13:02 +0000 Subject: signal.c: use ATOMIC_EXCHANGE for sigchld_hit sig_atomic_t may not be sufficient for multi-threaded applications if the sighandler runs on a different CPU than timer thread. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- signal.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'signal.c') diff --git a/signal.c b/signal.c index 238679e1bd..a817cb336a 100644 --- a/signal.c +++ b/signal.c @@ -692,7 +692,7 @@ signal_enque(int sig) ATOMIC_INC(signal_buff.size); } -static sig_atomic_t sigchld_hit; +static rb_atomic_t sigchld_hit; /* Prevent compiler from reordering access */ #define ACCESS_ONCE(type,x) (*((volatile type *)&(x))) @@ -705,7 +705,7 @@ sighandler(int sig) /* the VM always needs to handle SIGCHLD for rb_waitpid */ if (sig == RUBY_SIGCHLD) { rb_vm_t *vm = GET_VM(); - sigchld_hit = 1; + ATOMIC_EXCHANGE(sigchld_hit, 1); /* avoid spurious wakeup in main thread iff nobody uses trap(:CHLD) */ if (vm && ACCESS_ONCE(VALUE, vm->trap_list.cmd[sig])) { @@ -1066,8 +1066,7 @@ void ruby_waitpid_all(rb_vm_t *); /* process.c */ void ruby_sigchld_handler(rb_vm_t *vm) { - if (sigchld_hit) { - sigchld_hit = 0; + if (ATOMIC_EXCHANGE(sigchld_hit, 0)) { ruby_waitpid_all(vm); } } -- cgit v1.2.1