Back to index

glibc  2.9
sigset.h
Go to the documentation of this file.
00001 /* __sig_atomic_t, __sigset_t, and related definitions.  Linux version.
00002    Copyright (C) 1991, 1992, 1994, 1996, 1997, 2007
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef       _SIGSET_H_types
00022 # define _SIGSET_H_types    1
00023 
00024 typedef int __sig_atomic_t;
00025 
00026 /* A `sigset_t' has a bit for each signal.  */
00027 
00028 # define _SIGSET_NWORDS     (1024 / (8 * sizeof (unsigned long int)))
00029 typedef struct
00030   {
00031     unsigned long int __val[_SIGSET_NWORDS];
00032   } __sigset_t;
00033 
00034 #endif
00035 
00036 
00037 /* We only want to define these functions if <signal.h> was actually
00038    included; otherwise we were included just to define the types.  Since we
00039    are namespace-clean, it wouldn't hurt to define extra macros.  But
00040    trouble can be caused by functions being defined (e.g., any global
00041    register vars declared later will cause compilation errors).  */
00042 
00043 #if !defined _SIGSET_H_fns && defined _SIGNAL_H
00044 # define _SIGSET_H_fns 1
00045 
00046 # ifndef _EXTERN_INLINE
00047 #  define _EXTERN_INLINE __extern_inline
00048 # endif
00049 
00050 /* Return a mask that includes the bit for SIG only.  */
00051 # define __sigmask(sig) \
00052   (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
00053 
00054 /* Return the word index for SIG.  */
00055 # define __sigword(sig)     (((sig) - 1) / (8 * sizeof (unsigned long int)))
00056 
00057 # if defined __GNUC__ && __GNUC__ >= 2
00058 #  define __sigemptyset(set) \
00059   (__extension__ ({ int __cnt = _SIGSET_NWORDS;                             \
00060                   sigset_t *__set = (set);                                  \
00061                   while (--__cnt >= 0) __set->__val[__cnt] = 0;             \
00062                   0; }))
00063 #  define __sigfillset(set) \
00064   (__extension__ ({ int __cnt = _SIGSET_NWORDS;                             \
00065                   sigset_t *__set = (set);                                  \
00066                   while (--__cnt >= 0) __set->__val[__cnt] = ~0UL;          \
00067                   0; }))
00068 
00069 #  ifdef __USE_GNU
00070 /* The POSIX does not specify for handling the whole signal set in one
00071    command.  This is often wanted and so we define three more functions
00072    here.  */
00073 #   define __sigisemptyset(set) \
00074   (__extension__ ({ int __cnt = _SIGSET_NWORDS;                             \
00075                   const sigset_t *__set = (set);                     \
00076                   int __ret = __set->__val[--__cnt];                        \
00077                   while (!__ret && --__cnt >= 0)                     \
00078                      __ret = __set->__val[__cnt];                           \
00079                   __ret == 0; }))
00080 #   define __sigandset(dest, left, right) \
00081   (__extension__ ({ int __cnt = _SIGSET_NWORDS;                             \
00082                   sigset_t *__dest = (dest);                                \
00083                   const sigset_t *__left = (left);                          \
00084                   const sigset_t *__right = (right);                        \
00085                   while (--__cnt >= 0)                               \
00086                     __dest->__val[__cnt] = (__left->__val[__cnt]            \
00087                                          & __right->__val[__cnt]);          \
00088                   0; }))
00089 #   define __sigorset(dest, left, right) \
00090   (__extension__ ({ int __cnt = _SIGSET_NWORDS;                             \
00091                   sigset_t *__dest = (dest);                                \
00092                   const sigset_t *__left = (left);                          \
00093                   const sigset_t *__right = (right);                        \
00094                   while (--__cnt >= 0)                               \
00095                     __dest->__val[__cnt] = (__left->__val[__cnt]            \
00096                                          | __right->__val[__cnt]);          \
00097                   0; }))
00098 #  endif
00099 # endif
00100 
00101 /* These functions needn't check for a bogus signal number -- error
00102    checking is done in the non __ versions.  */
00103 
00104 extern int __sigismember (__const __sigset_t *, int);
00105 extern int __sigaddset (__sigset_t *, int);
00106 extern int __sigdelset (__sigset_t *, int);
00107 
00108 # ifdef __USE_EXTERN_INLINES
00109 #  define __SIGSETFN(NAME, BODY, CONST)                                     \
00110   _EXTERN_INLINE int                                                 \
00111   NAME (CONST __sigset_t *__set, int __sig)                                 \
00112   {                                                                  \
00113     unsigned long int __mask = __sigmask (__sig);                           \
00114     unsigned long int __word = __sigword (__sig);                           \
00115     return BODY;                                                     \
00116   }
00117 
00118 __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
00119 __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
00120 __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
00121 
00122 #  undef __SIGSETFN
00123 # endif
00124 
00125 
00126 #endif /* ! _SIGSET_H_fns.  */