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:
parent
4079a35447
commit
cbb79f0472
@ -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>
|
Tue Oct 28 16:22:41 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ruby.c (process_options, load_file_internal2): should not
|
* ruby.c (process_options, load_file_internal2): should not
|
||||||
|
10
signal.c
10
signal.c
@ -1298,15 +1298,12 @@ install_sighandler(int signum, sighandler_t handler)
|
|||||||
{
|
{
|
||||||
sighandler_t old;
|
sighandler_t old;
|
||||||
|
|
||||||
/* At this time, there is no subthread. Then sigmask guarantee atomics. */
|
|
||||||
rb_disable_interrupt();
|
|
||||||
old = ruby_signal(signum, handler);
|
old = ruby_signal(signum, handler);
|
||||||
if (old == SIG_ERR) return -1;
|
if (old == SIG_ERR) return -1;
|
||||||
/* signal handler should be inherited during exec. */
|
/* signal handler should be inherited during exec. */
|
||||||
if (old != SIG_DFL) {
|
if (old != SIG_DFL) {
|
||||||
ruby_signal(signum, old);
|
ruby_signal(signum, old);
|
||||||
}
|
}
|
||||||
rb_enable_interrupt();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifndef __native_client__
|
#ifndef __native_client__
|
||||||
@ -1319,7 +1316,6 @@ init_sigchld(int sig)
|
|||||||
{
|
{
|
||||||
sighandler_t oldfunc;
|
sighandler_t oldfunc;
|
||||||
|
|
||||||
rb_disable_interrupt();
|
|
||||||
oldfunc = ruby_signal(sig, SIG_DFL);
|
oldfunc = ruby_signal(sig, SIG_DFL);
|
||||||
if (oldfunc == SIG_ERR) return -1;
|
if (oldfunc == SIG_ERR) return -1;
|
||||||
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
|
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
|
||||||
@ -1328,7 +1324,6 @@ init_sigchld(int sig)
|
|||||||
else {
|
else {
|
||||||
GET_VM()->trap_list[sig].cmd = 0;
|
GET_VM()->trap_list[sig].cmd = 0;
|
||||||
}
|
}
|
||||||
rb_enable_interrupt();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
# ifndef __native_client__
|
# ifndef __native_client__
|
||||||
@ -1405,6 +1400,9 @@ Init_signal(void)
|
|||||||
rb_alias(rb_eSignal, rb_intern_const("signm"), rb_intern_const("message"));
|
rb_alias(rb_eSignal, rb_intern_const("signm"), rb_intern_const("message"));
|
||||||
rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);
|
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);
|
install_sighandler(SIGINT, sighandler);
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
install_sighandler(SIGHUP, sighandler);
|
install_sighandler(SIGHUP, sighandler);
|
||||||
@ -1448,4 +1446,6 @@ Init_signal(void)
|
|||||||
#elif defined(SIGCHLD)
|
#elif defined(SIGCHLD)
|
||||||
init_sigchld(SIGCHLD);
|
init_sigchld(SIGCHLD);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
rb_enable_interrupt();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user