4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief FIFORunner public header */
31 #ifndef HH_SENF_Scheduler_FIFORunner_
32 #define HH_SENF_Scheduler_FIFORunner_ 1
36 #include <boost/utility.hpp>
37 #include <senf/boost_intrusive/ilist.hpp>
38 #include <senf/boost_intrusive/ilist_hook.hpp>
39 #include <senf/Utils/singleton.hh>
40 #include "EventManager.hh"
42 //#include "FIFORunner.mpp"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
53 : public singleton<FIFORunner>
60 typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
61 typedef boost::intrusive::ilist<TaskListBase::value_traits<TaskInfo>, false> TaskList;
69 enum Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 };
71 explicit TaskInfo(std::string const & name, Priority priority=PRIORITY_NORMAL);
76 bool runnable() const;
82 virtual void v_run() = 0;
83 virtual bool v_enabled() const;
87 std::string backtrace_; // only used if SENF_BACKTRACE is defined.
89 friend class FIFORunner;
92 typedef boost::filter_iterator<
93 EventManager::IteratorFilter, TaskList::const_iterator> iterator;
95 using singleton<FIFORunner>::instance;
96 using singleton<FIFORunner>::alive;
98 void enqueue(TaskInfo * task);
99 void dequeue(TaskInfo * task);
103 void taskTimeout(unsigned ms);
104 unsigned taskTimeout() const;
105 void abortOnTimeout(bool flag);
106 bool abortOnTimeout() const;
108 void startWatchdog();
111 unsigned hangCount();
113 iterator begin() const;
114 iterator end() const;
124 static void watchdog(int, siginfo_t *, void *);
125 void watchdogError();
127 TaskList::iterator priorityEnd(TaskInfo::Priority p);
128 void run(TaskList::iterator f, TaskList::iterator l);
130 struct NullTask : public TaskInfo
134 virtual void v_run();;
135 virtual char const * v_type() const;
136 virtual std::string v_info() const;
140 TaskList::iterator next_;
142 NullTask normalPriorityEnd_;
143 NullTask highPriorityEnd_;
146 bool watchdogRunning_;
147 unsigned watchdogMs_;
149 std::string runningName_;
151 std::string runningBacktrace_;
153 unsigned watchdogCount_;
157 friend void senf::scheduler::restart();
158 friend class singleton<FIFORunner>;
163 //-/////////////////////////////////////////////////////////////////////////////////////////////////
164 #include "FIFORunner.cci"
165 //#include "FIFORunner.ct"
166 //#include "FIFORunner.cti"
173 // comment-column: 40
174 // c-file-style: "senf"
175 // indent-tabs-mode: nil
176 // ispell-local-dictionary: "american"
177 // compile-command: "scons -u test"