Thread Class Reference

Thread is a wrapper around boost::thread which allows for the thread object to be created before it is actually started. More...

#include <Thread.h>

Inheritance diagram for Thread:

AioLinuxScheduler AioPollingScheduler AioSignalHandlerThread CheckpointThread IoCompletionPortThread PooledThread ResourceThread TestThread TimerThread List of all members.

Public Member Functions

 Thread (std::string const &description="anonymous thread")
virtual ~Thread ()
virtual void start ()
 Spawns the OS thread.
void join ()
 Waits for the OS thread to terminate.
bool isStarted () const
 
Returns:
true if start has been called (and subsequent join has not completed)

bool isStopped () const
 
Returns:
opposite of isStarted()

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 run ()=0
virtual void beforeRun ()
virtual void afterRun ()

Protected Attributes

boost::thread * pBoostThread
bool bRunning
std::string name

Detailed Description

Thread is a wrapper around boost::thread which allows for the thread object to be created before it is actually started.

Definition at line 41 of file Thread.h.


Constructor & Destructor Documentation

Thread::Thread ( std::string const &  description = "anonymous thread"  )  [explicit]

Definition at line 36 of file Thread.cpp.

References bRunning, name, and pBoostThread.

00037 {
00038     // TODO:  do something with description
00039     name = desc;
00040     pBoostThread = NULL;
00041     bRunning = false;
00042 }

Thread::~Thread (  )  [virtual]

Definition at line 44 of file Thread.cpp.

References bRunning, and pBoostThread.

00045 {
00046     assert(!bRunning);
00047     assert(!pBoostThread);
00048 }


Member Function Documentation

void Thread::initAndRun (  )  [protected]

Definition at line 66 of file Thread.cpp.

References afterRun(), beforeRun(), and run().

Referenced by start().

00067 {
00068     beforeRun();
00069     run();
00070     afterRun();
00071 }

virtual void Thread::run (  )  [protected, pure virtual]

Implemented in CheckpointThread, AioLinuxScheduler, AioPollingScheduler, AioSignalHandlerThread, IoCompletionPortThread, PooledThread, TimerThread, TestThread, and ResourceThread.

Referenced by initAndRun().

void Thread::beforeRun (  )  [protected, virtual]

Definition at line 73 of file Thread.cpp.

References bRunning.

Referenced by initAndRun().

00074 {
00075     bRunning = true;
00076 }

void Thread::afterRun (  )  [protected, virtual]

Definition at line 78 of file Thread.cpp.

References bRunning.

Referenced by initAndRun().

00079 {
00080     bRunning = false;
00081 }

void Thread::start (  )  [virtual]

Spawns the OS thread.

Definition at line 50 of file Thread.cpp.

References initAndRun(), and 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 (  ) 

Waits for the OS thread to terminate.

Definition at line 56 of file Thread.cpp.

References pBoostThread.

Referenced by CheckpointThread::closeImpl(), TimerThread::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]

Returns:
true if start has been called (and subsequent join has not completed)

Reimplemented in AioLinuxScheduler.

Definition at line 71 of file Thread.h.

Referenced by CheckpointThread::closeImpl(), CacheImpl< PageT, VictimPolicyT >::closeImpl(), AioLinuxScheduler::isStarted(), and TimerThread::stop().

00072     {
00073         return pBoostThread ? true : false;
00074     }

bool Thread::isStopped (  )  const [inline]

Returns:
opposite of isStarted()

Definition at line 79 of file Thread.h.

00080     {
00081         return !isStarted();
00082     }

boost::thread& Thread::getBoostThread (  )  [inline]

Accesses the underlying boost::thread, e.g.

for use in a boost::thread_group. This thread must already be started.

Returns:
the underlying boost::thread

Definition at line 90 of file Thread.h.

00091     {
00092         assert(isStarted());
00093         return *pBoostThread;
00094     }

std::string Thread::getName (  )  [inline]

Definition at line 96 of file Thread.h.

00097     {
00098         return name;
00099     }

void Thread::setName ( std::string const &  s  )  [inline]

Definition at line 101 of file Thread.h.

00102     {
00103         name = s;
00104     }


Member Data Documentation

boost::thread* Thread::pBoostThread [protected]

Definition at line 44 of file Thread.h.

Referenced by join(), start(), Thread(), and ~Thread().

bool Thread::bRunning [protected]

Definition at line 45 of file Thread.h.

Referenced by afterRun(), beforeRun(), Thread(), and ~Thread().

std::string Thread::name [protected]

Definition at line 46 of file Thread.h.

Referenced by Thread().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:48 2009 for Fennel by  doxygen 1.5.1