1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

signal.c: avoid repeated disable/enable interrupt

We only install system-level signal handlers during init (before any
threads or user code is running), so there's no need to repeatedly
enable/disable the interrupts at that time.  We also do not change
system-level sig handlers once user-level code is running.

This saves about 20 syscalls at startup and makes the executable
smaller (numbers from 32-bit x86):

        text       data     bss     dec     hex filename
before: 2815726   12100   30552 2858378  2b9d8a ruby
 after: 2815022   12100   30552 2857674  2b9aca ruby

* signal.c (install_sighandler): remove rb_disable_interrupt and
  rb_enable_interrupt calls
  (init_sigchld): ditto
  (Init_signal): disable and enable interrupt once around all
  install_sighandler and init_sigchld to reduce syscalls at start
  [Feature #9345] [ruby-core:59480]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2014-10-28 18:39:45 +00:00
parent 4079a35447
commit cbb79f0472
2 changed files with 14 additions and 5 deletions

View file

@ -1,3 +1,12 @@
Tue Oct 28 16:52:07 2014 Eric Wong <e@80x24.org>
* signal.c (install_sighandler): remove rb_disable_interrupt and
rb_enable_interrupt calls
(init_sigchld): ditto
(Init_signal): disable and enable interrupt once around all
install_sighandler and init_sigchld to reduce syscalls at start
[Feature #9345] [ruby-core:59480]
Tue Oct 28 16:22:41 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (process_options, load_file_internal2): should not

View file

@ -1298,15 +1298,12 @@ install_sighandler(int signum, sighandler_t handler)
{
sighandler_t old;
/* At this time, there is no subthread. Then sigmask guarantee atomics. */
rb_disable_interrupt();
old = ruby_signal(signum, handler);
if (old == SIG_ERR) return -1;
/* signal handler should be inherited during exec. */
if (old != SIG_DFL) {
ruby_signal(signum, old);
}
rb_enable_interrupt();
return 0;
}
#ifndef __native_client__
@ -1319,7 +1316,6 @@ init_sigchld(int sig)
{
sighandler_t oldfunc;
rb_disable_interrupt();
oldfunc = ruby_signal(sig, SIG_DFL);
if (oldfunc == SIG_ERR) return -1;
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
@ -1328,7 +1324,6 @@ init_sigchld(int sig)
else {
GET_VM()->trap_list[sig].cmd = 0;
}
rb_enable_interrupt();
return 0;
}
# ifndef __native_client__
@ -1405,6 +1400,9 @@ Init_signal(void)
rb_alias(rb_eSignal, rb_intern_const("signm"), rb_intern_const("message"));
rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);
/* At this time, there is no subthread. Then sigmask guarantee atomics. */
rb_disable_interrupt();
install_sighandler(SIGINT, sighandler);
#ifdef SIGHUP
install_sighandler(SIGHUP, sighandler);
@ -1448,4 +1446,6 @@ Init_signal(void)
#elif defined(SIGCHLD)
init_sigchld(SIGCHLD);
#endif
rb_enable_interrupt();
}