Skyld AV
0.6
On access virus scanning for Linux
|
Implements the thread pool pattern. More...
#include <ThreadPool.h>
Public Types | |
enum | status { RUNNING, STOPPING } |
Public Member Functions | |
ThreadPool (int nThreads, void *(*workRoutine)(void *)) | |
Creates a new thread pool. More... | |
void | add (void *workItem) |
Adds a work item to the work list. More... | |
void * | getWorkItem () |
Gets a work item. More... | |
long | getWorklistSize () |
Gets size of worklist. More... | |
virtual | ~ThreadPool () |
Deletes thread pool. More... | |
Private Member Functions | |
int | createThread () |
Creates a new worker thread. More... | |
void | exitThread (void *retval) |
Exits a worker thread. More... | |
int | isStopping () |
Is thread pool stopping. More... | |
Static Private Member Functions | |
static void * | worker (void *) |
Working thread. More... | |
Private Attributes | |
enum status | status |
pthread_cond_t | cond |
pthread_mutex_t | mutexThread |
pthread_mutex_t | mutexWorker |
pthread_mutex_t | mutexWorkItem |
int | thread_count |
std::deque< void * > | worklist |
void *(* | workRoutine )(void *) |
Implements the thread pool pattern.
A number of threads is created to perform tasks. Tasks are stored in a queue. When a thread becomes available it completes a new task from the queue.
Definition at line 35 of file ThreadPool.h.
enum ThreadPool::status |
Enumerator | |
---|---|
RUNNING | |
STOPPING |
Definition at line 37 of file ThreadPool.h.
ThreadPool::ThreadPool | ( | int | nThreads, |
void *(*)(void *) | workRoutine | ||
) |
Creates a new thread pool.
nThreads | number of threads to be created |
workRoutine | routine that handles the individual units of work |
Definition at line 33 of file ThreadPool.cc.
|
virtual |
Deletes thread pool.
Definition at line 172 of file ThreadPool.cc.
void ThreadPool::add | ( | void * | workItem | ) |
Adds a work item to the work list.
workItem | work item |
Definition at line 55 of file ThreadPool.cc.
|
private |
Creates a new worker thread.
Definition at line 67 of file ThreadPool.cc.
|
private |
Exits a worker thread.
retval | return value |
Definition at line 87 of file ThreadPool.cc.
void * ThreadPool::getWorkItem | ( | ) |
Gets a work item.
Definition at line 100 of file ThreadPool.cc.
long ThreadPool::getWorklistSize | ( | ) |
Gets size of worklist.
Definition at line 119 of file ThreadPool.cc.
|
private |
Is thread pool stopping.
Definition at line 134 of file ThreadPool.cc.
|
staticprivate |
Working thread.
threadPool | thread pool |
Definition at line 144 of file ThreadPool.cc.
|
private |
Definition at line 52 of file ThreadPool.h.
|
private |
Definition at line 54 of file ThreadPool.h.
|
private |
Definition at line 55 of file ThreadPool.h.
|
private |
Definition at line 56 of file ThreadPool.h.
|
private |
Definition at line 48 of file ThreadPool.h.
|
private |
Definition at line 57 of file ThreadPool.h.
|
private |
Definition at line 58 of file ThreadPool.h.
|
private |
Definition at line 59 of file ThreadPool.h.