FIFORunner.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief FIFORunner inline non-template implementation */
16 
17 //#include "FIFORunner.ih"
18 
19 // Custom includes
20 #include <senf/config.hh>
21 #ifdef SENF_BACKTRACE
22 # include <sstream>
23 # include <senf/Utils/Backtrace.hh>
24 #endif
25 
26 #define prefix_ inline
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 // senf::scheduler::detail::FIFORunner::TaskInfo
31 
32 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::TaskInfo(std::string const & name,
33  Priority priority)
34  : Event(name), runnable_ (false), priority_ (priority)
35 {
36 #ifdef SENF_BACKTRACE
37  std::stringstream ss;
38  senf::backtrace(ss, 32);
39  backtrace_ = ss.str();
40 #endif
41 }
42 
43 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::~TaskInfo()
44 {}
45 
46 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::setRunnable()
47 {
48  runnable_ = true;
49 }
50 
51 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::run()
52 {
53  countRun();
54  // Be sure to run v_run last since the callback may destroy this instance
55  v_run();
56 }
57 
58 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::runnable()
59  const
60 {
61  return runnable_;
62 }
63 
64 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::v_enabled()
65  const
66 {
67  return TaskListBase::is_linked();
68 }
69 
70 //-/////////////////////////////////////////////////////////////////////////////////////////////////
71 // senf::scheduler::detail::FIFORunner::NullTask
72 
73 prefix_ senf::scheduler::detail::FIFORunner::NullTask::NullTask()
74  : senf::scheduler::detail::FIFORunner::TaskInfo ("<null>")
75 {}
76 
77 prefix_ senf::scheduler::detail::FIFORunner::NullTask::~NullTask()
78 {
79  if (TaskListBase::is_linked())
80  FIFORunner::instance().dequeue(this);
81 }
82 
83 prefix_ void senf::scheduler::detail::FIFORunner::NullTask::v_run()
84 {}
85 
86 prefix_ char const * senf::scheduler::detail::FIFORunner::NullTask::v_type()
87  const
88 {
89  return nullptr;
90 }
91 
92 prefix_ std::string senf::scheduler::detail::FIFORunner::NullTask::v_info()
93  const
94 {
95  return "";
96 }
97 
98 //-/////////////////////////////////////////////////////////////////////////////////////////////////
99 // senf::scheduler::detail::FIFORunner
100 
101 prefix_ void senf::scheduler::detail::FIFORunner::enqueue(TaskInfo * task)
102 {
103  tasks_.insert(priorityEnd(task->priority_), *task);
104 }
105 
106 prefix_ void senf::scheduler::detail::FIFORunner::taskTimeout(unsigned ms)
107 {
108  watchdogMs_ = ms;
109  if (watchdogRunning_)
110  startWatchdog();
111 }
112 
113 prefix_ unsigned senf::scheduler::detail::FIFORunner::taskTimeout()
114  const
115 {
116  return watchdogMs_;
117 }
118 
119 prefix_ void senf::scheduler::detail::FIFORunner::watchdogCallback(WatchdogCallback const & cb)
120 {
121  watchdogCallback_ = cb;
122 }
123 
124 prefix_ void senf::scheduler::detail::FIFORunner::abortOnTimeout(bool flag)
125 {
126  watchdogAbort_ = flag;
127 }
128 
129 prefix_ bool senf::scheduler::detail::FIFORunner::abortOnTimeout()
130  const
131 {
132  return watchdogAbort_;
133 }
134 
135 prefix_ unsigned senf::scheduler::detail::FIFORunner::hangCount()
136 {
137  unsigned hc (hangCount_);
138  hangCount_ = 0;
139  return hc;
140 }
141 
142 prefix_ senf::scheduler::detail::FIFORunner::iterator
143 senf::scheduler::detail::FIFORunner::begin()
144  const
145 {
146  // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added is such
147  // an element and must be skipped.
148  return boost::make_filter_iterator(
149  EventManager::IteratorFilter(), tasks_.begin(), tasks_.end());
150 }
151 
152 prefix_ senf::scheduler::detail::FIFORunner::iterator senf::scheduler::detail::FIFORunner::end()
153  const
154 {
155  return boost::make_filter_iterator(
156  EventManager::IteratorFilter(), tasks_.end(), tasks_.end());
157 }
158 
159 prefix_ void senf::scheduler::detail::FIFORunner::yield()
160 {
161  yield_ = true;
162 }
163 
164 prefix_ void senf::scheduler::detail::FIFORunner::watchdogCheckpoint(const char * checkpoint)
165 {
166  watchdogCheckpoint_ = checkpoint;
167 }
168 
169 //-/////////////////////////////////////////////////////////////////////////////////////////////////
170 #undef prefix_
171 
172 
173 // Local Variables:
174 // mode: c++
175 // fill-column: 100
176 // comment-column: 40
177 // c-file-style: "senf"
178 // indent-tabs-mode: nil
179 // ispell-local-dictionary: "american"
180 // compile-command: "scons -u test"
181 // End: