Implementation of Signal Set
If the
implementation has fewer signals than bits in an integer, a signal set can be
implemented using one bit per signal. For the remainder of this section, assume
that an implementation has 31 signals and 32-bit integers. The sigemptyset function
zeros the integer, and the sigfillset function turns on all the bits in the
integer. These two functions can be implemented as macros in the <signal.h>
header:
#define
sigemptyset(ptr) (*(ptr) = 0)
#define
sigfillset(ptr) (*(ptr) = ~(sigset_t)0, 0)
Note that sigfillset
must return 0, in addition to setting all the bits on in the signal set, so we
use C's comma operator, which returns the value after the comma as the value of
the expression.
Using this
implementation, sigaddset turns on a single bit and sigdelset turns off a
single bit; sigismember tests a certain bit. Since no signal is ever numbered
0, we subtract 1 from the signal number to obtain the bit to manipulate. Figure
10.12 shows implementations of these functions.
Imlementations:
See Also
No comments:
Post a Comment