sigset.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
  2. Copyright (C) 1991-2016 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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SIGSET_H_types
  16. # define _SIGSET_H_types 1
  17. typedef int __sig_atomic_t;
  18. /* A `sigset_t' has a bit for each signal. */
  19. # define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
  20. typedef struct
  21. {
  22. unsigned long int __val[_SIGSET_NWORDS];
  23. } __sigset_t;
  24. #endif
  25. /* We only want to define these functions if <signal.h> was actually
  26. included; otherwise we were included just to define the types. Since we
  27. are namespace-clean, it wouldn't hurt to define extra macros. But
  28. trouble can be caused by functions being defined (e.g., any global
  29. register vars declared later will cause compilation errors). */
  30. #if !defined _SIGSET_H_fns && defined _SIGNAL_H
  31. # define _SIGSET_H_fns 1
  32. # ifndef _EXTERN_INLINE
  33. # define _EXTERN_INLINE __extern_inline
  34. # endif
  35. /* Return a mask that includes the bit for SIG only. */
  36. # define __sigmask(sig) \
  37. (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
  38. /* Return the word index for SIG. */
  39. # define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
  40. # if defined __GNUC__ && __GNUC__ >= 2
  41. # define __sigemptyset(set) \
  42. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  43. sigset_t *__set = (set); \
  44. while (--__cnt >= 0) __set->__val[__cnt] = 0; \
  45. 0; }))
  46. # define __sigfillset(set) \
  47. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  48. sigset_t *__set = (set); \
  49. while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
  50. 0; }))
  51. # ifdef __USE_GNU
  52. /* The POSIX does not specify for handling the whole signal set in one
  53. command. This is often wanted and so we define three more functions
  54. here. */
  55. # define __sigisemptyset(set) \
  56. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  57. const sigset_t *__set = (set); \
  58. int __ret = __set->__val[--__cnt]; \
  59. while (!__ret && --__cnt >= 0) \
  60. __ret = __set->__val[__cnt]; \
  61. __ret == 0; }))
  62. # define __sigandset(dest, left, right) \
  63. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  64. sigset_t *__dest = (dest); \
  65. const sigset_t *__left = (left); \
  66. const sigset_t *__right = (right); \
  67. while (--__cnt >= 0) \
  68. __dest->__val[__cnt] = (__left->__val[__cnt] \
  69. & __right->__val[__cnt]); \
  70. 0; }))
  71. # define __sigorset(dest, left, right) \
  72. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  73. sigset_t *__dest = (dest); \
  74. const sigset_t *__left = (left); \
  75. const sigset_t *__right = (right); \
  76. while (--__cnt >= 0) \
  77. __dest->__val[__cnt] = (__left->__val[__cnt] \
  78. | __right->__val[__cnt]); \
  79. 0; }))
  80. # endif
  81. # endif
  82. /* These functions needn't check for a bogus signal number -- error
  83. checking is done in the non __ versions. */
  84. extern int __sigismember (const __sigset_t *, int);
  85. extern int __sigaddset (__sigset_t *, int);
  86. extern int __sigdelset (__sigset_t *, int);
  87. # ifdef __USE_EXTERN_INLINES
  88. # define __SIGSETFN(NAME, BODY, CONST) \
  89. _EXTERN_INLINE int \
  90. NAME (CONST __sigset_t *__set, int __sig) \
  91. { \
  92. unsigned long int __mask = __sigmask (__sig); \
  93. unsigned long int __word = __sigword (__sig); \
  94. return BODY; \
  95. }
  96. __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, const)
  97. __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
  98. __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  99. # undef __SIGSETFN
  100. # endif
  101. #endif /* ! _SIGSET_H_fns. */