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_FIFORunner_
27 #define HH_FIFORunner_ 1
31 #include <boost/utility.hpp>
32 #include "../boost/intrusive/ilist.hpp"
33 #include "../boost/intrusive/ilist_hook.hpp"
35 //#include "FIFORunner.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
41 /** \brief Task execution scheduler
43 The FIFORunner implements a simple FIFO scheduler for callback tasks. All tasks are held in
44 a queue. Whenever a task is run, it is moved to the end of the queue. Running the queue will
45 run all tasks which have been marked runnable.
47 When running a task, it's runnable flag is always reset. The flag is set whenever an event
48 is posted for the task.
58 typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
59 typedef TaskListBase::value_traits<TaskInfo> TaskListType;
60 typedef boost::intrusive::ilist<TaskListType, false> TaskList;
63 ///////////////////////////////////////////////////////////////////////////
66 /** \brief Task structure
68 TaskInfo is the base-class for all tasks.
76 bool runnable; ///< Runnable flag
77 /**< This must be set to \c true when the task is
78 runnable. It is reset automatically when the task is
81 std::string name; ///< Descriptive task name
83 std::string backtrace;
85 virtual void run() = 0; ///< Called to run the task
88 ///////////////////////////////////////////////////////////////////////////
89 ///\name Structors and default members
96 ///////////////////////////////////////////////////////////////////////////
98 void enqueue(TaskInfo * task); ///< Add task to queue
99 void dequeue(TaskInfo * task); ///< Remove task from queue
101 void run(); ///< Run queue
103 void taskTimeout(unsigned ms); ///< Set task timeout to \a ms milliseconds
104 unsigned taskTimeout() const; ///< Get task timeout in milliseconds
106 unsigned hangCount() const; ///< Number of task expirations
107 /**< The FIFORunner manages a watchdog which checks, that a
108 single task does not run continuously for a longer time
109 or block. If a task runs for more than 1s, a warning is
110 printed and the hangCount is increased. */
115 static void watchdog(int, siginfo_t *, void *);
118 TaskList::iterator next_;
120 unsigned watchdogMs_;
121 std::string runningName_;
123 std::string runningBacktrace_;
125 unsigned watchdogCount_;
132 ///////////////////////////////hh.e////////////////////////////////////////
133 #include "FIFORunner.cci"
134 //#include "FIFORunner.ct"
135 //#include "FIFORunner.cti"
142 // comment-column: 40
143 // c-file-style: "senf"
144 // indent-tabs-mode: nil
145 // ispell-local-dictionary: "american"
146 // compile-command: "scons -u test"