| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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;
80 shared_ptr<pool_core_type> m_core; // pimpl idiom
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
202 typedef thread_pool<task_func, fifo_scheduler, static_size, resize_controller, wait_for_all_tasks> fifo_pool;
203
204
210 typedef thread_pool<task_func, lifo_scheduler, static_size, resize_controller, wait_for_all_tasks> lifo_pool;
211
212
218 typedef thread_pool<prio_task_func, prio_scheduler, static_size, resize_controller, wait_for_all_tasks> prio_pool;
219
220
226 typedef fifo_pool pool;
227
228
229
230 } } // namespace boost::threadpool
231
232 #endif // THREADPOOL_POOL_HPP_INCLUDED
boost::threadpool::thread_pool::wait
void wait(size_t task_threshold=0) const
The current thread of execution is blocked until the sum of all active and pending tasks is equal or ...
Definition: pool.hpp:176
size_policies.hpp
Size policies.
boost::threadpool::thread_pool::task_type
Task task_type
Indicates the task&#39;s type.
Definition: pool.hpp:84
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
task_adaptors.hpp
Task adaptors.
boost::threadpool::thread_pool::pool_core_type
detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_core_type
Definition: pool.hpp:79
boost::threadpool::thread_pool::scheduler_type
SchedulingPolicy< task_type > scheduler_type
Indicates the scheduler&#39;s type.
Definition: pool.hpp:85
boost::threadpool::thread_pool::size_controller_type
SizePolicyController< pool_core_type > size_controller_type
Definition: pool.hpp:92
boost::threadpool::thread_pool::size_policy_type
SizePolicy< pool_core_type > size_policy_type
Definition: pool.hpp:91
Gaudi::Functional::void
class MergingTransformer< Out(const vector_of_const_< In > void
Definition: MergingTransformer.h:23
boost::threadpool::fifo_pool
thread_pool< task_func, fifo_scheduler, static_size, resize_controller, wait_for_all_tasks > fifo_pool
Fifo pool.
Definition: pool.hpp:202
pool_core.hpp
Thread pool core.
boost::threadpool::thread_pool::schedule
bool schedule(task_type const &task)
Schedules a task for asynchronous execution.
Definition: pool.hpp:130
boost::threadpool::thread_pool::empty
bool empty() const
Indicates that there are no tasks pending.
Definition: pool.hpp:166
boost::threadpool::lifo_pool
thread_pool< task_func, lifo_scheduler, static_size, resize_controller, wait_for_all_tasks > lifo_pool
Lifo pool.
Definition: pool.hpp:210
boost::threadpool::thread_pool::thread_pool
thread_pool(size_t initial_threads=0)
Constructor.
Definition: pool.hpp:99
boost::threadpool::prio_pool
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
boost::threadpool::thread_pool::m_shutdown_controller
shared_ptr< void > m_shutdown_controller
Definition: pool.hpp:81
boost::threadpool::thread_pool::pending
size_t pending() const
Returns the number of tasks which are ready for execution.
Definition: pool.hpp:148
boost::threadpool::pool
fifo_pool pool
A standard pool.
Definition: pool.hpp:226
boost::threadpool::thread_pool::active
size_t active() const
Returns the number of tasks which are currently executed.
Definition: pool.hpp:139
boost::threadpool::thread_pool::size_controller
size_controller_type size_controller()
Gets the size controller which manages the number of threads in the pool.
Definition: pool.hpp:111
boost::threadpool::thread_pool
Thread pool.
Definition: pool.hpp:73
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
boost::threadpool::detail::pool_core
Thread pool.
Definition: pool_core.hpp:75
boost::threadpool::thread_pool::wait
bool wait(xtime const &timestamp, size_t task_threshold=0) const
The current thread of execution is blocked until the timestamp is met or the sum of all active and pe...
Definition: pool.hpp:189
boost::threadpool::thread_pool::clear
void clear()
Removes all pending tasks from the pool&#39;s scheduler.
Definition: pool.hpp:156
shutdown_policies.hpp
Shutdown policies.
locking_ptr.hpp
The locking_ptr is smart pointer with a scoped locking mechanism.
boost::threadpool::task_func
function0< void > task_func
Standard task function object.
Definition: task_adaptors.hpp:37
boost::threadpool::thread_pool::size
size_t size() const
Gets the number of threads in the pool.
Definition: pool.hpp:120
scheduling_policies.hpp
Task scheduling policies.