Autowiring  1.0.3
A C++ Inversion of Control Framework
autowiring::ThreadPool Class Referenceabstract

Generic interface for a thread pool More...

#include <ThreadPool.h>

Inheritance diagram for autowiring::ThreadPool:
autowiring::SystemThreadPool

Public Member Functions

virtual void Consume (const std::shared_ptr< DispatchQueue > &dq)
 Causes the thread pool to call all lambdas specified on the passed DispatchQueue More...
 
bool IsStarted (void) const
 
Returns
True if the thread pool is running

 
template<class Fx >
bool operator+= (Fx &&fx)
 Submits the specified lambda to this context's ThreadPool for processing More...
 
virtual std::shared_ptr< void > Start (void)
 Begins processing on this thread pool More...
 
virtual bool Submit (std::unique_ptr< DispatchThunkBase > &&thunk)=0
 Adds the specified thunk to be executed by the thread pool at some later time More...
 

Protected Member Functions

virtual void OnStartUnsafe (void)
 Called when the thread pool is first started More...
 
virtual void OnStop (void)
 Called when the thread pool is being cleaned up More...
 

Detailed Description

Generic interface for a thread pool

Member Function Documentation

virtual void autowiring::ThreadPool::Consume ( const std::shared_ptr< DispatchQueue > &  dq)
virtual

Causes the thread pool to call all lambdas specified on the passed DispatchQueue

The dispatchers on the DispatchQueue are executed sequentially with respect to each other. Each dispatcher is guaranteed to be destroyed before the next one is executed. Dispatchers may potentially be executed on different threads, depending on the exact details of the ThreadPool's implementation. There is no guarantee of timeliness of execution provided by this implementation; the queue may be emptied before this function returns in some cases, or its state may not be changed at all. The DispatchQueue may be aborted while the pool has posession of it; this will cause the ThreadPool to abandon processing of the queue in the normal way.

Once the pool has emptied the queue, it stops processing dispatchers from it. The user must call Consume again in order to continue processing.

This method is guaranteed not to block. The default implementation captures the passed queue in a lambda and invokes Submit with this constructed lambda.

virtual void autowiring::ThreadPool::OnStartUnsafe ( void  )
inlineprotectedvirtual

Called when the thread pool is first started

This method is called at most once

virtual void autowiring::ThreadPool::OnStop ( void  )
inlineprotectedvirtual

Called when the thread pool is being cleaned up

Where possible, this method should return immediately.

template<class Fx >
bool autowiring::ThreadPool::operator+= ( Fx &&  fx)
inline

Submits the specified lambda to this context's ThreadPool for processing

Returns
True if the job has been submitted for execution

The passed thunk will not be executed if the current context has already stopped.

virtual std::shared_ptr<void> autowiring::ThreadPool::Start ( void  )
virtual

Begins processing on this thread pool

Returns
A token that must be held in scope while the thread pool should be started

This method is idempotent. Unlike CoreThread instances, a thread pool may be restarted. The returned shared pointer must be held for as long as the thread pool should be kept running. If the returned token is destroyed, the thread pool will be stopped automatically. Termination of work items in the thread pool may occur at a later time on certain platforms; in some cases, a call to Start may result in the creation of a new thread pool before the previous thread pool is completely torn down.

virtual bool autowiring::ThreadPool::Submit ( std::unique_ptr< DispatchThunkBase > &&  thunk)
pure virtual

Adds the specified thunk to be executed by the thread pool at some later time

Returns
True if the job was successfully accepted, false otherwise

This method may be called even if the thread pool is not currently running. In that case, the job will be enqueued until the thread pool is started, at which time it will be submitted for execution.

Referenced by operator+=().


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