sigset.h 4.5 KB

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