2 * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
15 SignalSet(int signal
);
16 SignalSet(const sigset_t
& signals
);
18 void SetTo(const sigset_t
& signals
);
19 void SetTo(int signal
);
21 const sigset_t
& Signals() const { return fSignals
; }
23 bool ContainsSignal(int signal
) const;
25 SignalSet
& AddSignal(int signal
);
26 SignalSet
& AddSignals(const SignalSet
& signals
);
27 SignalSet
& RemoveSignal(int signal
);
28 SignalSet
& RemoveSignals(const SignalSet
& signals
);
30 status_t
BlockInCurrentThread(
31 SignalSet
* oldMask
= NULL
) const;
32 status_t
UnblockInCurrentThread(
33 SignalSet
* oldMask
= NULL
) const;
34 status_t
SetCurrentThreadSignalMask(
35 SignalSet
* oldMask
= NULL
) const;
37 static SignalSet
CurrentThreadSignalMask();
44 SignalSet::SignalSet()
46 sigemptyset(&fSignals
);
50 SignalSet::SignalSet(int signal
)
56 SignalSet::SignalSet(const sigset_t
& signals
)
64 SignalSet::SetTo(const sigset_t
& signals
)
71 SignalSet::SetTo(int signal
)
73 sigemptyset(&fSignals
);
74 sigaddset(&fSignals
, signal
);
79 SignalSet::ContainsSignal(int signal
) const
81 return sigismember(&fSignals
, signal
) != 0;
86 SignalSet::AddSignal(int signal
)
88 sigaddset(&fSignals
, signal
);
94 SignalSet::AddSignals(const SignalSet
& signals
)
96 // NOTE: That is not portable.
97 fSignals
|= signals
.fSignals
;
103 SignalSet::RemoveSignal(int signal
)
105 sigdelset(&fSignals
, signal
);
111 SignalSet::RemoveSignals(const SignalSet
& signals
)
113 // NOTE: That is not portable.
114 fSignals
&= ~signals
.fSignals
;
120 SignalSet::BlockInCurrentThread(SignalSet
* oldMask
) const
122 return pthread_sigmask(SIG_BLOCK
, &fSignals
,
123 oldMask
!= NULL
? &oldMask
->fSignals
: NULL
);
128 SignalSet::UnblockInCurrentThread(SignalSet
* oldMask
) const
130 return pthread_sigmask(SIG_UNBLOCK
, &fSignals
,
131 oldMask
!= NULL
? &oldMask
->fSignals
: NULL
);
136 SignalSet::SetCurrentThreadSignalMask(SignalSet
* oldMask
) const
138 return pthread_sigmask(SIG_SETMASK
, &fSignals
,
139 oldMask
!= NULL
? &oldMask
->fSignals
: NULL
);
144 SignalSet::CurrentThreadSignalMask()
147 pthread_sigmask(SIG_BLOCK
, NULL
, &signals
.fSignals
);
152 #endif // SIGNAL_SET_H