pool.hpp
Go to the documentation of this file.
1 
22 #ifndef THREADPOOL_POOL_HPP_INCLUDED
23 #define THREADPOOL_POOL_HPP_INCLUDED
24 
25 #include <boost/ref.hpp>
26 
27 #include "./detail/pool_core.hpp"
28 
29 #include "task_adaptors.hpp"
30 
31 #include "./detail/locking_ptr.hpp"
32 
33 #include "scheduling_policies.hpp"
34 #include "size_policies.hpp"
35 #include "shutdown_policies.hpp"
36 
37 
38 
40 namespace boost { namespace threadpool
41 {
42 
43 
44 
66  template <
67  typename Task = task_func,
68  template <typename> class SchedulingPolicy = fifo_scheduler,
69  template <typename> class SizePolicy = static_size,
70  template <typename> class SizePolicyController = resize_controller,
71  template <typename> class ShutdownPolicy = wait_for_all_tasks
72  >
73  class thread_pool
74  {
75  typedef detail::pool_core<Task,
76  SchedulingPolicy,
77  SizePolicy,
78  SizePolicyController,
79  ShutdownPolicy> pool_core_type;
81  shared_ptr<void> m_shutdown_controller; // If the last pool holding a pointer to the core is deleted the controller shuts the pool down.
82 
83  public: // Type definitions
84  typedef Task task_type;
85  typedef SchedulingPolicy<task_type> scheduler_type;
86  /* typedef thread_pool<Task,
87  SchedulingPolicy,
88  SizePolicy,
89  ShutdownPolicy > pool_type; //!< Indicates the thread pool's type.
90  */
91  typedef SizePolicy<pool_core_type> size_policy_type;
92  typedef SizePolicyController<pool_core_type> size_controller_type;
93 
94 
95  public:
99  thread_pool(size_t initial_threads = 0)
100  : m_core(new pool_core_type)
101  , m_shutdown_controller(static_cast<void*>(0), bind(&pool_core_type::shutdown, m_core))
102  {
103  size_policy_type::init(*m_core, initial_threads);
104  }
105 
106 
111  size_controller_type size_controller()
112  {
113  return m_core->size_controller();
114  }
115 
116 
120  size_t size() const
121  {
122  return m_core->size();
123  }
124 
125 
130  bool schedule(task_type const & task)
131  {
132  return m_core->schedule(task);
133  }
134 
135 
139  size_t active() const
140  {
141  return m_core->active();
142  }
143 
144 
148  size_t pending() const
149  {
150  return m_core->pending();
151  }
152 
153 
156  void clear()
157  {
158  m_core->clear();
159  }
160 
161 
166  bool empty() const
167  {
168  return m_core->empty();
169  }
170 
171 
176  void wait(size_t task_threshold = 0) const
177  {
178  m_core->wait(task_threshold);
179  }
180 
181 
189  bool wait(xtime const & timestamp, size_t task_threshold = 0) const
190  {
191  return m_core->wait(timestamp, task_threshold);
192  }
193  };
194 
195 
196 
203 
204 
211 
212 
219 
220 
226  typedef fifo_pool pool;
227 
228 
229 
230 } } // namespace boost::threadpool
231 
232 #endif // THREADPOOL_POOL_HPP_INCLUDED
void wait(size_t task_threshold=0) const
Definition: pool.hpp:176
Size policies.
Task task_type
Indicates the task&#39;s type.
Definition: pool.hpp:84
The namespace threadpool contains a thread pool and related utility classes.
Task adaptors.
detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_core_type
Definition: pool.hpp:79
SchedulingPolicy< task_type > scheduler_type
Indicates the scheduler&#39;s type.
Definition: pool.hpp:85
SizePolicyController< pool_core_type > size_controller_type
Definition: pool.hpp:92
SizePolicy< pool_core_type > size_policy_type
Definition: pool.hpp:91
thread_pool< task_func, fifo_scheduler, static_size, resize_controller, wait_for_all_tasks > fifo_pool
Fifo pool.
Definition: pool.hpp:202
Thread pool core.
bool schedule(task_type const &task)
Definition: pool.hpp:130
thread_pool< task_func, lifo_scheduler, static_size, resize_controller, wait_for_all_tasks > lifo_pool
Lifo pool.
Definition: pool.hpp:210
thread_pool(size_t initial_threads=0)
Definition: pool.hpp:99
thread_pool< prio_task_func, prio_scheduler, static_size, resize_controller, wait_for_all_tasks > prio_pool
Pool for prioritized task.
Definition: pool.hpp:218
shared_ptr< void > m_shutdown_controller
Definition: pool.hpp:81
size_t pending() const
Definition: pool.hpp:148
fifo_pool pool
A standard pool.
Definition: pool.hpp:226
size_t active() const
Definition: pool.hpp:139
size_controller_type size_controller()
Definition: pool.hpp:111
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
bool wait(xtime const &timestamp, size_t task_threshold=0) const
Definition: pool.hpp:189
Shutdown policies.
The locking_ptr is smart pointer with a scoped locking mechanism.
function0< void > task_func
Standard task function object.
size_t size() const
Definition: pool.hpp:120
Task scheduling policies.


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