libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / debugger / util / SignalSet.h
blob082c9026e8db2a60bcec6a72de323c894e7253ae
1 /*
2 * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef SIGNAL_SET_H
6 #define SIGNAL_SET_H
9 #include <signal.h>
12 class SignalSet {
13 public:
14 SignalSet();
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();
39 private:
40 sigset_t fSignals;
44 SignalSet::SignalSet()
46 sigemptyset(&fSignals);
50 SignalSet::SignalSet(int signal)
52 SetTo(signal);
56 SignalSet::SignalSet(const sigset_t& signals)
58 fSignals(signals)
63 void
64 SignalSet::SetTo(const sigset_t& signals)
66 fSignals = signals;
70 void
71 SignalSet::SetTo(int signal)
73 sigemptyset(&fSignals);
74 sigaddset(&fSignals, signal);
78 bool
79 SignalSet::ContainsSignal(int signal) const
81 return sigismember(&fSignals, signal) != 0;
85 SignalSet&
86 SignalSet::AddSignal(int signal)
88 sigaddset(&fSignals, signal);
89 return *this;
93 SignalSet&
94 SignalSet::AddSignals(const SignalSet& signals)
96 // NOTE: That is not portable.
97 fSignals |= signals.fSignals;
98 return *this;
102 SignalSet&
103 SignalSet::RemoveSignal(int signal)
105 sigdelset(&fSignals, signal);
106 return *this;
110 SignalSet&
111 SignalSet::RemoveSignals(const SignalSet& signals)
113 // NOTE: That is not portable.
114 fSignals &= ~signals.fSignals;
115 return *this;
119 status_t
120 SignalSet::BlockInCurrentThread(SignalSet* oldMask) const
122 return pthread_sigmask(SIG_BLOCK, &fSignals,
123 oldMask != NULL ? &oldMask->fSignals : NULL);
127 status_t
128 SignalSet::UnblockInCurrentThread(SignalSet* oldMask) const
130 return pthread_sigmask(SIG_UNBLOCK, &fSignals,
131 oldMask != NULL ? &oldMask->fSignals : NULL);
135 status_t
136 SignalSet::SetCurrentThreadSignalMask(SignalSet* oldMask) const
138 return pthread_sigmask(SIG_SETMASK, &fSignals,
139 oldMask != NULL ? &oldMask->fSignals : NULL);
143 /*static*/ SignalSet
144 SignalSet::CurrentThreadSignalMask()
146 SignalSet signals;
147 pthread_sigmask(SIG_BLOCK, NULL, &signals.fSignals);
148 return signals;
152 #endif // SIGNAL_SET_H