4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief FIFORunner public header */
26 #ifndef HH_SENF_Scheduler_FIFORunner_
27 #define HH_SENF_Scheduler_FIFORunner_ 1
31 #include <boost/utility.hpp>
32 #include <boost/intrusive/ilist.hpp>
33 #include <boost/intrusive/ilist_hook.hpp>
34 #include "../Utils/singleton.hh"
35 #include "EventManager.hh"
37 //#include "FIFORunner.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
48 : public singleton<FIFORunner>
55 typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
56 typedef boost::intrusive::ilist<TaskListBase::value_traits<TaskInfo>, false> TaskList;
64 enum Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 };
66 explicit TaskInfo(std::string const & name, Priority priority=PRIORITY_NORMAL);
71 bool runnable() const;
77 virtual void v_run() = 0;
78 virtual bool v_enabled() const;
83 std::string backtrace_;
86 friend class FIFORunner;
89 typedef boost::filter_iterator<
90 EventManager::IteratorFilter, TaskList::const_iterator> iterator;
92 using singleton<FIFORunner>::instance;
93 using singleton<FIFORunner>::alive;
95 void enqueue(TaskInfo * task);
96 void dequeue(TaskInfo * task);
100 void taskTimeout(unsigned ms);
101 unsigned taskTimeout() const;
102 void abortOnTimeout(bool flag);
103 bool abortOnTimeout() const;
105 void startWatchdog();
108 unsigned hangCount();
110 iterator begin() const;
111 iterator end() const;
121 static void watchdog(int, siginfo_t *, void *);
122 void watchdogError();
124 TaskList::iterator priorityEnd(TaskInfo::Priority p);
125 void run(TaskList::iterator f, TaskList::iterator l);
127 struct NullTask : public TaskInfo
131 virtual void v_run();;
132 virtual char const * v_type() const;
133 virtual std::string v_info() const;
137 TaskList::iterator next_;
139 NullTask normalPriorityEnd_;
140 NullTask highPriorityEnd_;
143 bool watchdogRunning_;
144 unsigned watchdogMs_;
146 std::string runningName_;
148 std::string runningBacktrace_;
150 unsigned watchdogCount_;
154 friend void senf::scheduler::restart();
155 friend class singleton<FIFORunner>;
160 ///////////////////////////////hh.e////////////////////////////////////////
161 #include "FIFORunner.cci"
162 //#include "FIFORunner.ct"
163 //#include "FIFORunner.cti"
170 // comment-column: 40
171 // c-file-style: "senf"
172 // indent-tabs-mode: nil
173 // ispell-local-dictionary: "american"
174 // compile-command: "scons -u test"