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 <senf/boost_intrusive/ilist.hpp>
33 #include <senf/boost_intrusive/ilist_hook.hpp>
34 #include <senf/Utils/singleton.hh>
35 #include "EventManager.hh"
37 //#include "FIFORunner.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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;
82 std::string backtrace_; // only used if SENF_BACKTRACE is defined.
84 friend class FIFORunner;
87 typedef boost::filter_iterator<
88 EventManager::IteratorFilter, TaskList::const_iterator> iterator;
90 using singleton<FIFORunner>::instance;
91 using singleton<FIFORunner>::alive;
93 void enqueue(TaskInfo * task);
94 void dequeue(TaskInfo * task);
98 void taskTimeout(unsigned ms);
99 unsigned taskTimeout() const;
100 void abortOnTimeout(bool flag);
101 bool abortOnTimeout() const;
103 void startWatchdog();
106 unsigned hangCount();
108 iterator begin() const;
109 iterator end() const;
119 static void watchdog(int, siginfo_t *, void *);
120 void watchdogError();
122 TaskList::iterator priorityEnd(TaskInfo::Priority p);
123 void run(TaskList::iterator f, TaskList::iterator l);
125 struct NullTask : public TaskInfo
129 virtual void v_run();;
130 virtual char const * v_type() const;
131 virtual std::string v_info() const;
135 TaskList::iterator next_;
137 NullTask normalPriorityEnd_;
138 NullTask highPriorityEnd_;
141 bool watchdogRunning_;
142 unsigned watchdogMs_;
144 std::string runningName_;
146 std::string runningBacktrace_;
148 unsigned watchdogCount_;
152 friend void senf::scheduler::restart();
153 friend class singleton<FIFORunner>;
158 //-/////////////////////////////////////////////////////////////////////////////////////////////////
159 #include "FIFORunner.cci"
160 //#include "FIFORunner.ct"
161 //#include "FIFORunner.cti"
168 // comment-column: 40
169 // c-file-style: "senf"
170 // indent-tabs-mode: nil
171 // ispell-local-dictionary: "american"
172 // compile-command: "scons -u test"