libqi-api  2.0.6.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions
qi::ThreadPool Class Reference

Pool of workers. More...

#include <threadpool.hpp>

List of all members.

Public Member Functions

 ThreadPool (unsigned int minWorkers=2, unsigned int maxWorkers=100, unsigned int minIdleWorkers=1, unsigned int maxIdleWorkers=0)
 ThreadPool constructor.
 ~ThreadPool ()
 ThreadPool destructor.
unsigned int size () const
 Returns the number of workers in the pool.
unsigned int active () const
 Returns the number of active workers in the pool.
void setMaxWorkers (unsigned int n)
 Resizes the pool.
unsigned int getMaxWorkers () const
 Sets minimum number of workers in the pool.
void setMinWorkers (unsigned int n)
 Sets max idle workers.
unsigned int getMinWorkers () const
 Sets min idle workers.
void setMinIdleWorkers (unsigned int n)
 Returns maximum number of workers in the pool.
unsigned int getMinIdleWorkers () const
 Returns minimum number of workers in the pool.
void setMaxIdleWorkers (unsigned int n)
 Returns maximum number of inactive workers in the pool.
unsigned int getMaxIdleWorkers () const
 Returns minimum number of inactive workers in the pool.
void stop ()
 Stop the threadpool, no more will be accepted.
void reset ()
 Put the threadpool back in a state where it accept request.
void waitForAll ()
 Sleeps until all tasks are completed.
bool schedule (const boost::function< void(void)> &f)
 Adds a task to the pool.

Detailed Description

Pool of workers.

Definition at line 20 of file threadpool.hpp.


Constructor & Destructor Documentation

qi::ThreadPool::ThreadPool ( unsigned int  minWorkers = 2,
unsigned int  maxWorkers = 100,
unsigned int  minIdleWorkers = 1,
unsigned int  maxIdleWorkers = 0 
)

ThreadPool constructor.

Parameters:
minWorkersMinimum number of workers in the pool at any time
maxWorkersMaximum number of workers allowed in the pool
minIdleWorkersMinimum number of inactive workers and ready to execute a task immediately
maxIdleWorkersMaximum number of workers inactive

If maxIdleWorkers is 0, then no thread reclamation is done.

ThreadPool destructor.

 * The destructor will quit all threads and return. All tasks left in the queue
 * are dropped. To be sure that all tasks are completed, use
 * :cpp:func:`qi::ThreadPool::waitForAll()`
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::size() const`, :cpp:func:`qi::ThreadPool::waitForAll()`
 * 

Member Function Documentation

unsigned int qi::ThreadPool::active ( ) const

Returns the number of active workers in the pool.

Returns:
Number of active workers.

Returns minimum number of inactive workers in the pool.

Returns:
Maximum mumber of inactive workers.
 * Return the maximum number of inactive workers.
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMaxIdleWorkers(unsigned int)`
 * 

Sets minimum number of workers in the pool.

Returns:
Maximum number of workers.
 * Return the maximum number of workers.
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMaxWorkers(unsigned int)`
 * 

Returns minimum number of workers in the pool.

Returns:
Minimum number of inactive workers.
 * Return the minimum number of inactive workers.
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMinIdleWorkers(unsigned int)`
 * 

Sets min idle workers.

Returns:
Minimum number of workers.
 * Return the minimum number of workers.
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMinWorkers(unsigned int)`
 * 

Put the threadpool back in a state where it accept request.

qi::ThreadPool::schedule ( const boost::function< void(void)> &  f)

Adds a task to the pool.

Parameters:
fBoost function with type void(void) that represents the task.
Returns:
True if the task has been added to the tasks queue.

Adds a task to the pool. The task will begin immediately if there is at least one idling worker. Otherwise the tasks will be executed as soon as all tasks scheduled before have begun and a worker is idling.

qi::ThreadPool::setMaxIdleWorkers ( unsigned int  n)

Returns maximum number of inactive workers in the pool.

Parameters:
nNew number of max idle workers in the pool.
 * This function will change the maximum number of workers inactive in the pool.
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMinIdleWorkers(unsigned int)`, :cpp:func:`qi::ThreadPool::getMaxIdleWorkers() const`
 * 
qi::ThreadPool::setMaxWorkers ( unsigned int  n)

Resizes the pool.

Parameters:
nNew number of max workers in the pool
 * This function will set the new maximum number of workers in the pool. It is
 * impossible to set the maximum workers value to a lower value than the minimum
 * one (value is discarded).
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMinWorkers(unsigned int)`, :cpp:func:`qi::ThreadPool::getMaxWorkers() const`
 * 
qi::ThreadPool::setMinIdleWorkers ( unsigned int  n)

Returns maximum number of workers in the pool.

Parameters:
nNew number of min idle workers in the pool.
 * This function will change the minIdleWorkers number. It will spwan new
 * workers if necessary and ensure that at any time, n workers are ready to
 * handle new tasks.
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMaxIdleWorkers(unsigned int)`, :cpp:func:`qi::ThreadPool::getMinIdleWorkers() const`
 * 
qi::ThreadPool::setMinWorkers ( unsigned int  n)

Sets max idle workers.

Parameters:
nNew number of min workers in the pool
 * This function will set the new minimum number of workers in the pool. It will
 * spwan new workers if minWorkers is increased. It is impossible to set the
 * minimum workers value to a greater value than maximum workers (value is
 * discarded).
 *
 * .. seealso::
 *     :cpp:func:`qi::ThreadPool::setMaxWorkers(unsigned int)`, :cpp:func:`qi::ThreadPool::getMinWorkers() const`
 * 

Returns the number of workers in the pool.

Returns:
Number of workers.

Stop the threadpool, no more will be accepted.

Sleeps until all tasks are completed.

If all workers are inactive and there is no task left, returns immediately. Otherwise sleeps until all tasks in the pool are completed.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines