CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

container::CThreadPool Class Reference

#include <cthreadpool.h>

Collaboration diagram for container::CThreadPool:

List of all members.


Classes

class  Task
class  Thread

Public Member Functions

 CThreadPool (int numThreads, int queueLen)
 lock for m_threads
 ~CThreadPool ()
void queue (Task *t)
void stop ()

Protected Member Functions

TaskgetTask ()
void threadDone (CThreadPool::Thread *thread)

Private Types

typedef std::list< Thread * > threadlist_t
typedef std::list< Task * > tasklist_t

Private Attributes

threadlist_t m_threads
tasklist_t m_queue
int m_maxQueueLen
int m_curQueueLen
bool m_running
sptk::CWaiter m_queueLock
sptk::CWaiter m_tlLock

Detailed Description

Implemets a thread pool that manages number of threads of given type Well... Actually this is more of a queue. Perhaps when I move it to SPTK, I'll rename it.
Author:
Ilya A. Volynets-Evenbakh

Definition at line 35 of file cthreadpool.h.


Member Typedef Documentation

typedef std::list<Task*> container::CThreadPool::tasklist_t [private]

Definition at line 60 of file cthreadpool.h.

typedef std::list<Thread*> container::CThreadPool::threadlist_t [private]

Definition at line 59 of file cthreadpool.h.


Constructor & Destructor Documentation

container::CThreadPool::CThreadPool ( int  numThreads,
int  queueLen 
)

lock for m_threads

Definition at line 26 of file cthreadpool.cpp.

References m_threads, and m_tlLock.

container::CThreadPool::~CThreadPool (  ) 

Todo:
make number of threads run-time adjustable?

Definition at line 40 of file cthreadpool.cpp.

References stop().

Here is the call graph for this function:


Member Function Documentation

CThreadPool::Task * container::CThreadPool::getTask (  )  [protected]

Called by PooledThread to retrieve next task to process. Blocks if no tasks are available

Definition at line 60 of file cthreadpool.cpp.

References m_curQueueLen, m_queue, m_queueLock, and m_running.

Referenced by container::CThreadPool::CThreadPool::Thread::threadFunction().

void container::CThreadPool::queue ( CThreadPool::Task t  ) 

Adds task t to the queue. It can block waiting for some other task to Complete, if maxQueueLength is exceeded.

Definition at line 46 of file cthreadpool.cpp.

References m_curQueueLen, m_maxQueueLen, m_queue, and m_queueLock.

Referenced by container::AcceptConnection::operator()().

void container::CThreadPool::stop (  ) 

Once this function is called, threads will start receiving NULL tasks and will exit.

Definition at line 116 of file cthreadpool.cpp.

References m_queueLock, m_running, m_threads, and m_tlLock.

Referenced by ~CThreadPool().

void container::CThreadPool::threadDone ( CThreadPool::Thread thread  )  [protected]

Definition at line 132 of file cthreadpool.cpp.

References m_threads, and m_tlLock.

Referenced by container::CThreadPool::CThreadPool::Thread::onThreadExit().


Member Data Documentation

Definition at line 65 of file cthreadpool.h.

Referenced by getTask(), and queue().

Definition at line 64 of file cthreadpool.h.

Referenced by queue().

Definition at line 63 of file cthreadpool.h.

Referenced by getTask(), and queue().

sptk::CWaiter container::CThreadPool::m_queueLock [private]

Definition at line 67 of file cthreadpool.h.

Referenced by getTask(), queue(), and stop().

Definition at line 62 of file cthreadpool.h.

Referenced by CThreadPool(), stop(), and threadDone().

sptk::CWaiter container::CThreadPool::m_tlLock [private]

Definition at line 68 of file cthreadpool.h.

Referenced by CThreadPool(), stop(), and threadDone().


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

SourceForge.net Logo