2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief SignalDispatcher internal header */
17 #ifndef IH_SENF_Scheduler_SignalEvent_
18 #define IH_SENF_Scheduler_SignalEvent_ 1
21 #include "FdManager.hh"
22 #include <boost/intrusive/set.hpp>
23 #include <senf/Utils/Exception.hh>
24 #include <senf/Utils/singleton.hh>
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35 struct SignalSetCompare {
36 bool operator()(SignalEvent const & a, SignalEvent const & b) const
37 { return a.signal_ < b.signal_; }
40 struct FindNumericSignal {
41 bool operator()(SignalEvent const & a, int b) const
42 { return a.signal_ < b; }
43 bool operator()(int a, SignalEvent const & b) const
44 { return a < b.signal_; }
47 class SignalDispatcher
48 : public detail::FdManager::Event,
49 public singleton<SignalDispatcher>
51 typedef boost::intrusive::set< SignalEvent,
52 boost::intrusive::constant_time_size<false>,
53 boost::intrusive::compare<SignalSetCompare>,
54 boost::intrusive::base_hook<SignalSetBase> > SignalSet;
57 using singleton<SignalDispatcher>::instance;
58 using singleton<SignalDispatcher>::alive;
60 void add(SignalEvent & event);
61 void remove(SignalEvent & event);
63 void unblockSignals();
68 struct DuplicateSignalRegistrationException : public Exception
69 { DuplicateSignalRegistrationException()
70 : Exception("duplicate signal registration") {} };
78 virtual void signal(int events);
79 static void sigHandler(int signal, ::siginfo_t * siginfo, void *);
88 friend void senf::scheduler::restart();
89 friend class senf::scheduler::SignalEvent;
90 friend class singleton<SignalDispatcher>;
95 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 // comment-column: 40
103 // c-file-style: "senf"
104 // indent-tabs-mode: nil
105 // ispell-local-dictionary: "american"
106 // compile-command: "scons -u test"