aboutsummaryrefslogtreecommitdiffstats
path: root/signal.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-29 22:13:02 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-29 22:13:02 +0000
commit4bf8834dc8e124446bd2447ad38c96d677eceb59 (patch)
tree80e9ff3931440f4989aa3459dee03ef1bd90539d /signal.c
parent3a0f6ab422433147c0e444199782865e13fa158c (diff)
downloadruby-4bf8834dc8e124446bd2447ad38c96d677eceb59.tar.gz
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
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c7
1 files changed, 3 insertions, 4 deletions
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);
}
}