sigset.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
  2. Copyright (C) 1991, 1992, 1994, 1996, 1997 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _SIGSET_H_types
  17. # define _SIGSET_H_types 1
  18. typedef int __sig_atomic_t;
  19. /* A 'sigset_t' has a bit for each signal.
  20. * Signal 0 does not exist, so we have signals 1..64.
  21. * glibc has space for 1024 signals (!), but all arches supported
  22. * by Linux have 64 signals only.
  23. * See, for example, _NSIG (defined to 65) in signum.h
  24. */
  25. # define _SIGSET_NWORDS (64 / (8 * sizeof (unsigned long int)))
  26. typedef struct
  27. {
  28. unsigned long int __val[_SIGSET_NWORDS];
  29. } __sigset_t;
  30. #endif
  31. /* We only want to define these functions if <signal.h> was actually
  32. included; otherwise we were included just to define the types. Since we
  33. are namespace-clean, it wouldn't hurt to define extra macros. But
  34. trouble can be caused by functions being defined (e.g., any global
  35. register vars declared later will cause compilation errors). */
  36. #if !defined _SIGSET_H_fns && defined _SIGNAL_H
  37. # define _SIGSET_H_fns 1
  38. # ifndef _EXTERN_INLINE
  39. # define _EXTERN_INLINE extern __inline
  40. # endif
  41. /* Return a mask that includes the bit for SIG only. */
  42. /* Unsigned cast ensures shift/mask insns are used. */
  43. # define __sigmask(sig) \
  44. (((unsigned long int) 1) << ((unsigned)((sig) - 1) % (8 * sizeof (unsigned long int))))
  45. /* Return the word index for SIG. */
  46. # define __sigword(sig) ((unsigned)((sig) - 1) / (8 * sizeof (unsigned long int)))
  47. # if defined __GNUC__ && __GNUC__ >= 2
  48. # define __sigemptyset(set) \
  49. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  50. sigset_t *__set = (set); \
  51. while (--__cnt >= 0) __set->__val[__cnt] = 0; \
  52. 0; }))
  53. # define __sigfillset(set) \
  54. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  55. sigset_t *__set = (set); \
  56. while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
  57. 0; }))
  58. # ifdef __USE_GNU
  59. /* The POSIX does not specify for handling the whole signal set in one
  60. command. This is often wanted and so we define three more functions
  61. here. */
  62. # define __sigisemptyset(set) \
  63. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  64. const sigset_t *__set = (set); \
  65. int __ret = __set->__val[--__cnt]; \
  66. while (!__ret && --__cnt >= 0) \
  67. __ret = __set->__val[__cnt]; \
  68. __ret == 0; }))
  69. # define __sigandset(dest, left, right) \
  70. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  71. sigset_t *__dest = (dest); \
  72. const sigset_t *__left = (left); \
  73. const sigset_t *__right = (right); \
  74. while (--__cnt >= 0) \
  75. __dest->__val[__cnt] = (__left->__val[__cnt] \
  76. & __right->__val[__cnt]); \
  77. 0; }))
  78. # define __sigorset(dest, left, right) \
  79. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  80. sigset_t *__dest = (dest); \
  81. const sigset_t *__left = (left); \
  82. const sigset_t *__right = (right); \
  83. while (--__cnt >= 0) \
  84. __dest->__val[__cnt] = (__left->__val[__cnt] \
  85. | __right->__val[__cnt]); \
  86. 0; }))
  87. # endif
  88. # endif
  89. /* These functions needn't check for a bogus signal number -- error
  90. checking is done in the non __ versions. */
  91. extern int __sigismember (__const __sigset_t *, int);
  92. libc_hidden_proto(__sigismember)
  93. extern int __sigaddset (__sigset_t *, int);
  94. libc_hidden_proto(__sigaddset)
  95. extern int __sigdelset (__sigset_t *, int);
  96. libc_hidden_proto(__sigdelset)
  97. # ifdef __USE_EXTERN_INLINES
  98. # define __SIGSETFN(NAME, BODY, CONST) \
  99. _EXTERN_INLINE int \
  100. NAME (CONST __sigset_t *__set, int __sig) \
  101. { \
  102. unsigned long int __mask = __sigmask (__sig); \
  103. unsigned long int __word = __sigword (__sig); \
  104. return BODY; \
  105. }
  106. __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
  107. __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
  108. __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  109. # undef __SIGSETFN
  110. # endif
  111. #endif /* ! _SIGSET_H_fns. */