summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-28 18:39:45 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-28 18:39:45 +0000
commitcbb79f0472c4d5fa663033a46c34c6102cbb0e23 (patch)
treef37bce7f6211ef61a5eb5ffe71b3fefeb84811fa /signal.c
parent4079a35447218918a2494b5d7242c9a80b540183 (diff)
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
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/signal.c b/signal.c
index 85e01bf165..5098b8ddb3 100644
--- a/signal.c
+++ b/signal.c
@@ -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();
}