MetriVis | Overview | Download | User Manual | Development |
Reference | Overview | Design Documentation | Reference Backend | Reference Frontend |
Public Member Functions | |
ThreadPool (int number_of_threads) | |
Constructor initializes a thread pool of a given size. | |
~ThreadPool () | |
Deconstructor. | |
void | PushRequest (const RequestDescription &request_description) |
Schedules a HTTP request to be handeled in this pipeline. | |
void | ScheduleRequestsManually () |
Forces the ThreadPool to schedule pending requests manually. | |
void | Terminate () |
Removes all pending requests and waits until all jobs finished. | |
Protected Member Functions | |
const RequestDescription & | PopRequest () const |
Gets the next RequestDescription for execution. | |
Private Member Functions | |
void | ScheduleRequests () |
Schedules pending requests into the FIFO worker queue. | |
void | ProcessRequest () |
Processes a request. | |
Private Attributes | |
boost::threadpool::pool | pool_ |
Internal thread pool. | |
std::queue < RequestDescription > | request_desriptions_ |
requests. | |
boost::mutex | dispatcher_mutex_ |
Mutex for locking dispatcher_. | |
std::stack< S * > | dispatchers_ |
Stack of dispatcher for each thread. | |
bool | post_mortem_ |
Indicates if the pool is terminated. |
In the thread pool pattern in programming, a number of N threads are created to perform a number of M tasks, usually organized in a queue. Typically, N << M. As soon as a thread completes its task, it will request the next task from the queue until all tasks have been completed. The thread can then terminate, or sleep until there are new tasks available. (snippet from Wikipedia, the free encyclopedia).
This class is not recyclable. Once it is deleted it wont be able to resurrect. After ThreadPool::Terminate is called the object can't be used anymore.
metrivis::RequestHandler< T, ID >::ThreadPool< S >::ThreadPool | ( | int | number_of_threads | ) | [inline] |
Constructor initializes a thread pool of a given size.
number_of_threads,: | The number of threads to be contained. |
metrivis::RequestHandler< T, ID >::ThreadPool< S >::~ThreadPool | ( | ) | [inline] |
Deconstructor.
The ThreadPool should be stopped first with ThreadPool::Terminate function.
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::PushRequest | ( | const RequestDescription & | request_description | ) | [inline] |
Schedules a HTTP request to be handeled in this pipeline.
request_description,: | The HTTP request description object. |
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::ScheduleRequestsManually | ( | ) | [inline] |
Forces the ThreadPool to schedule pending requests manually.
This will just injects all pending requests into the ThreadPool. The requests will be handedled as soon as there are free worker threads available. This shouldn't be needed to call since new requests are automatically scheduled.
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::Terminate | ( | ) | [inline] |
Removes all pending requests and waits until all jobs finished.
Blocks until all resources are freed again.
const RequestDescription& metrivis::RequestHandler< T, ID >::ThreadPool< S >::PopRequest | ( | ) | const [inline, protected] |
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::ScheduleRequests | ( | ) | [inline, private] |
Schedules pending requests into the FIFO worker queue.
Adds the request to the thread pool. Requests will be handeled in a FIFO way.
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::ProcessRequest | ( | ) | [inline, private] |
Processes a request.
This function is registered as the running function for all threads spawned in this thread pool.