Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Scheduler / FIFORunner.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief FIFORunner public header */
25
26 #ifndef HH_SENF_Scheduler_FIFORunner_
27 #define HH_SENF_Scheduler_FIFORunner_ 1
28
29 // Custom includes
30 #include <signal.h>
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"
36
37 //#include "FIFORunner.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 namespace senf {
41 namespace scheduler {
42
43     void restart();
44
45 namespace detail {
46
47     class FIFORunner
48         : public singleton<FIFORunner>
49     {
50     public:
51         struct TaskInfo;
52
53     private:
54         struct TaskListTag;
55         typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
56         typedef boost::intrusive::ilist<TaskListBase::value_traits<TaskInfo>, false> TaskList;
57
58     public:
59         class TaskInfo
60             : public Event,
61               public TaskListBase
62         {
63         public:
64             enum Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 };
65
66             explicit TaskInfo(std::string const & name, Priority priority=PRIORITY_NORMAL);
67             virtual ~TaskInfo();
68
69             void run();
70
71             bool runnable() const;
72
73         protected:
74             void setRunnable();
75
76         private:
77             virtual void v_run() = 0;
78             virtual bool v_enabled() const;
79
80             bool runnable_;
81             Priority priority_;
82 #       ifdef SENF_DEBUG
83             std::string backtrace_;
84 #       endif
85
86             friend class FIFORunner;
87         };
88
89         typedef boost::filter_iterator<
90             EventManager::IteratorFilter, TaskList::const_iterator> iterator;
91
92         using singleton<FIFORunner>::instance;
93         using singleton<FIFORunner>::alive;
94
95         void enqueue(TaskInfo * task);
96         void dequeue(TaskInfo * task);
97
98         void run();
99
100         void taskTimeout(unsigned ms);
101         unsigned taskTimeout() const;
102         void abortOnTimeout(bool flag);
103         bool abortOnTimeout() const;
104
105         void startWatchdog();
106         void stopWatchdog();
107
108         unsigned hangCount();
109
110         iterator begin() const;
111         iterator end() const;
112
113         void yield();
114
115     protected:
116
117     private:
118         FIFORunner();
119         ~FIFORunner();
120
121         static void watchdog(int, siginfo_t *, void *);
122         void watchdogError();
123
124         TaskList::iterator priorityEnd(TaskInfo::Priority p);
125         void run(TaskList::iterator f, TaskList::iterator l);
126
127         struct NullTask : public TaskInfo
128         {
129             NullTask();
130             ~NullTask();
131             virtual void v_run();;
132             virtual char const * v_type() const;
133             virtual std::string v_info() const;
134         };
135
136         TaskList tasks_;
137         TaskList::iterator next_;
138
139         NullTask normalPriorityEnd_;
140         NullTask highPriorityEnd_;
141
142         timer_t watchdogId_;
143         bool watchdogRunning_;
144         unsigned watchdogMs_;
145         bool watchdogAbort_;
146         std::string runningName_;
147 #   ifdef SENF_DEBUG
148         std::string runningBacktrace_;
149 #   endif
150         unsigned watchdogCount_;
151         unsigned hangCount_;
152         bool yield_;
153
154         friend void senf::scheduler::restart();
155         friend class singleton<FIFORunner>;
156     };
157
158 }}}
159
160 //-/////////////////////////////////////////////////////////////////////////////////////////////////
161 #include "FIFORunner.cci"
162 //#include "FIFORunner.ct"
163 //#include "FIFORunner.cti"
164 #endif
165
166 \f
167 // Local Variables:
168 // mode: c++
169 // fill-column: 100
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"
175 // End: