vpr::BaseThread Class Reference

Base class for all thread implementations. More...

#include <vpr/Thread/BaseThread.h>

Inheritance diagram for vpr::BaseThread:

Inheritance graph
[legend]
Collaboration diagram for vpr::BaseThread:

Collaboration graph
[legend]
List of all members.

Public Types

enum  VPRThreadPriority { VPR_PRIORITY_LOW, VPR_PRIORITY_NORMAL, VPR_PRIORITY_HIGH, VPR_PRIORITY_URGENT }
enum  VPRThreadScope { VPR_LOCAL_THREAD, VPR_GLOBAL_THREAD }
enum  VPRThreadState { VPR_JOINABLE_THREAD, VPR_UNJOINABLE_THREAD }

Public Member Functions

 BaseThread ()
virtual ~BaseThread ()
virtual void setFunctor (BaseThreadFunctor *functorPtr)=0
 Sets the thread's functor--the code that will get executed.
virtual vpr::ReturnStatus start ()=0
 Starts the thread's execution.
TSTablegetTSTable ()
 Gets the Thread specific data table.
virtual int join (void **status=0)
 Causes the calling thread wait for the termination of this thread.
virtual int resume ()
 Resumes the execution of this thread (if it was previously suspended using suspend()).
virtual int suspend ()
 Suspends the execution of this thread.
virtual int getPrio (VPRThreadPriority *prio)
 Gets this thread's current priority.
virtual int setPrio (VPRThreadPriority prio)
 Sets this thread's priority.
vpr::Int32 getTID ()
 Gets the "thread ID" of this vpr::BaseThread object.
bool valid ()
 Is this a valid thread?
virtual int kill (int signum)
 Sends the specified signal to this thread (not necessarily SIGKILL).
virtual void kill ()
 Kills (cancels) this thread.
virtual std::ostream & outStream (std::ostream &out)
 Ouputs the state of the object.

Static Public Member Functions

static TSTablegetGlobalTSTable ()
 Get the Thread the global thread specific data table.

Protected Member Functions

void registerThread (bool successfulCreation)
 After the object has been created, call this routine to complete initialization.
void unregisterThread ()
void createThreadId ()
 Initializes the state of the object.

Protected Attributes

vpr::Int32 mThreadId

Detailed Description

Base class for all thread implementations.

Provides functionality that is common to all threading implementations.

Note:
This class is not designed to be used as a polymorphic base class to hold references to threads. Just use the real thread type.

Definition at line 73 of file BaseThread.h.


Member Enumeration Documentation

enum vpr::BaseThread::VPRThreadPriority

Enumerator:
VPR_PRIORITY_LOW  The lowest possible priority.
VPR_PRIORITY_NORMAL  The most common priority.
VPR_PRIORITY_HIGH  Slightly higher priority.
VPR_PRIORITY_URGENT  The highest priority.

Definition at line 76 of file BaseThread.h.

00077    {
00078       VPR_PRIORITY_LOW,      
00079       VPR_PRIORITY_NORMAL,   
00080       VPR_PRIORITY_HIGH,     
00081       VPR_PRIORITY_URGENT    
00082    };

enum vpr::BaseThread::VPRThreadScope

Enumerator:
VPR_LOCAL_THREAD 
VPR_GLOBAL_THREAD 

Definition at line 84 of file BaseThread.h.

00085    {
00086       VPR_LOCAL_THREAD,
00087       VPR_GLOBAL_THREAD
00088    };

enum vpr::BaseThread::VPRThreadState

Enumerator:
VPR_JOINABLE_THREAD  The thread can be reattached later.
VPR_UNJOINABLE_THREAD  The thread cannot be attached with join().

Definition at line 90 of file BaseThread.h.

00091    {
00092       VPR_JOINABLE_THREAD,   
00093       VPR_UNJOINABLE_THREAD  
00094    };


Constructor & Destructor Documentation

vpr::BaseThread::BaseThread (  )  [inline]

Definition at line 96 of file BaseThread.h.

00096                 : mThreadId(-1)
00097    {
00098       ;
00099    }

virtual vpr::BaseThread::~BaseThread (  )  [inline, virtual]

Definition at line 101 of file BaseThread.h.

00102    {
00103       ;
00104    }


Member Function Documentation

virtual void vpr::BaseThread::setFunctor ( BaseThreadFunctor functorPtr  )  [pure virtual]

Sets the thread's functor--the code that will get executed.

Implemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

virtual vpr::ReturnStatus vpr::BaseThread::start (  )  [pure virtual]

Starts the thread's execution.

Implemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

TSTable* vpr::BaseThread::getTSTable (  )  [inline]

Gets the Thread specific data table.

Note:
Users should NOT access the table directly instead, use vpr::TSObjectProxy objects.

Definition at line 119 of file BaseThread.h.

00120    {
00121       return &mTSTable;
00122    }

static TSTable* vpr::BaseThread::getGlobalTSTable (  )  [inline, static]

Get the Thread the global thread specific data table.

This table is shared by all threads that were not created by VPR.

Definition at line 128 of file BaseThread.h.

00129    {
00130       return &gTSTable;
00131    }

void vpr::BaseThread::registerThread ( bool  successfulCreation  )  [protected]

After the object has been created, call this routine to complete initialization.

It is done this way because I need to call this based on stuff that happens in derived class's constructor.

Precondition:
The Thread Manager should be lock()'ed before calling this function so that the addThread() function can execute correctly
Postcondition:
Thread is setup correctly to run. The thread has been registered with the system. Creates the thread's ID (mThreadId).
Parameters:
successfulCreation Did the thread get created correctly?

Definition at line 82 of file BaseThread.cpp.

References createThreadId(), mThreadId, and vprASSERT.

Referenced by vpr::ThreadSGI::start(), vpr::ThreadPosix::start(), vpr::ThreadNSPR::start(), and vpr::ThreadPosix::startThread().

00083 {
00084    if(succesfulCreation)   // Succeed
00085    {
00086       createThreadId();
00087       Thread* thread_ptr = dynamic_cast<Thread*>(this);
00088       vprASSERT(NULL != thread_ptr);
00089       ThreadManager::instance()->addThread(thread_ptr); // Add the thread to the table
00090    }
00091    else
00092    {
00093       mThreadId = -1;      // We have an invalid thread
00094    }
00095 }

void vpr::BaseThread::unregisterThread (  )  [protected]

Definition at line 97 of file BaseThread.cpp.

References vprASSERT.

Referenced by vpr::ThreadNSPR::~ThreadNSPR(), vpr::ThreadPosix::~ThreadPosix(), and vpr::ThreadSGI::~ThreadSGI().

00098 {
00099    vpr::Thread* thread_ptr = dynamic_cast<vpr::Thread*>(this);
00100    vprASSERT(NULL != thread_ptr);
00101    vpr::ThreadManager::instance()->removeThread(thread_ptr);
00102 }

virtual int vpr::BaseThread::join ( void **  status = 0  )  [inline, virtual]

Causes the calling thread wait for the termination of this thread.

Postcondition:
The caller blocks until this thread finishes its execution (i.e., calls the exit() method). This routine may return immediately if this thread has already exited.
Parameters:
status Current state of the terminating thread when that thread calls the exit routine (optional).
Returns:
0 is returned if this thread is "joined" successfully.

-1 is returned on an error condition.

Reimplemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

Definition at line 204 of file BaseThread.h.

00205    {
00206       boost::ignore_unused_variable_warning(status);
00207       return -1;
00208    }

virtual int vpr::BaseThread::resume (  )  [inline, virtual]

Resumes the execution of this thread (if it was previously suspended using suspend()).

Returns:
0 is returned if this thread resumes execuation successfully.

-1 is returned otherwise.

Reimplemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

Definition at line 217 of file BaseThread.h.

00218    {
00219       return -1;
00220    }

virtual int vpr::BaseThread::suspend ( void   )  [inline, virtual]

Suspends the execution of this thread.

Returns:
0 is returned if this thread is suspended successfully.

-1 is returned otherwise.

Reimplemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

Definition at line 228 of file BaseThread.h.

00229    {
00230       return -1;
00231    }

virtual int vpr::BaseThread::getPrio ( VPRThreadPriority prio  )  [inline, virtual]

Gets this thread's current priority.

Postcondition:
The priority of this thread is returned in the integer pointer variable.
Parameters:
prio Pointer to an int variable that will have the thread's priority stored in it.
Returns:
0 is returned if the priority was retrieved successfully.

-1 is returned if the priority could not be read.

Definition at line 245 of file BaseThread.h.

00246    {
00247       boost::ignore_unused_variable_warning(prio);
00248       return -1;
00249    }

virtual int vpr::BaseThread::setPrio ( VPRThreadPriority  prio  )  [inline, virtual]

Sets this thread's priority.

Parameters:
prio The new priority for this thread.
Returns:
0 is returned if this thread's priority was set successfully.

-1 is returned otherwise.

Definition at line 259 of file BaseThread.h.

00260    {
00261       boost::ignore_unused_variable_warning(prio);
00262       return -1;
00263    }

vpr::Int32 vpr::BaseThread::getTID (  )  [inline]

Gets the "thread ID" of this vpr::BaseThread object.

This is a unique integer value assigned when the thread was created.

Returns:
-1 is returned if this is a bad thread. This usually means that there was a reation error.

Otherwise, the value returned is this thread's ID.

Definition at line 273 of file BaseThread.h.

Referenced by vpr::ThreadManager::addThread(), vpr::ThreadManager::removeThread(), and vpr::ThreadNSPR::start().

00274    {
00275       return mThreadId;
00276    }

bool vpr::BaseThread::valid (  )  [inline]

Is this a valid thread?

Returns:
true is returned if this object represents a thread that has been spawned correctly.
Note:
A true value may be returned before the spawned thread begins executing. This is due to the way that the operating system schedules a newly created thread. However, true is returned if and only if the thread has been spawned successfully.

Definition at line 289 of file BaseThread.h.

00290    {
00291       return (mThreadId != -1);
00292    }

virtual int vpr::BaseThread::kill ( int  signum  )  [inline, virtual]

Sends the specified signal to this thread (not necessarily SIGKILL).

Postcondition:
This thread receives the specified signal.
Parameters:
signum The signal to send to the specified thread.
Returns:
0 is returned if the thread was sent the given signal.

-1 is returned if an error occurred.

Reimplemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

Definition at line 304 of file BaseThread.h.

00305    {
00306       boost::ignore_unused_variable_warning(signum);
00307       return -1;
00308    }

virtual void vpr::BaseThread::kill (  )  [inline, virtual]

Kills (cancels) this thread.

Postcondition:
This thread is cancelled. Immediate cancellation is not guaranteed.

Reimplemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

Definition at line 315 of file BaseThread.h.

00316    {;}

std::ostream & vpr::BaseThread::outStream ( std::ostream &  out  )  [virtual]

Ouputs the state of the object.

Reimplemented in vpr::ThreadNSPR, vpr::ThreadPosix, and vpr::ThreadSGI.

Definition at line 58 of file BaseThread.cpp.

References mThreadId.

Referenced by vpr::ThreadSGI::outStream(), and vpr::ThreadPosix::outStream().

00059 {
00060    out.setf(std::ios::right);
00061    out << std::setw(3) << mThreadId;
00062    out.unsetf(std::ios::right);
00063    return out;
00064 }

void vpr::BaseThread::createThreadId (  )  [inline, protected]

Initializes the state of the object.

Definition at line 327 of file BaseThread.h.

Referenced by registerThread().

00328    {
00329       mThreadId = getNextThreadId();
00330    }


Member Data Documentation

vpr::Int32 vpr::BaseThread::mThreadId [protected]

Definition at line 338 of file BaseThread.h.

Referenced by outStream(), and registerThread().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:55:54 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1