diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-29 22:13:02 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-29 22:13:02 +0000 |
commit | 4bf8834dc8e124446bd2447ad38c96d677eceb59 (patch) | |
tree | 80e9ff3931440f4989aa3459dee03ef1bd90539d | |
parent | 3a0f6ab422433147c0e444199782865e13fa158c (diff) | |
download | ruby-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
-rw-r--r-- | signal.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -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); } } |