mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
3a0f6ab422
commit
4bf8834dc8
1 changed files with 3 additions and 4 deletions
7
signal.c
7
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue