Scheduler: Restructure signal blocking/unblocking
[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_ unsigned senf::scheduler::detail::FIFORunner::hangCount()
127     const
128 {
129     return hangCount_;
130 }
131
132 prefix_ senf::scheduler::detail::FIFORunner::iterator
133 senf::scheduler::detail::FIFORunner::begin()
134     const
135 {
136     // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added is such
137     // an element and must be skipped.
138     return boost::make_filter_iterator(
139         EventManager::IteratorFilter(), tasks_.begin(), tasks_.end());
140 }
141
142 prefix_ senf::scheduler::detail::FIFORunner::iterator senf::scheduler::detail::FIFORunner::end()
143     const
144 {
145     return boost::make_filter_iterator(
146         EventManager::IteratorFilter(), tasks_.end(), tasks_.end());
147 }
148
149 ///////////////////////////////cci.e///////////////////////////////////////
150 #undef prefix_
151
152 \f
153 // Local Variables:
154 // mode: c++
155 // fill-column: 100
156 // comment-column: 40
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"
161 // End: