task_adaptors.hpp
Go to the documentation of this file.
1 
17 #ifndef THREADPOOL_TASK_ADAPTERS_HPP_INCLUDED
18 #define THREADPOOL_TASK_ADAPTERS_HPP_INCLUDED
19 
20 
21 #include <boost/smart_ptr.hpp>
22 #include <boost/function.hpp>
23 #include <boost/thread.hpp>
24 
25 
26 namespace boost { namespace threadpool
27 {
28 
37  typedef function0<void> task_func;
38 
39 
40 
41 
52  {
53  private:
54  unsigned int m_priority;
55  task_func m_function;
56 
57  public:
58  typedef void result_type;
59 
60  public:
65  prio_task_func(unsigned int const priority, task_func const & function)
66  : m_priority(priority)
67  , m_function(function)
68  {
69  }
70 
73  void operator() (void) const
74  {
75  if(m_function)
76  {
77  m_function();
78  }
79  }
80 
85  bool operator< (const prio_task_func& rhs) const
86  {
87  return m_priority < rhs.m_priority;
88  }
89 
90  }; // prio_task_func
91 
92 
93 
94 
95 
96 
97 
98 
108  {
109  private:
110  function0<bool> m_function;
111  unsigned int m_break_s;
112  unsigned int m_break_ns;
113 
114  public:
115  typedef void result_type;
116 
117  public:
122  looped_task_func(function0<bool> const & function, unsigned int const interval = 0)
123  : m_function(function)
124  {
125  m_break_s = interval / 1000;
126  m_break_ns = (interval - m_break_s * 1000) * 1000 * 1000;
127  }
128 
131  void operator() (void) const
132  {
133  if(m_function)
134  {
135  if(m_break_s > 0 || m_break_ns > 0)
136  { // Sleep some time before first execution
137  xtime xt;
138  xtime_get(&xt, TIME_UTC);
139  xt.nsec += m_break_ns;
140  xt.sec += m_break_s;
141  thread::sleep(xt);
142  }
143 
144  while(m_function())
145  {
146  if(m_break_s > 0 || m_break_ns > 0)
147  {
148  xtime xt;
149  xtime_get(&xt, TIME_UTC);
150  xt.nsec += m_break_ns;
151  xt.sec += m_break_s;
152  thread::sleep(xt);
153  }
154  else
155  {
156  thread::yield(); // Be fair to other threads
157  }
158  }
159  }
160  }
161 
162  }; // looped_task_func
163 
164 
165 } } // namespace boost::threadpool
166 
167 #endif // THREADPOOL_TASK_ADAPTERS_HPP_INCLUDED
168 
task_func m_function
The task&#39;s function.
The namespace threadpool contains a thread pool and related utility classes.
void result_type
Indicates the functor&#39;s result type.
unsigned int m_priority
The priority of the task&#39;s function.
prio_task_func(unsigned int const priority, task_func const &function)
Looped task function object.
function0< bool > m_function
The task&#39;s function.
bool operator<(const prio_task_func &rhs) const
void result_type
Indicates the functor&#39;s result type.
looped_task_func(function0< bool > const &function, unsigned int const interval=0)
unsigned int m_break_ns
Duration of breaks in nano seconds.
unsigned int m_break_s
Duration of breaks in seconds.
Prioritized task function object.
function0< void > task_func
Standard task function object.


asr_descriptor_surface_based_recognition
Author(s): Allgeyer Tobias, Hutmacher Robin, Meißner Pascal
autogenerated on Mon Dec 16 2019 03:31:15