Fennel: ThreadPool< Task > Class Template Reference (original) (raw)
ThreadPool is a very simple thread-pooling implementation. More...
#include <[ThreadPool.h](ThreadPool%5F8h-source.html)>
Inheritance diagram for ThreadPool< Task >:

| Public Member Functions | |
|---|---|
| ThreadPool () | |
| Constructor. | |
| virtual | ~ThreadPool () |
| Destructor: stop must already have been called. | |
| void | submitTask (Task &task) |
| Submits a task to the pool. | |
| void | start (uint nThreads) |
| Starts the given number of threads in the pool. | |
| void | stop () |
| Shuts down the pool, waiting for any pending tasks to complete. | |
| void | setThreadTracker (ThreadTracker &threadTracker) |
| Sets a tracker to use for created threads. | |
| Protected Types | |
| enum | State { STATE_STARTED, STATE_STOPPING, STATE_STOPPED } |
| Protected Attributes | |
| std::vector< PooledThread * > | threads |
| State | state |
| LocalCondition | stoppingCondition |
| ThreadTracker * | pThreadTracker |
| StrictMutex | mutex |
| LocalCondition | condition |
| Private Member Functions | |
| virtual bool | isQueueEmpty () |
| virtual void | runOneTask (StrictMutexGuard &guard) |
| Private Attributes | |
| std::deque< Task > | queue |
Detailed Description
template
class ThreadPool< Task >
ThreadPool is a very simple thread-pooling implementation.
It's a template to avoid requiring task queue entries to be dynamically allocated.
The Task template parameter must behave as a concrete data type, and must have a method execute().
Definition at line 95 of file ThreadPool.h.
Member Enumeration Documentation
Enumerator:
| STATE_STARTED | | | ----------------- | | | STATE_STOPPING | | | STATE_STOPPED | |
Definition at line 46 of file ThreadPool.h.
Constructor & Destructor Documentation
Destructor: stop must already have been called.
Definition at line 125 of file ThreadPool.h.
Member Function Documentation
template
| virtual bool ThreadPool< Task >::isQueueEmpty | ( | | ) | [inline, private, virtual] | | --------------------------------------------------------------------- | - | | - | ---------------------------- |
Implements ThreadPoolBase.
Definition at line 104 of file ThreadPool.h.
00105 { 00106 Task task = queue.front(); 00107 queue.pop_front(); 00108 guard.unlock(); 00109 task.execute(); 00110 guard.lock(); 00111 }
template
| void ThreadPool< Task >::submitTask | ( | Task & | task | ) | [inline] |
|---|
| void ThreadPoolBase::start | ( | uint | nThreads | ) | [inherited] |
|---|
| void ThreadPoolBase::stop | ( | | ) | [inherited] | | ------------------------- | - | | - | ------------- |
Shuts down the pool, waiting for any pending tasks to complete.
The start/stop calls should never be invoked from more than one thread simultaneously.
Definition at line 73 of file ThreadPool.cpp.
References SynchMonitoredObject::condition, deleteAndNullify(), ThreadPoolBase::isQueueEmpty(), SynchMonitoredObject::mutex, ThreadPoolBase::state, ThreadPoolBase::STATE_STOPPED, ThreadPoolBase::STATE_STOPPING, ThreadPoolBase::stoppingCondition, and ThreadPoolBase::threads.
Referenced by ExternalSortExecStreamImpl::computeFirstResultParallel(), ThreadedTestBase::runThreadedTestCase(), ParallelExecStreamScheduler::stop(), and ThreadPoolScheduler::stop().
| void ThreadPoolBase::setThreadTracker | ( | ThreadTracker & | threadTracker | ) | [inherited] |
|---|
Member Data Documentation
Definition at line 38 of file SynchMonitoredObject.h.
Referenced by ParallelExecStreamScheduler::abort(), LogicalTxnLog::checkpoint(), Database::checkpointImpl(), CheckpointThread::closeImpl(), LogicalTxnLog::commitTxn(), ParallelExecStreamScheduler::executeManager(), ParallelExecStreamScheduler::executeTask(), LogicalTxnLog::getOldestActiveTxnId(), LogicalTxnLog::newLogicalTxn(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), GroupLock::release(), Database::requestCheckpoint(), CheckpointThread::requestCheckpoint(), LogicalTxnLog::rollbackTxn(), TimerThread::run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), SXMutex::setSchedulingPolicy(), TimerThread::signalImmediate(), ParallelExecStreamScheduler::signalSentinel(), ThreadPoolBase::start(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::tryUpgrade(), SXMutex::waitFor(), GroupLock::waitFor(), and Database::writeStats().
Definition at line 39 of file SynchMonitoredObject.h.
Referenced by ParallelExecStreamScheduler::abort(), Database::checkpointImpl(), CheckpointThread::closeImpl(), LogicalTxnLog::commitTxnWithGroup(), ParallelExecStreamScheduler::executeTask(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), GroupLock::release(), Database::requestCheckpoint(), CheckpointThread::requestCheckpoint(), TimerThread::run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), TimerThread::signalImmediate(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::waitFor(), and GroupLock::waitFor().
The documentation for this class was generated from the following file:
- /home/pub/open/dev/fennel/synch/ThreadPool.h
