#include <TimerThread.h>
Inheritance diagram for TimerThread:
Public Member Functions | |
TimerThread (TimerThreadClient &clientInit) | |
void | stop () |
Stops (and joins) the timer thread. | |
void | signalImmediate () |
Requests an immediate execution of onTimerInterval() in the timer thread context. | |
virtual void | start () |
Spawns the OS thread. | |
void | join () |
Waits for the OS thread to terminate. | |
bool | isStarted () const |
| |
bool | isStopped () const |
| |
boost::thread & | getBoostThread () |
Accesses the underlying boost::thread, e.g. | |
std::string | getName () |
void | setName (std::string const &s) |
Protected Member Functions | |
void | initAndRun () |
virtual void | beforeRun () |
virtual void | afterRun () |
Protected Attributes | |
boost::thread * | pBoostThread |
bool | bRunning |
std::string | name |
Private Member Functions | |
virtual void | run () |
Private Attributes | |
TimerThreadClient & | client |
bool | bStop |
StrictMutex | mutex |
LocalCondition | condition |
Once started, the thread runs until stop() is called.
Definition at line 58 of file TimerThread.h.
TimerThread::TimerThread | ( | TimerThreadClient & | clientInit | ) | [explicit] |
void TimerThread::run | ( | ) | [private, virtual] |
Implements Thread.
Definition at line 37 of file TimerThread.cpp.
References bStop, client, SynchMonitoredObject::condition, convertTimeout(), TimerThreadClient::getTimerIntervalMillis(), SynchMonitoredObject::mutex, ThreadTracker::onThreadEnd(), ThreadTracker::onThreadStart(), and TimerThreadClient::onTimerInterval().
00038 { 00039 // TODO jvs 13-Oct-2006: resource acquisition as initialization 00040 client.onThreadStart(); 00041 try { 00042 for (;;) { 00043 uint millis = client.getTimerIntervalMillis(); 00044 if (!millis) { 00045 break; 00046 } 00047 boost::xtime atv; 00048 convertTimeout(millis,atv); 00049 StrictMutexGuard mutexGuard(mutex); 00050 while (!bStop) { 00051 if (!condition.timed_wait(mutexGuard,atv)) { 00052 break; 00053 } 00054 } 00055 if (bStop) { 00056 break; 00057 } 00058 client.onTimerInterval(); 00059 } 00060 } catch (...) { 00061 client.onThreadEnd(); 00062 throw; 00063 } 00064 client.onThreadEnd(); 00065 }
void TimerThread::stop | ( | ) |
Stops (and joins) the timer thread.
Definition at line 67 of file TimerThread.cpp.
References bStop, SynchMonitoredObject::condition, Thread::isStarted(), Thread::join(), and SynchMonitoredObject::mutex.
Referenced by CacheImpl< PageT, VictimPolicyT >::closeImpl(), and StatsTimer::stop().
00068 { 00069 StrictMutexGuard mutexGuard(mutex); 00070 if (bStop || !isStarted()) { 00071 return; 00072 } 00073 bStop = true; 00074 condition.notify_all(); 00075 mutexGuard.unlock(); 00076 join(); 00077 mutexGuard.lock(); 00078 bStop = false; 00079 }
void TimerThread::signalImmediate | ( | ) |
Requests an immediate execution of onTimerInterval() in the timer thread context.
Afterwards, timed execution resumes as usual.
Definition at line 81 of file TimerThread.cpp.
References SynchMonitoredObject::condition, and SynchMonitoredObject::mutex.
00082 { 00083 StrictMutexGuard mutexGuard(mutex); 00084 condition.notify_all(); 00085 }
void Thread::initAndRun | ( | ) | [protected, inherited] |
Definition at line 66 of file Thread.cpp.
References Thread::afterRun(), Thread::beforeRun(), and Thread::run().
Referenced by Thread::start().
void Thread::beforeRun | ( | ) | [protected, virtual, inherited] |
Definition at line 73 of file Thread.cpp.
References Thread::bRunning.
Referenced by Thread::initAndRun().
00074 { 00075 bRunning = true; 00076 }
void Thread::afterRun | ( | ) | [protected, virtual, inherited] |
Definition at line 78 of file Thread.cpp.
References Thread::bRunning.
Referenced by Thread::initAndRun().
00079 { 00080 bRunning = false; 00081 }
void Thread::start | ( | ) | [virtual, inherited] |
Spawns the OS thread.
Definition at line 50 of file Thread.cpp.
References Thread::initAndRun(), and Thread::pBoostThread.
Referenced by AioLinuxScheduler::AioLinuxScheduler(), AioPollingScheduler::AioPollingScheduler(), StatsTimer::start(), ResourceTest::testConcurrency(), and LocalConditionTest::testNotifyAll().
00051 { 00052 pBoostThread = new boost::thread( 00053 boost::bind(&Thread::initAndRun,this)); 00054 }
void Thread::join | ( | ) | [inherited] |
Waits for the OS thread to terminate.
Definition at line 56 of file Thread.cpp.
References Thread::pBoostThread.
Referenced by CheckpointThread::closeImpl(), stop(), AioPollingScheduler::stop(), AioLinuxScheduler::stop(), ResourceTest::testConcurrency(), and LocalConditionTest::testNotifyAll().
00057 { 00058 assert(pBoostThread); 00059 boost::thread t; 00060 assert(*pBoostThread != t); 00061 pBoostThread->join(); 00062 delete pBoostThread; 00063 pBoostThread = NULL; 00064 }
bool Thread::isStarted | ( | ) | const [inline, inherited] |
Reimplemented in AioLinuxScheduler.
Definition at line 71 of file Thread.h.
Referenced by CheckpointThread::closeImpl(), CacheImpl< PageT, VictimPolicyT >::closeImpl(), AioLinuxScheduler::isStarted(), and stop().
00072 { 00073 return pBoostThread ? true : false; 00074 }
bool Thread::isStopped | ( | ) | const [inline, inherited] |
Definition at line 79 of file Thread.h.
00080 { 00081 return !isStarted(); 00082 }
boost::thread& Thread::getBoostThread | ( | ) | [inline, inherited] |
Accesses the underlying boost::thread, e.g.
for use in a boost::thread_group. This thread must already be started.
Definition at line 90 of file Thread.h.
00091 { 00092 assert(isStarted()); 00093 return *pBoostThread; 00094 }
std::string Thread::getName | ( | ) | [inline, inherited] |
void Thread::setName | ( | std::string const & | s | ) | [inline, inherited] |
TimerThreadClient& TimerThread::client [private] |
bool TimerThread::bStop [private] |
boost::thread* Thread::pBoostThread [protected, inherited] |
Definition at line 44 of file Thread.h.
Referenced by Thread::join(), Thread::start(), Thread::Thread(), and Thread::~Thread().
bool Thread::bRunning [protected, inherited] |
Definition at line 45 of file Thread.h.
Referenced by Thread::afterRun(), Thread::beforeRun(), Thread::Thread(), and Thread::~Thread().
std::string Thread::name [protected, inherited] |
StrictMutex SynchMonitoredObject::mutex [protected, inherited] |
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(), run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), SXMutex::setSchedulingPolicy(), signalImmediate(), ParallelExecStreamScheduler::signalSentinel(), ThreadPoolBase::start(), stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::tryUpgrade(), SXMutex::waitFor(), GroupLock::waitFor(), and Database::writeStats().
LocalCondition SynchMonitoredObject::condition [protected, inherited] |
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(), run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), signalImmediate(), stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::waitFor(), and GroupLock::waitFor().