Created
August 22, 2008 01:57
-
-
Save tmm1/6716 to your computer and use it in GitHub Desktop.
Patch to MRI signal.c to prevent unnecessary sigprocmask syscalls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- signal.c.orig 2008-08-21 18:42:46.000000000 -0700 | |
+++ signal.c 2008-08-21 18:55:42.000000000 -0700 | |
@@ -23,6 +23,7 @@ | |
#if defined HAVE_SIGPROCMASK || defined HAVE_SIGSETMASK | |
#define USE_TRAP_MASK 1 | |
+static int restore_signals = 0; | |
#else | |
#define USE_TRAP_MASK 0 | |
#endif | |
@@ -687,9 +688,19 @@ | |
#if USE_TRAP_MASK | |
# ifdef HAVE_SIGPROCMASK | |
+ | |
static sigset_t trap_last_mask; | |
+#define sigcmpset(a,b) ({ \ | |
+ int __cnt = _SIGSET_NWORDS; \ | |
+ int __ret = 0; \ | |
+ while (--__cnt >= 0) if (a.__val[__cnt] != b.__val[__cnt]){ __ret = -1; break; } \ | |
+ __ret; }) | |
+ | |
# else | |
+ | |
static int trap_last_mask; | |
+#define sigcmpset(a,b) (a!=b) | |
+ | |
# endif | |
#endif | |
@@ -841,14 +852,17 @@ | |
trap_ensure(arg) | |
struct trap_arg *arg; | |
{ | |
- /* enable interrupt */ | |
+ /* enable interrupt */ | |
+ if (sigcmpset(arg->mask, trap_last_mask) != 0) { | |
#ifdef HAVE_SIGPROCMASK | |
sigprocmask(SIG_SETMASK, &arg->mask, NULL); | |
#else | |
sigsetmask(arg->mask); | |
#endif | |
trap_last_mask = arg->mask; | |
- return 0; | |
+ restore_signals = 1; | |
+ } | |
+ return 0; | |
} | |
#endif | |
@@ -856,11 +870,14 @@ | |
rb_trap_restore_mask() | |
{ | |
#if USE_TRAP_MASK | |
+ if (restore_signals) { | |
# ifdef HAVE_SIGPROCMASK | |
sigprocmask(SIG_SETMASK, &trap_last_mask, NULL); | |
# else | |
sigsetmask(trap_last_mask); | |
# endif | |
+ restore_signals = 0; | |
+ } | |
#endif | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment