| The Gaudi Framework v28r2p1 (f1a77ff4)

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > Class Template Reference

Thread pool. More...

`#include <src/threadpool/boost/threadpool/detail/pool_core.hpp>`

Inheritance diagram for boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >:
[legend]
Collaboration diagram for boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >:
[legend]

## Public Types
typedef Task | task_type
| Indicates the task's type. More...
typedef SchedulingPolicy< task_type > | scheduler_type
| Indicates the scheduler's type. More...
typedef pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > | pool_type
| Indicates the thread pool's type. More...
typedef SizePolicy< pool_type > | size_policy_type
| Indicates the sizer's type. More...
typedef SizePolicyController< pool_type > | size_controller_type
typedef ShutdownPolicy< pool_type > | shutdown_policy_type
| Indicates the shutdown policy's type. More...
typedef worker_thread< pool_type > | worker_type

## Public Member Functions
| BOOST_STATIC_ASSERT (function_traits< task_type()>::arity==0)
| BOOST_STATIC_ASSERT (is_void< typename result_of< task_type()>::type >::value)
| pool_core ()
| Constructor. More...
| ~pool_core ()
| Destructor. More...
size_controller_type | size_controller ()
| Gets the size controller which manages the number of threads in the pool. More...
size_t | size () const volatile
| Gets the number of threads in the pool. More...
void | shutdown ()
bool | schedule (task_type const &task) volatile
| Schedules a task for asynchronous execution. More...
size_t | active () const volatile
| Returns the number of tasks which are currently executed. More...
size_t | pending () const volatile
| Returns the number of tasks which are ready for execution. More...
void | clear () volatile
| Removes all pending tasks from the pool's scheduler. More...
bool | empty () const volatile
| Indicates that there are no tasks pending. More...
void | wait (size_t const task_threshold=0) const volatile
| The current thread of execution is blocked until the sum of all active and pending tasks is equal or less than a given threshold. More...
bool | wait (xtime const &timestamp, size_t const task_threshold=0) const volatile
| The current thread of execution is blocked until the timestamp is met or the sum of all active and pending tasks is equal or less than a given threshold. More...

## Private Member Functions
void | terminate_all_workers (bool const wait) volatile
bool | resize (size_t const worker_count) volatile
| Changes the number of worker threads in the pool. More...
void | worker_died_unexpectedly (shared_ptr< worker_type > worker) volatile
void | worker_destructed (shared_ptr< worker_type > worker) volatile
bool | execute_task () volatile

## Private Attributes
volatile size_t | m_worker_count
volatile size_t | m_target_worker_count
volatile size_t | m_active_worker_count
scheduler_type | m_scheduler
scoped_ptr< size_policy_type > | m_size_policy
bool | m_terminate_all_workers
std::vector< shared_ptr< worker_type > > | m_terminated_workers
recursive_mutex | m_monitor
condition | m_worker_idle_or_terminated_event
condition | m_task_or_terminate_workers_event

## Friends
class | worker_thread< pool_type >
class | SizePolicy< pool_type >
class | ShutdownPolicy< pool_type >

## Detailed Description

### template<typename Task, template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>
class boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >

Thread pool.

Thread pools are a mechanism for asynchronous and parallel processing within the same process. The pool class provides a convenient way for dispatching asynchronous tasks as functions objects. The scheduling of these tasks can be easily controlled by using customized schedulers. A task must not throw an exception.

A pool_impl is DefaultConstructible and NonCopyable.

Parameters

  Task | A function object which implements the operator 'void operator() (void) const'. The operator () is called by the pool to execute the task. Exceptions are ignored.
  Scheduler | A task container which determines how tasks are scheduled. It is guaranteed that this container is accessed only by one thread at a time. The scheduler shall not throw exceptions.

Remarks
  The pool class is thread-safe.

See also
  Tasks: task_func, prio_task_func
  Scheduling policies: fifo_scheduler, lifo_scheduler, prio_scheduler

Definition at line 75 of file pool_core.hpp.

## Member Typedef Documentation

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef pool_core<Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pool_type

Indicates the thread pool's type.

Definition at line 87 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef SchedulingPolicy<task_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::scheduler_type

Indicates the scheduler's type.

Definition at line 82 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef ShutdownPolicy<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::shutdown_policy_type

Indicates the shutdown policy's type.

Definition at line 94 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef SizePolicyController<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_controller_type

Definition at line 91 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef SizePolicy<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_policy_type

Indicates the sizer's type.

Definition at line 88 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef Task boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::task_type

Indicates the task's type.

Definition at line 81 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

typedef worker_thread<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::worker_type

Definition at line 96 of file pool_core.hpp.

## Constructor & Destructor Documentation

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pool_core | ( |  | ) |
| inline

Constructor.

Definition at line 137 of file pool_core.hpp.

138 : m_worker_count(0)
139 , m_target_worker_count(0)
140 , m_active_worker_count(0)
141 , m_terminate_all_workers(false)
142 {
143 pool_type volatile & self_ref = *this;
144 m_size_policy.reset(new size_policy_type(self_ref));
145
146 m_scheduler.clear();
147 }
boost::threadpool::detail::pool_core::m_worker_count
volatile size_t m_worker_count
Definition: pool_core.hpp:117
boost::threadpool::detail::pool_core::m_target_worker_count
volatile size_t m_target_worker_count
Definition: pool_core.hpp:118
boost::threadpool::detail::pool_core::size_policy_type
SizePolicy< pool_type > size_policy_type
Indicates the sizer&#39;s type.
Definition: pool_core.hpp:88
boost::threadpool::detail::pool_core::pool_type
pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_type
Indicates the thread pool&#39;s type.
Definition: pool_core.hpp:87
boost::threadpool::detail::pool_core::m_size_policy
scoped_ptr< size_policy_type > m_size_policy
Definition: pool_core.hpp:125
boost::threadpool::detail::pool_core::m_scheduler
scheduler_type m_scheduler
Definition: pool_core.hpp:124
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
boost::threadpool::detail::pool_core::m_terminate_all_workers
bool m_terminate_all_workers
Definition: pool_core.hpp:127
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::~pool_core | ( |  | ) |
| inline

Destructor.

Definition at line 151 of file pool_core.hpp.

152 {
153 }

## Member Function Documentation

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::active | ( |  | ) | const volatile
| inline

Returns the number of tasks which are currently executed.

Returns
  The number of active tasks.

Definition at line 201 of file pool_core.hpp.

202 {
203 return m_active_worker_count;
204 }
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::BOOST_STATIC_ASSERT | ( | function_traits< task_type()>::arity | = `=0` | ) |

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::BOOST_STATIC_ASSERT | ( | is_void< typename result_of< task_type()>::type >::value |  | ) |

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::clear | ( |  | ) | volatile
| inline

Removes all pending tasks from the pool's scheduler.

Definition at line 219 of file pool_core.hpp.

220 {
221 locking_ptr<pool_type, recursive_mutex> lockedThis(*this, m_monitor);
222 lockedThis->m_scheduler.clear();
223 }
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::empty | ( |  | ) | const volatile
| inline

Indicates that there are no tasks pending.

Returns
  true if there are no tasks ready for execution.

Remarks
  This function is more efficient that the check 'pending() == 0'.

Definition at line 230 of file pool_core.hpp.

231 {
232 locking_ptr<const pool_type, recursive_mutex> lockedThis(*this, m_monitor);
233 return lockedThis->m_scheduler.empty();
234 }
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::execute_task | ( |  | ) | volatile
| inline private

Definition at line 401 of file pool_core.hpp.

402 {
403 function0<void> task;
404
405 { // fetch task
406 pool_type* lockedThis = const_cast<pool_type*>(this);
407 recursive_mutex::scoped_lock lock(lockedThis->m_monitor);
408
409 // decrease number of threads if necessary
410 if(m_worker_count > m_target_worker_count)
411 {
412 return false; // terminate worker
413 }
414
415
416 // wait for tasks
417 while(lockedThis->m_scheduler.empty())
418 {
419 // decrease number of workers if necessary
420 if(m_worker_count > m_target_worker_count)
421 {
422 return false; // terminate worker
423 }
424 else
425 {
426 m_active_worker_count--;
427 lockedThis->m_worker_idle_or_terminated_event.notify_all();
428 lockedThis->m_task_or_terminate_workers_event.wait(lock);
429 m_active_worker_count++;
430 }
431 }
432
433 task = lockedThis->m_scheduler.top();
434 lockedThis->m_scheduler.pop();
435 }
436
437 // call task function
438 if(task)
439 {
440 task();
441 }
442
443 //guard->disable();
444 return true;
445 }
boost::threadpool::detail::pool_core::m_worker_count
volatile size_t m_worker_count
Definition: pool_core.hpp:117
boost::threadpool::detail::pool_core::m_target_worker_count
volatile size_t m_target_worker_count
Definition: pool_core.hpp:118
boost::threadpool::detail::pool_core::pool_type
pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_type
Indicates the thread pool&#39;s type.
Definition: pool_core.hpp:87
std::lock
T lock(T...args)
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pending | ( |  | ) | const volatile
| inline

Returns the number of tasks which are ready for execution.

Returns
  The number of pending tasks.

Definition at line 210 of file pool_core.hpp.

211 {
212 locking_ptr<const pool_type, recursive_mutex> lockedThis(*this, m_monitor);
213 return lockedThis->m_scheduler.size();
214 }
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::resize | ( | size_t const | worker_count | ) | volatile
| inline private

Changes the number of worker threads in the pool.

The resizing is handled by the SizePolicy.

Parameters

  threads | The new number of worker threads.

Returns
  true, if pool will be resized and false if not.

Definition at line 329 of file pool_core.hpp.

330 {
331 locking_ptr<pool_type, recursive_mutex> lockedThis(*this, m_monitor);
332
333 if(!m_terminate_all_workers)
334 {
335 m_target_worker_count = worker_count;
336 }
337 else
338 {
339 return false;
340 }
341
342
343 if(m_worker_count <= m_target_worker_count)
344 { // increase worker count
345 while(m_worker_count < m_target_worker_count)
346 {
347 try
348 {
349 worker_thread<pool_type>::create_and_attach(lockedThis->shared_from_this());
350 m_worker_count++;
351 m_active_worker_count++;
352 }
353 catch(thread_resource_error)
354 {
355 return false;
356 }
357 }
358 }
359 else
360 { // decrease worker count
361 lockedThis->m_task_or_terminate_workers_event.notify_all(); // TODO: Optimize number of notified workers
362 }
363
364 return true;
365 }
boost::threadpool::detail::pool_core::m_worker_count
volatile size_t m_worker_count
Definition: pool_core.hpp:117
boost::threadpool::detail::pool_core::m_target_worker_count
volatile size_t m_target_worker_count
Definition: pool_core.hpp:118
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
boost::threadpool::detail::worker_thread::create_and_attach
static void create_and_attach(shared_ptr< pool_type > const &pool)
Constructs a new worker thread and attaches it to the pool.
Definition: worker_thread.hpp:100
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
boost::threadpool::detail::pool_core::m_terminate_all_workers
bool m_terminate_all_workers
Definition: pool_core.hpp:127
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::schedule | ( | task_type const & | task | ) | volatile
| inline

Schedules a task for asynchronous execution.

The task will be executed once only.

Parameters

  task | The task function object. It should not throw execeptions.

Returns
  true, if the task could be scheduled and false otherwise.

Definition at line 182 of file pool_core.hpp.

183 {
184 locking_ptr<pool_type, recursive_mutex> lockedThis(*this, m_monitor);
185
186 if(lockedThis->m_scheduler.push(task))
187 {
188 lockedThis->m_task_or_terminate_workers_event.notify_one();
189 return true;
190 }
191 else
192 {
193 return false;
194 }
195 }
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::shutdown | ( |  | ) |
| inline

Definition at line 173 of file pool_core.hpp.

174 {
175 ShutdownPolicy<pool_type>::shutdown(*this);
176 }
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size | ( |  | ) | const volatile
| inline

Gets the number of threads in the pool.

Returns
  The number of threads.

Definition at line 167 of file pool_core.hpp.

168 {
169 return m_worker_count;
170 }
boost::threadpool::detail::pool_core::m_worker_count
volatile size_t m_worker_count
Definition: pool_core.hpp:117
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

size_controller_type boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_controller | ( |  | ) |
| inline

Gets the size controller which manages the number of threads in the pool.

Returns
  The size controller.

See also
  SizePolicy

Definition at line 159 of file pool_core.hpp.

160 {
161 return size_controller_type(*m_size_policy, this->shared_from_this());
162 }
boost::threadpool::detail::pool_core::m_size_policy
scoped_ptr< size_policy_type > m_size_policy
Definition: pool_core.hpp:125
boost::threadpool::detail::pool_core::size_controller_type
SizePolicyController< pool_type > size_controller_type
Definition: pool_core.hpp:91
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::terminate_all_workers | ( | bool const | wait | ) | volatile
| inline private

Definition at line 296 of file pool_core.hpp.

297 {
298 pool_type* self = const_cast<pool_type*>(this);
299 recursive_mutex::scoped_lock lock(self->m_monitor);
300
301 self->m_terminate_all_workers = true;
302
303 m_target_worker_count = 0;
304 self->m_task_or_terminate_workers_event.notify_all();
305
306 if(wait)
307 {
308 while(m_active_worker_count > 0)
309 {
310 self->m_worker_idle_or_terminated_event.wait(lock);
311 }
312
313 for(typename std::vector<shared_ptr<worker_type> >::iterator it = self->m_terminated_workers.begin();
314 it != self->m_terminated_workers.end();
315 ++it)
316 {
317 (*it)->join();
318 }
319 self->m_terminated_workers.clear();
320 }
321 }
boost::threadpool::detail::pool_core::m_target_worker_count
volatile size_t m_target_worker_count
Definition: pool_core.hpp:118
boost::threadpool::detail::pool_core::pool_type
pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_type
Indicates the thread pool&#39;s type.
Definition: pool_core.hpp:87
std::lock
T lock(T...args)
std::vector
STL class.
std::vector::begin
T begin(T...args)
boost::threadpool::detail::pool_core::wait
void wait(size_t const task_threshold=0) const volatile
The current thread of execution is blocked until the sum of all active and pending tasks is equal or ...
Definition: pool_core.hpp:241
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::wait | ( | size_t const | task_threshold = `0` | ) | const volatile
| inline

The current thread of execution is blocked until the sum of all active and pending tasks is equal or less than a given threshold.

Parameters

  task_threshold | The maximum number of tasks in pool and scheduler.

Definition at line 241 of file pool_core.hpp.

242 {
243 const pool_type* self = const_cast<const pool_type*>(this);
244 recursive_mutex::scoped_lock lock(self->m_monitor);
245
246 if(0 == task_threshold)
247 {
248 while(0 != self->m_active_worker_count || !self->m_scheduler.empty())
249 {
250 self->m_worker_idle_or_terminated_event.wait(lock);
251 }
252 }
253 else
254 {
255 while(task_threshold < self->m_active_worker_count + self->m_scheduler.size())
256 {
257 self->m_worker_idle_or_terminated_event.wait(lock);
258 }
259 }
260 }
boost::threadpool::detail::pool_core::pool_type
pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_type
Indicates the thread pool&#39;s type.
Definition: pool_core.hpp:87
std::lock
T lock(T...args)
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::wait | ( | xtime const & | timestamp,
|  | size_t const | task_threshold = `0`
| ) |  | const volatile
| inline

The current thread of execution is blocked until the timestamp is met or the sum of all active and pending tasks is equal or less than a given threshold.

Parameters

  timestamp | The time when function returns at the latest.
  task_threshold | The maximum number of tasks in pool and scheduler.

Returns
  true if the task sum is equal or less than the threshold, false otherwise.

Definition at line 269 of file pool_core.hpp.

270 {
271 const pool_type* self = const_cast<const pool_type*>(this);
272 recursive_mutex::scoped_lock lock(self->m_monitor);
273
274 if(0 == task_threshold)
275 {
276 while(0 != self->m_active_worker_count || !self->m_scheduler.empty())
277 {
278 if(!self->m_worker_idle_or_terminated_event.timed_wait(lock, timestamp)) return false;
279 }
280 }
281 else
282 {
283 while(task_threshold < self->m_active_worker_count + self->m_scheduler.size())
284 {
285 if(!self->m_worker_idle_or_terminated_event.timed_wait(lock, timestamp)) return false;
286 }
287 }
288
289 return true;
290 }
boost::threadpool::detail::pool_core::pool_type
pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_type
Indicates the thread pool&#39;s type.
Definition: pool_core.hpp:87
std::lock
T lock(T...args)
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::worker_destructed | ( | shared_ptr< worker_type > | worker | ) | volatile
| inline private

Definition at line 387 of file pool_core.hpp.

388 {
389 locking_ptr<pool_type, recursive_mutex> lockedThis(*this, m_monitor);
390 m_worker_count--;
391 m_active_worker_count--;
392 lockedThis->m_worker_idle_or_terminated_event.notify_all();
393
394 if(m_terminate_all_workers)
395 {
396 lockedThis->m_terminated_workers.push_back(worker);
397 }
398 }
boost::threadpool::detail::pool_core::m_worker_count
volatile size_t m_worker_count
Definition: pool_core.hpp:117
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
boost::threadpool::detail::pool_core::m_terminate_all_workers
bool m_terminate_all_workers
Definition: pool_core.hpp:127
template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::worker_died_unexpectedly | ( | shared_ptr< worker_type > | worker | ) | volatile
| inline private

Definition at line 369 of file pool_core.hpp.

370 {
371 locking_ptr<pool_type, recursive_mutex> lockedThis(*this, m_monitor);
372
373 m_worker_count--;
374 m_active_worker_count--;
375 lockedThis->m_worker_idle_or_terminated_event.notify_all();
376
377 if(m_terminate_all_workers)
378 {
379 lockedThis->m_terminated_workers.push_back(worker);
380 }
381 else
382 {
383 lockedThis->m_size_policy->worker_died_unexpectedly(m_worker_count);
384 }
385 }
boost::threadpool::detail::pool_core::m_worker_count
volatile size_t m_worker_count
Definition: pool_core.hpp:117
boost::threadpool::detail::pool_core::m_monitor
recursive_mutex m_monitor
Definition: pool_core.hpp:131
boost::threadpool::detail::pool_core::m_active_worker_count
volatile size_t m_active_worker_count
Definition: pool_core.hpp:119
boost::threadpool::detail::pool_core::m_terminate_all_workers
bool m_terminate_all_workers
Definition: pool_core.hpp:127

## Friends And Related Function Documentation

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

friend class ShutdownPolicy< pool_type >
| friend

Definition at line 113 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

friend class SizePolicy< pool_type >
| friend

Definition at line 112 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

friend class worker_thread< pool_type >
| friend

Definition at line 106 of file pool_core.hpp.

## Member Data Documentation

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

volatile size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_active_worker_count
| private

Definition at line 119 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

recursive_mutex boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_monitor
| mutable private

Definition at line 131 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

scheduler_type boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_scheduler
| private

Definition at line 124 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

scoped_ptr<size_policy_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_size_policy
| private

Definition at line 125 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

volatile size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_target_worker_count
| private

Definition at line 118 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

condition boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_task_or_terminate_workers_event
| mutable private

Definition at line 133 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_terminate_all_workers
| private

Definition at line 127 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

std::vector<shared_ptr<worker_type> > boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_terminated_workers
| private

Definition at line 128 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

volatile size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_worker_count
| private

Definition at line 117 of file pool_core.hpp.

template<typename Task , template< typename > class SchedulingPolicy, template< typename > class SizePolicy, template< typename > class SizePolicyController, template< typename > class ShutdownPolicy>

condition boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_worker_idle_or_terminated_event
| mutable private

Definition at line 132 of file pool_core.hpp.

The documentation for this class was generated from the following file:

- GaudiMTTools/src/threadpool/boost/threadpool/detail/pool_core.hpp