Fix SCons 1.2.0 build failure
[senf.git] / Scheduler / FIFORunner.cci
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 inline non-template implementation */
25
26 //#include "FIFORunner.ih"
27
28 // Custom includes
29 #ifdef SENF_DEBUG
30 #include <sstream>
31 #include "../Utils/Backtrace.hh"
32 #endif
33
34 #define prefix_ inline
35 ///////////////////////////////cci.p///////////////////////////////////////
36
37 ///////////////////////////////////////////////////////////////////////////
38 //  senf::scheduler::detail::FIFORunner::TaskInfo
39
40 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::TaskInfo(std::string const & name,
41                                                                 Priority priority)
42     : Event(name), runnable_ (false), priority_ (priority)
43 {}
44
45 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::~TaskInfo()
46 {}
47
48 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::setRunnable()
49 {
50     runnable_ = true;
51 }
52
53 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::run()
54 {
55     countRun();
56     // Be sure to run v_run last since the callback may destroy this instance
57     v_run();
58 }
59
60 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::runnable()
61     const
62 {
63     return runnable_;
64 }
65
66 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::v_enabled()
67     const
68 {
69     return TaskListBase::linked();
70 }
71
72 ///////////////////////////////////////////////////////////////////////////
73 // senf::scheduler::detail::FIFORunner::NullTask
74
75 prefix_ senf::scheduler::detail::FIFORunner::NullTask::NullTask()
76     : senf::scheduler::detail::FIFORunner::TaskInfo ("<null>") 
77 {}
78
79 prefix_ senf::scheduler::detail::FIFORunner::NullTask::~NullTask()
80 {
81     if (TaskListBase::linked())
82         FIFORunner::instance().dequeue(this);
83 }
84
85 prefix_ void senf::scheduler::detail::FIFORunner::NullTask::v_run()
86 {}
87
88 prefix_ char const * senf::scheduler::detail::FIFORunner::NullTask::v_type()
89     const
90 {
91     return 0;
92 }
93
94 prefix_ std::string senf::scheduler::detail::FIFORunner::NullTask::v_info()
95     const
96 {
97     return "";
98 }
99
100 ///////////////////////////////////////////////////////////////////////////
101 // senf::scheduler::detail::FIFORunner
102
103 prefix_ void senf::scheduler::detail::FIFORunner::enqueue(TaskInfo * task)
104 {
105     tasks_.insert(priorityEnd(task->priority_), *task);
106 #ifdef SENF_DEBUG
107     std::stringstream ss;
108     backtrace(ss, 32);
109     task->backtrace_ = ss.str();
110 #endif
111 }
112
113 prefix_ void senf::scheduler::detail::FIFORunner::taskTimeout(unsigned ms)
114 {
115     watchdogMs_ = ms;
116     if (watchdogRunning_)
117         startWatchdog();
118 }
119
120 prefix_ unsigned senf::scheduler::detail::FIFORunner::taskTimeout()
121     const
122 {
123     return watchdogMs_;
124 }
125
126 prefix_ void senf::scheduler::detail::FIFORunner::abortOnTimeout(bool flag)
127 {
128     watchdogAbort_ = flag;
129 }
130
131 prefix_ bool senf::scheduler::detail::FIFORunner::abortOnTimeout()
132     const
133 {
134     return watchdogAbort_;
135 }
136
137 prefix_ unsigned senf::scheduler::detail::FIFORunner::hangCount()
138 {
139     unsigned hc (hangCount_);
140     hangCount_ = 0;
141     return hc;
142 }
143
144 prefix_ senf::scheduler::detail::FIFORunner::iterator
145 senf::scheduler::detail::FIFORunner::begin()
146     const
147 {
148     // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added is such
149     // an element and must be skipped.
150     return boost::make_filter_iterator(
151         EventManager::IteratorFilter(), tasks_.begin(), tasks_.end());
152 }
153
154 prefix_ senf::scheduler::detail::FIFORunner::iterator senf::scheduler::detail::FIFORunner::end()
155     const
156 {
157     return boost::make_filter_iterator(
158         EventManager::IteratorFilter(), tasks_.end(), tasks_.end());
159 }
160
161 prefix_ void senf::scheduler::detail::FIFORunner::yield()
162 {
163     yield_ = true;
164 }
165
166 ///////////////////////////////cci.e///////////////////////////////////////
167 #undef prefix_
168
169 \f
170 // Local Variables:
171 // mode: c++
172 // fill-column: 100
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"
178 // End: