Scheduler: Fix stupid typing error
[senf.git] / 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_FIFORunner_
27 #define HH_FIFORunner_ 1
28
29 // Custom includes
30 #include <signal.h>
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"
36
37 //#include "FIFORunner.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
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             explicit TaskInfo(std::string const & name);
65             virtual ~TaskInfo();
66
67             void run();
68
69             bool runnable() const;
70
71         protected:
72             void setRunnable();
73             
74         private:
75             virtual void v_run() = 0;
76             virtual bool v_enabled() const;
77
78             bool runnable_;
79 #       ifdef SENF_DEBUG
80             std::string backtrace_;
81 #       endif
82
83             friend class FIFORunner;
84         };
85
86         typedef boost::filter_iterator<
87             EventManager::IteratorFilter, TaskList::const_iterator> iterator;
88
89         using singleton<FIFORunner>::instance;
90         using singleton<FIFORunner>::alive;
91
92         void enqueue(TaskInfo * task);
93         void dequeue(TaskInfo * task);
94         
95         void run();
96
97         void taskTimeout(unsigned ms);
98         unsigned taskTimeout() const;
99
100         unsigned hangCount() const;
101
102         iterator begin() const;
103         iterator end() const;
104
105     protected:
106
107     private:
108         FIFORunner();
109         ~FIFORunner();
110
111         static void watchdog(int, siginfo_t *, void *);
112
113         TaskList tasks_;
114         TaskList::iterator next_;
115         timer_t watchdogId_;
116         unsigned watchdogMs_;
117         std::string runningName_;
118 #   ifdef SENF_DEBUG
119         std::string runningBacktrace_;
120 #   endif
121         unsigned watchdogCount_;
122         unsigned hangCount_;
123
124         friend void senf::scheduler::restart();
125         friend class singleton<FIFORunner>;
126     };
127
128 }}}
129
130 ///////////////////////////////hh.e////////////////////////////////////////
131 #include "FIFORunner.cci"
132 //#include "FIFORunner.ct"
133 //#include "FIFORunner.cti"
134 #endif
135
136 \f
137 // Local Variables:
138 // mode: c++
139 // fill-column: 100
140 // comment-column: 40
141 // c-file-style: "senf"
142 // indent-tabs-mode: nil
143 // ispell-local-dictionary: "american"
144 // compile-command: "scons -u test"
145 // End: