Skyld AV  0.6
On access virus scanning for Linux
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ThreadPool Class Reference

Implements the thread pool pattern. More...

#include <ThreadPool.h>

Collaboration diagram for ThreadPool:
Collaboration graph

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 *)
 

Detailed Description

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.

Member Enumeration Documentation

Enumerator
RUNNING 
STOPPING 

Definition at line 37 of file ThreadPool.h.

Constructor & Destructor Documentation

ThreadPool::ThreadPool ( int  nThreads,
void *(*)(void *)  workRoutine 
)

Creates a new thread pool.

Parameters
nThreadsnumber of threads to be created
workRoutineroutine that handles the individual units of work

Definition at line 33 of file ThreadPool.cc.

Here is the call graph for this function:

ThreadPool::~ThreadPool ( )
virtual

Deletes thread pool.

Definition at line 172 of file ThreadPool.cc.

Member Function Documentation

void ThreadPool::add ( void *  workItem)

Adds a work item to the work list.

Parameters
workItemwork item

Definition at line 55 of file ThreadPool.cc.

Here is the caller graph for this function:

int ThreadPool::createThread ( )
private

Creates a new worker thread.

Returns
success = 0

Definition at line 67 of file ThreadPool.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void ThreadPool::exitThread ( void *  retval)
private

Exits a worker thread.

Parameters
retvalreturn value

Definition at line 87 of file ThreadPool.cc.

Here is the caller graph for this function:

void * ThreadPool::getWorkItem ( )

Gets a work item.

Returns
work item or NULL

Definition at line 100 of file ThreadPool.cc.

Here is the caller graph for this function:

long ThreadPool::getWorklistSize ( )

Gets size of worklist.

Returns
size of worklist, -1 signals error

Definition at line 119 of file ThreadPool.cc.

int ThreadPool::isStopping ( )
private

Is thread pool stopping.

Returns
thread pool is stopping

Definition at line 134 of file ThreadPool.cc.

Here is the caller graph for this function:

void * ThreadPool::worker ( void *  threadPool)
staticprivate

Working thread.

Parameters
threadPoolthread pool
Returns
return value

Definition at line 144 of file ThreadPool.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

pthread_cond_t ThreadPool::cond
private

Definition at line 52 of file ThreadPool.h.

pthread_mutex_t ThreadPool::mutexThread
private

Definition at line 54 of file ThreadPool.h.

pthread_mutex_t ThreadPool::mutexWorker
private

Definition at line 55 of file ThreadPool.h.

pthread_mutex_t ThreadPool::mutexWorkItem
private

Definition at line 56 of file ThreadPool.h.

enum status ThreadPool::status
private

Definition at line 48 of file ThreadPool.h.

int ThreadPool::thread_count
private

Definition at line 57 of file ThreadPool.h.

std::deque<void *> ThreadPool::worklist
private

Definition at line 58 of file ThreadPool.h.

void*(* ThreadPool::workRoutine)(void *)
private

Definition at line 59 of file ThreadPool.h.


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