summaryrefslogtreecommitdiff
path: root/libc/sysdeps
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 15:31:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 15:31:22 +0000
commit0e4d4dd89170d47a662f1cd0de1b4f3a5dbc1f2d (patch)
tree324429d9476664c8dff6d315daaf98b4a011c48d /libc/sysdeps
parent4298bd6e30f8841250f4912fdbda7a4a2230b561 (diff)
optimize signal mask ops. comment out "impossible" errors
text data bss dec hex filename - 1179 13 2 1194 4aa libc/misc/syslog/syslog.o + 1165 13 2 1180 49c libc/misc/syslog/syslog.o - 435 4 0 439 1b7 libc/pwd_grp/lckpwdf.o + 393 4 0 397 18d libc/pwd_grp/lckpwdf.o - 38 0 0 38 26 libc/signal/sigandset.o + 32 0 0 32 20 libc/signal/sigandset.o - 63 0 0 63 3f libc/signal/sigblock.o + 56 0 0 56 38 libc/signal/sigblock.o - 22 0 0 22 16 libc/signal/sigempty.o + 20 0 0 20 14 libc/signal/sigempty.o - 25 0 0 25 19 libc/signal/sigfillset.o + 20 0 0 20 14 libc/signal/sigfillset.o - 34 0 0 34 22 libc/signal/sigisempty.o + 16 0 0 16 10 libc/signal/sigisempty.o - 38 0 0 38 26 libc/signal/sigorset.o + 32 0 0 32 20 libc/signal/sigorset.o - 119 0 0 119 77 libc/signal/sigpause.o + 113 0 0 113 71 libc/signal/sigpause.o - 215 0 0 215 d7 libc/signal/sigset.o + 211 0 0 211 d3 libc/signal/sigset.o - 63 0 0 63 3f libc/signal/sigsetmask.o + 56 0 0 56 38 libc/signal/sigsetmask.o - 194 0 1 195 c3 libc/stdlib/abort.o + 183 0 1 184 b8 libc/stdlib/abort.o - 323 0 0 323 143 libc/unistd/sleep.o + 309 0 0 309 135 libc/unistd/sleep.o
Diffstat (limited to 'libc/sysdeps')
-rw-r--r--libc/sysdeps/linux/alpha/sigprocmask.c4
-rw-r--r--libc/sysdeps/linux/common/bits/sigset.h127
-rw-r--r--libc/sysdeps/linux/common/ssp.c4
3 files changed, 90 insertions, 45 deletions
diff --git a/libc/sysdeps/linux/alpha/sigprocmask.c b/libc/sysdeps/linux/alpha/sigprocmask.c
index 5728418b5..e143f61e3 100644
--- a/libc/sysdeps/linux/alpha/sigprocmask.c
+++ b/libc/sysdeps/linux/alpha/sigprocmask.c
@@ -51,7 +51,9 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset)
if (oset)
{
- if (_SIGSET_NWORDS > 1)
+ if (_SIGSET_NWORDS == 2) /* typical */
+ oset->__val[1] = 0;
+ if (_SIGSET_NWORDS > 2)
memset(oset, 0, sizeof(*oset));
oset->__val[0] = result;
}
diff --git a/libc/sysdeps/linux/common/bits/sigset.h b/libc/sysdeps/linux/common/bits/sigset.h
index 14497671d..964b09178 100644
--- a/libc/sysdeps/linux/common/bits/sigset.h
+++ b/libc/sysdeps/linux/common/bits/sigset.h
@@ -30,10 +30,9 @@ typedef int __sig_atomic_t;
*/
# define _SIGSET_NWORDS (64 / (8 * sizeof (unsigned long int)))
-typedef struct
- {
- unsigned long int __val[_SIGSET_NWORDS];
- } __sigset_t;
+typedef struct {
+ unsigned long int __val[_SIGSET_NWORDS];
+} __sigset_t;
#endif
@@ -59,47 +58,91 @@ typedef struct
/* Return the word index for SIG. */
# define __sigword(sig) ((unsigned)((sig) - 1) / (8 * sizeof (unsigned long int)))
+/* gcc 4.3.1 is not clever enough to optimize for _SIGSET_NWORDS == 1 and 2,
+ * which are about the only values which can be there */
+
# if defined __GNUC__ && __GNUC__ >= 2
# define __sigemptyset(set) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__set = (set); \
- while (--__cnt >= 0) __set->__val[__cnt] = 0; \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__set = (set); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __set->__val[0] = 0; \
+ if (_SIGSET_NWORDS == 2) \
+ __set->__val[1] = 0; \
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) __set->__val[__cnt] = 0; \
+ } \
+ 0; \
+}))
# define __sigfillset(set) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__set = (set); \
- while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__set = (set); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __set->__val[0] = ~0UL; \
+ if (_SIGSET_NWORDS == 2) \
+ __set->__val[1] = ~0UL; \
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
+ } \
+ 0; \
+}))
# ifdef __USE_GNU
/* The POSIX does not specify for handling the whole signal set in one
command. This is often wanted and so we define three more functions
here. */
# define __sigisemptyset(set) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- const sigset_t *__set = (set); \
- int __ret = __set->__val[--__cnt]; \
- while (!__ret && --__cnt >= 0) \
- __ret = __set->__val[__cnt]; \
- __ret == 0; }))
+(__extension__ ({ \
+ long __ret; \
+ const sigset_t *__set = (set); \
+ if (_SIGSET_NWORDS == 1) { \
+ __ret = __set->__val[0]; \
+ } else if (_SIGSET_NWORDS == 2) { \
+ __ret = __set->__val[0] | __set->__val[1]; \
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ __ret = __set->__val[--__cnt]; \
+ while (!__ret && --__cnt >= 0) \
+ __ret = __set->__val[__cnt]; \
+ } \
+ __ret == 0; \
+}))
# define __sigandset(dest, left, right) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__dest = (dest); \
- const sigset_t *__left = (left); \
- const sigset_t *__right = (right); \
- while (--__cnt >= 0) \
- __dest->__val[__cnt] = (__left->__val[__cnt] \
- & __right->__val[__cnt]); \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__dest = (dest); \
+ const sigset_t *__left = (left); \
+ const sigset_t *__right = (right); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __dest->__val[0] = __left->__val[0] & __right->__val[0];\
+ if (_SIGSET_NWORDS == 2) \
+ __dest->__val[1] = __left->__val[1] & __right->__val[1];\
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) \
+ __dest->__val[__cnt] = (__left->__val[__cnt] \
+ & __right->__val[__cnt]); \
+ } \
+ 0; \
+}))
# define __sigorset(dest, left, right) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__dest = (dest); \
- const sigset_t *__left = (left); \
- const sigset_t *__right = (right); \
- while (--__cnt >= 0) \
- __dest->__val[__cnt] = (__left->__val[__cnt] \
- | __right->__val[__cnt]); \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__dest = (dest); \
+ const sigset_t *__left = (left); \
+ const sigset_t *__right = (right); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __dest->__val[0] = __left->__val[0] | __right->__val[0];\
+ if (_SIGSET_NWORDS == 2) \
+ __dest->__val[1] = __left->__val[1] | __right->__val[1];\
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) \
+ __dest->__val[__cnt] = (__left->__val[__cnt] \
+ | __right->__val[__cnt]); \
+ } \
+ 0; \
+}))
# endif
# endif
@@ -114,14 +157,14 @@ extern int __sigdelset (__sigset_t *, int);
libc_hidden_proto(__sigdelset)
# ifdef __USE_EXTERN_INLINES
-# define __SIGSETFN(NAME, BODY, CONST) \
- _EXTERN_INLINE int \
- NAME (CONST __sigset_t *__set, int __sig) \
- { \
- unsigned long int __mask = __sigmask (__sig); \
- unsigned long int __word = __sigword (__sig); \
- return BODY; \
- }
+# define __SIGSETFN(NAME, BODY, CONST) \
+_EXTERN_INLINE int \
+NAME (CONST __sigset_t *__set, int __sig) \
+{ \
+ unsigned long int __mask = __sigmask (__sig); \
+ unsigned long int __word = __sigword (__sig); \
+ return BODY; \
+}
__SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
__SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c
index c244c6220..fadf6077b 100644
--- a/libc/sysdeps/linux/common/ssp.c
+++ b/libc/sysdeps/linux/common/ssp.c
@@ -51,14 +51,14 @@ static void block_signals(void)
struct sigaction sa;
sigset_t mask;
- sigfillset(&mask);
+ __sigfillset(&mask);
sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */
sigprocmask(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */
/* Make the default handler associated with the signal handler */
memset(&sa, 0, sizeof(sa));
- sigfillset(&sa.sa_mask); /* Block all signals */
+ __sigfillset(&sa.sa_mask); /* Block all signals */
/* sa.sa_flags = 0; - memset did it */
if (SIG_DFL) /* if it's constant zero, it's already done */
sa.sa_handler = SIG_DFL;